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:
Joffrey JAFFEUX
2023-03-17 14:24:38 +01:00
committed by GitHub
parent 74349e17c9
commit 12a18d4d55
343 changed files with 9077 additions and 8745 deletions

View File

@ -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",

View File

@ -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(

View File

@ -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)

View File

@ -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)

View File

@ -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) }

View File

@ -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