mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:00:46 +08:00
DEV: properly namespace chat (#20690)
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. -->
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe ChatChannelSerializer do
|
||||
describe Chat::ChannelSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:chat_channel) { Fabricate(:chat_channel) }
|
||||
@ -29,10 +29,10 @@ describe ChatChannelSerializer do
|
||||
it "includes the archive status if the channel is archived and the archive record exists" do
|
||||
expect(subject.as_json.key?(:archive_completed)).to eq(false)
|
||||
|
||||
chat_channel.update!(status: ChatChannel.statuses[:archived])
|
||||
chat_channel.update!(status: Chat::Channel.statuses[:archived])
|
||||
expect(subject.as_json.key?(:archive_completed)).to eq(false)
|
||||
|
||||
ChatChannelArchive.create!(
|
||||
Chat::ChannelArchive.create!(
|
||||
chat_channel: chat_channel,
|
||||
archived_by: admin,
|
||||
destination_topic_title: "This will be the archive topic",
|
@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe ChatMessageSerializer do
|
||||
describe Chat::MessageSerializer do
|
||||
fab!(:chat_channel) { Fabricate(:category_channel) }
|
||||
fab!(:message_poster) { Fabricate(:user) }
|
||||
fab!(:message_1) { Fabricate(:chat_message, user: message_poster, chat_channel: chat_channel) }
|
||||
@ -79,7 +79,7 @@ describe ChatMessageSerializer do
|
||||
let(:options) { { scope: guardian, root: nil, chat_channel: message_1.chat_channel } }
|
||||
|
||||
it "returns an empty list if the user already flagged the message" do
|
||||
reviewable = Fabricate(:reviewable_chat_message, target: message_1)
|
||||
reviewable = Fabricate(:chat_reviewable_message, target: message_1)
|
||||
|
||||
serialized =
|
||||
described_class.new(
|
||||
@ -98,7 +98,7 @@ describe ChatMessageSerializer do
|
||||
end
|
||||
|
||||
it "return available flags if staff already reviewed the previous flag" do
|
||||
reviewable = Fabricate(:reviewable_chat_message, target: message_1)
|
||||
reviewable = Fabricate(:chat_reviewable_message, target: message_1)
|
||||
|
||||
serialized =
|
||||
described_class.new(
|
@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ChatMessageUserSerializer do
|
||||
RSpec.describe Chat::MessageUserSerializer do
|
||||
subject do
|
||||
user = Fabricate(:user, **params)
|
||||
guardian = Guardian.new(user)
|
@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe DirectMessageSerializer do
|
||||
describe Chat::DirectMessageSerializer do
|
||||
describe "#user" do
|
||||
it "returns you when there are two of us" do
|
||||
me = Fabricate.build(:user)
|
@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ChatInReplyToSerializer do
|
||||
RSpec.describe Chat::InReplyToSerializer do
|
||||
subject(:serializer) { described_class.new(message, scope: guardian, root: nil) }
|
||||
|
||||
fab!(:chat_channel) { Fabricate(:chat_channel) }
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StructuredChannelSerializer do
|
||||
RSpec.describe Chat::StructuredChannelSerializer do
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:guardian) { Guardian.new(user1) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
@ -33,7 +33,7 @@ RSpec.describe StructuredChannelSerializer do
|
||||
end
|
||||
|
||||
def fetch_data
|
||||
Chat::ChatChannelFetcher.structured(guardian)
|
||||
Chat::ChannelFetcher.structured(guardian)
|
||||
end
|
||||
|
||||
it "serializes a public channel correctly with membership embedded" do
|
Reference in New Issue
Block a user