mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 04:23:44 +08:00
12a18d4d55
This commit main goal was to comply with Zeitwerk and properly rely on autoloading. To achieve this, most resources have been namespaced under the `Chat` module. - Given all models are now namespaced with `Chat::` and would change the stored types in DB when using polymorphism or STI (single table inheritance), this commit uses various Rails methods to ensure proper class is loaded and the stored name in DB is unchanged, eg: `Chat::Message` model will be stored as `"ChatMessage"`, and `"ChatMessage"` will correctly load `Chat::Message` model. - Jobs are now using constants only, eg: `Jobs::Chat::Foo` and should only be enqueued this way Notes: - This commit also used this opportunity to limit the number of registered css files in plugin.rb - `discourse_dev` support has been removed within this commit and will be reintroduced later <!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe CurrentUserSerializer do
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
let(:serializer) do
|
|
described_class.new(current_user, scope: Guardian.new(current_user), root: false)
|
|
end
|
|
|
|
before do
|
|
SiteSetting.chat_enabled = true
|
|
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
|
|
current_user.user_option.update(chat_enabled: true)
|
|
end
|
|
|
|
describe "#chat_drafts" do
|
|
context "when user can't chat" do
|
|
before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff] }
|
|
|
|
it "is not present" do
|
|
expect(serializer.as_json[:chat_drafts]).to be_blank
|
|
end
|
|
end
|
|
|
|
it "is ordered by most recent drafts" do
|
|
Fabricate(:chat_draft, user: current_user, value: "second draft")
|
|
Fabricate(:chat_draft, user: current_user, value: "first draft")
|
|
|
|
values =
|
|
serializer.as_json[:chat_drafts].map { |draft| MultiJson.load(draft[:data])["value"] }
|
|
expect(values).to eq(["first draft", "second draft"])
|
|
end
|
|
|
|
it "limits the numbers of drafts" do
|
|
21.times { Fabricate(:chat_draft, user: current_user) }
|
|
|
|
expect(serializer.as_json[:chat_drafts].length).to eq(20)
|
|
end
|
|
end
|
|
end
|