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

@ -41,7 +41,7 @@ RSpec.shared_examples "a chat channel model" do
before { category_channel_1.chatable.destroy! }
it "doesn’t list the channel" do
ids = ChatChannel.public_channels.pluck(:chatable_id)
ids = Chat::Channel.public_channels.pluck(:chatable_id)
expect(ids).to_not include(category_channel_1.chatable_id)
expect(ids).to include(category_channel_2.chatable_id)
end
@ -235,7 +235,7 @@ RSpec.shared_examples "a chat channel model" do
expect(membership.chat_channel).to eq(private_category_channel)
expect(private_category_channel.user_count_stale).to eq(true)
expect_job_enqueued(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -244,7 +244,7 @@ RSpec.shared_examples "a chat channel model" do
it "updates an existing membership for the user and enqueues a job to update the count" do
membership =
UserChatChannelMembership.create!(
Chat::UserChatChannelMembership.create!(
chat_channel: private_category_channel,
user: user1,
following: false,
@ -256,7 +256,7 @@ RSpec.shared_examples "a chat channel model" do
expect(membership.reload.following).to eq(true)
expect(private_category_channel.user_count_stale).to eq(true)
expect_job_enqueued(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -265,7 +265,7 @@ RSpec.shared_examples "a chat channel model" do
it "does nothing if the user is already a member" do
membership =
UserChatChannelMembership.create!(
Chat::UserChatChannelMembership.create!(
chat_channel: private_category_channel,
user: user1,
following: true,
@ -273,7 +273,7 @@ RSpec.shared_examples "a chat channel model" do
expect(private_category_channel.user_count_stale).to eq(false)
expect_not_enqueued_with(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -283,7 +283,7 @@ RSpec.shared_examples "a chat channel model" do
it "does not recalculate user count if it's already been marked as stale" do
private_category_channel.update!(user_count_stale: true)
expect_not_enqueued_with(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -306,7 +306,7 @@ RSpec.shared_examples "a chat channel model" do
expect(@membership.reload.following).to eq(false)
expect(private_category_channel.user_count_stale).to eq(true)
expect_job_enqueued(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -325,7 +325,7 @@ RSpec.shared_examples "a chat channel model" do
expect(private_category_channel.user_count_stale).to eq(false)
expect_job_enqueued(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},
@ -335,7 +335,7 @@ RSpec.shared_examples "a chat channel model" do
it "does not recalculate user count if it's already been marked as stale" do
private_category_channel.update!(user_count_stale: true)
expect_not_enqueued_with(
job: :update_channel_user_count,
job: Jobs::Chat::UpdateChannelUserCount,
args: {
chat_channel_id: private_category_channel.id,
},