mirror of
https://github.com/discourse/discourse.git
synced 2026-08-17 16:35:03 -05: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:
+11
-6
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::AutoJoinChannelBatch do
|
||||
describe Jobs::Chat::AutoJoinChannelBatch do
|
||||
describe "#execute" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
let!(:user) { Fabricate(:user, last_seen_at: 15.minutes.ago) }
|
||||
@@ -64,7 +64,12 @@ describe Jobs::AutoJoinChannelBatch do
|
||||
|
||||
it "enqueues the user count update job and marks the channel user count as stale" do
|
||||
subject.execute(chat_channel_id: channel.id, starts_at: user.id, ends_at: user.id)
|
||||
expect_job_enqueued(job: :update_channel_user_count, args: { chat_channel_id: channel.id })
|
||||
expect_job_enqueued(
|
||||
job: Jobs::Chat::UpdateChannelUserCount,
|
||||
args: {
|
||||
chat_channel_id: channel.id,
|
||||
},
|
||||
)
|
||||
|
||||
expect(channel.reload.user_count_stale).to eq(true)
|
||||
end
|
||||
@@ -72,7 +77,7 @@ describe Jobs::AutoJoinChannelBatch do
|
||||
it "does not enqueue the user count update job or mark the channel user count as stale when there is more than use user" do
|
||||
user_2 = Fabricate(:user)
|
||||
expect_not_enqueued_with(
|
||||
job: :update_channel_user_count,
|
||||
job: Jobs::Chat::UpdateChannelUserCount,
|
||||
args: {
|
||||
chat_channel_id: channel.id,
|
||||
},
|
||||
@@ -92,7 +97,7 @@ describe Jobs::AutoJoinChannelBatch do
|
||||
it "sets the join reason to automatic" do
|
||||
subject.execute(chat_channel_id: channel.id, starts_at: user.id, ends_at: user.id)
|
||||
|
||||
new_membership = UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
new_membership = Chat::UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
expect(new_membership.automatic?).to eq(true)
|
||||
end
|
||||
|
||||
@@ -179,12 +184,12 @@ describe Jobs::AutoJoinChannelBatch do
|
||||
end
|
||||
|
||||
def assert_users_follows_channel(channel, users)
|
||||
new_memberships = UserChatChannelMembership.where(user: users, chat_channel: channel)
|
||||
new_memberships = Chat::UserChatChannelMembership.where(user: users, chat_channel: channel)
|
||||
expect(new_memberships.all?(&:following)).to eq(true)
|
||||
end
|
||||
|
||||
def assert_user_skipped(channel, user)
|
||||
new_membership = UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
new_membership = Chat::UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
expect(new_membership).to be_nil
|
||||
end
|
||||
end
|
||||
+7
-7
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::AutoManageChannelMemberships do
|
||||
describe Jobs::Chat::AutoManageChannelMemberships do
|
||||
let(:user) { Fabricate(:user, last_seen_at: 15.minutes.ago) }
|
||||
let(:category) { Fabricate(:category, user: user) }
|
||||
let(:channel) { Fabricate(:category_channel, auto_join_users: true, chatable: category) }
|
||||
@@ -13,7 +13,7 @@ describe Jobs::AutoManageChannelMemberships do
|
||||
end
|
||||
|
||||
it "does nothing when the channel doesn't exist" do
|
||||
assert_batches_enqueued(ChatChannel.new(id: -1), 0)
|
||||
assert_batches_enqueued(Chat::Channel.new(id: -1), 0)
|
||||
end
|
||||
|
||||
it "does nothing when the chatable is not a category" do
|
||||
@@ -44,24 +44,24 @@ describe Jobs::AutoManageChannelMemberships do
|
||||
it "does nothing when we already reached the max_chat_auto_joined_users limit" do
|
||||
SiteSetting.max_chat_auto_joined_users = 1
|
||||
user_2 = Fabricate(:user, last_seen_at: 2.minutes.ago)
|
||||
UserChatChannelMembership.create!(
|
||||
Chat::UserChatChannelMembership.create!(
|
||||
user: user_2,
|
||||
chat_channel: channel,
|
||||
following: true,
|
||||
join_mode: UserChatChannelMembership.join_modes[:automatic],
|
||||
join_mode: Chat::UserChatChannelMembership.join_modes[:automatic],
|
||||
)
|
||||
|
||||
assert_batches_enqueued(channel, 0)
|
||||
end
|
||||
|
||||
it "ignores users that are already channel members" do
|
||||
UserChatChannelMembership.create!(user: user, chat_channel: channel, following: true)
|
||||
Chat::UserChatChannelMembership.create!(user: user, chat_channel: channel, following: true)
|
||||
|
||||
assert_batches_enqueued(channel, 0)
|
||||
end
|
||||
|
||||
it "doesn't queue a batch when the user doesn't follow the channel" do
|
||||
UserChatChannelMembership.create!(user: user, chat_channel: channel, following: false)
|
||||
Chat::UserChatChannelMembership.create!(user: user, chat_channel: channel, following: false)
|
||||
|
||||
assert_batches_enqueued(channel, 0)
|
||||
end
|
||||
@@ -120,7 +120,7 @@ describe Jobs::AutoManageChannelMemberships do
|
||||
|
||||
def assert_batches_enqueued(channel, expected)
|
||||
expect { subject.execute(chat_channel_id: channel.id) }.to change(
|
||||
Jobs::AutoJoinChannelBatch.jobs,
|
||||
Jobs::Chat::AutoJoinChannelBatch.jobs,
|
||||
:size,
|
||||
).by(expected)
|
||||
end
|
||||
+3
-3
@@ -2,12 +2,12 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::ChatChannelArchive do
|
||||
describe Jobs::Chat::ChannelArchive do
|
||||
fab!(:chat_channel) { Fabricate(:category_channel) }
|
||||
fab!(:user) { Fabricate(:user, admin: true) }
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:chat_archive) do
|
||||
ChatChannelArchive.create!(
|
||||
Chat::ChannelArchive.create!(
|
||||
chat_channel: chat_channel,
|
||||
archived_by: user,
|
||||
destination_topic_title: "This will be the archive topic",
|
||||
@@ -34,7 +34,7 @@ describe Jobs::ChatChannelArchive do
|
||||
end
|
||||
|
||||
it "processes the archive" do
|
||||
Chat::ChatChannelArchiveService.any_instance.expects(:execute)
|
||||
Chat::ChannelArchiveService.any_instance.expects(:execute)
|
||||
run_job
|
||||
end
|
||||
end
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe Jobs::ChatChannelDelete do
|
||||
describe Jobs::Chat::ChannelDelete do
|
||||
fab!(:chat_channel) { Fabricate(:chat_channel) }
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
@@ -14,7 +14,7 @@ describe Jobs::ChatChannelDelete do
|
||||
end
|
||||
@message_ids = messages.map(&:id)
|
||||
|
||||
10.times { ChatMessageReaction.create(chat_message: messages.sample, user: users.sample) }
|
||||
10.times { Chat::MessageReaction.create(chat_message: messages.sample, user: users.sample) }
|
||||
|
||||
10.times do
|
||||
upload = Fabricate(:upload, user: users.sample)
|
||||
@@ -28,14 +28,14 @@ describe Jobs::ChatChannelDelete do
|
||||
UploadReference.create(target: message, upload: upload)
|
||||
end
|
||||
|
||||
ChatMention.create(
|
||||
Chat::Mention.create(
|
||||
user: user2,
|
||||
chat_message: messages.sample,
|
||||
notification: Fabricate(:notification),
|
||||
)
|
||||
|
||||
@incoming_chat_webhook_id = Fabricate(:incoming_chat_webhook, chat_channel: chat_channel)
|
||||
ChatWebhookEvent.create(
|
||||
Chat::WebhookEvent.create(
|
||||
incoming_chat_webhook: @incoming_chat_webhook_id,
|
||||
chat_message: messages.sample,
|
||||
)
|
||||
@@ -48,7 +48,7 @@ describe Jobs::ChatChannelDelete do
|
||||
new_message: revision_message.message,
|
||||
)
|
||||
|
||||
ChatDraft.create(chat_channel: chat_channel, user: users.sample, data: "wow some draft")
|
||||
Chat::Draft.create(chat_channel: chat_channel, user: users.sample, data: "wow some draft")
|
||||
|
||||
Fabricate(:user_chat_channel_membership, chat_channel: chat_channel, user: user1)
|
||||
Fabricate(:user_chat_channel_membership, chat_channel: chat_channel, user: user2)
|
||||
@@ -59,21 +59,21 @@ describe Jobs::ChatChannelDelete do
|
||||
|
||||
def counts
|
||||
{
|
||||
incoming_webhooks: IncomingChatWebhook.where(chat_channel_id: chat_channel.id).count,
|
||||
incoming_webhooks: Chat::IncomingWebhook.where(chat_channel_id: chat_channel.id).count,
|
||||
webhook_events:
|
||||
ChatWebhookEvent.where(incoming_chat_webhook_id: @incoming_chat_webhook_id).count,
|
||||
drafts: ChatDraft.where(chat_channel: chat_channel).count,
|
||||
channel_memberships: UserChatChannelMembership.where(chat_channel: chat_channel).count,
|
||||
revisions: ChatMessageRevision.where(chat_message_id: @message_ids).count,
|
||||
mentions: ChatMention.where(chat_message_id: @message_ids).count,
|
||||
Chat::WebhookEvent.where(incoming_chat_webhook_id: @incoming_chat_webhook_id).count,
|
||||
drafts: Chat::Draft.where(chat_channel: chat_channel).count,
|
||||
channel_memberships: Chat::UserChatChannelMembership.where(chat_channel: chat_channel).count,
|
||||
revisions: Chat::MessageRevision.where(chat_message_id: @message_ids).count,
|
||||
mentions: Chat::Mention.where(chat_message_id: @message_ids).count,
|
||||
chat_uploads:
|
||||
DB.query_single(
|
||||
"SELECT COUNT(*) FROM chat_uploads WHERE chat_message_id IN (#{@message_ids.join(",")})",
|
||||
).first,
|
||||
upload_references:
|
||||
UploadReference.where(target_id: @message_ids, target_type: "ChatMessage").count,
|
||||
messages: ChatMessage.where(id: @message_ids).count,
|
||||
reactions: ChatMessageReaction.where(chat_message_id: @message_ids).count,
|
||||
UploadReference.where(target_id: @message_ids, target_type: Chat::Message.sti_name).count,
|
||||
messages: Chat::Message.where(id: @message_ids).count,
|
||||
reactions: Chat::MessageReaction.where(chat_message_id: @message_ids).count,
|
||||
}
|
||||
end
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::DeleteUserMessages do
|
||||
RSpec.describe Jobs::Chat::DeleteUserMessages do
|
||||
describe "#execute" do
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
fab!(:channel) { Fabricate(:chat_channel) }
|
||||
@@ -26,7 +26,7 @@ RSpec.describe Jobs::DeleteUserMessages do
|
||||
|
||||
subject.execute(user_id: user_1)
|
||||
|
||||
expect(ChatMessage.with_deleted.where(id: chat_message.id)).to be_empty
|
||||
expect(Chat::Message.with_deleted.where(id: chat_message.id)).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
+14
-14
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::ChatNotifyMentioned do
|
||||
describe Jobs::Chat::NotifyMentioned do
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
fab!(:public_channel) { Fabricate(:category_channel) }
|
||||
@@ -77,7 +77,7 @@ describe Jobs::ChatNotifyMentioned do
|
||||
it "does nothing when user is not following the channel" do
|
||||
message = create_chat_message
|
||||
|
||||
UserChatChannelMembership.where(chat_channel: public_channel, user: user_2).update!(
|
||||
Chat::UserChatChannelMembership.where(chat_channel: public_channel, user: user_2).update!(
|
||||
following: false,
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ describe Jobs::ChatNotifyMentioned do
|
||||
it "does nothing when user doesn't have a membership record" do
|
||||
message = create_chat_message
|
||||
|
||||
UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).destroy!
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).destroy!
|
||||
|
||||
PostAlerter.expects(:push_notification).never
|
||||
|
||||
@@ -146,8 +146,8 @@ describe Jobs::ChatNotifyMentioned do
|
||||
|
||||
it "skips desktop notifications based on user preferences" do
|
||||
message = create_chat_message
|
||||
UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
|
||||
desktop_notification =
|
||||
@@ -158,8 +158,8 @@ describe Jobs::ChatNotifyMentioned do
|
||||
|
||||
it "skips push notifications based on user preferences" do
|
||||
message = create_chat_message
|
||||
UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
|
||||
PostAlerter.expects(:push_notification).never
|
||||
@@ -173,8 +173,8 @@ describe Jobs::ChatNotifyMentioned do
|
||||
|
||||
it "skips desktop notifications based on user muting preferences" do
|
||||
message = create_chat_message
|
||||
UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
muted: true,
|
||||
)
|
||||
|
||||
@@ -186,8 +186,8 @@ describe Jobs::ChatNotifyMentioned do
|
||||
|
||||
it "skips push notifications based on user muting preferences" do
|
||||
message = create_chat_message
|
||||
UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
muted: true,
|
||||
)
|
||||
|
||||
@@ -214,7 +214,7 @@ describe Jobs::ChatNotifyMentioned do
|
||||
expect(desktop_notification.data[:notification_type]).to eq(Notification.types[:chat_mention])
|
||||
expect(desktop_notification.data[:username]).to eq(user_1.username)
|
||||
expect(desktop_notification.data[:tag]).to eq(
|
||||
Chat::ChatNotifier.push_notification_tag(:mention, public_channel.id),
|
||||
Chat::Notifier.push_notification_tag(:mention, public_channel.id),
|
||||
)
|
||||
expect(desktop_notification.data[:excerpt]).to eq(message.push_notification_excerpt)
|
||||
expect(desktop_notification.data[:post_url]).to eq(
|
||||
@@ -230,7 +230,7 @@ describe Jobs::ChatNotifyMentioned do
|
||||
{
|
||||
notification_type: Notification.types[:chat_mention],
|
||||
username: user_1.username,
|
||||
tag: Chat::ChatNotifier.push_notification_tag(:mention, public_channel.id),
|
||||
tag: Chat::Notifier.push_notification_tag(:mention, public_channel.id),
|
||||
excerpt: message.push_notification_excerpt,
|
||||
post_url: "/chat/c/#{public_channel.slug}/#{public_channel.id}/#{message.id}",
|
||||
translated_title: payload_translated_title,
|
||||
@@ -264,7 +264,7 @@ describe Jobs::ChatNotifyMentioned do
|
||||
expect(data_hash[:chat_channel_slug]).to eq(public_channel.slug)
|
||||
|
||||
chat_mention =
|
||||
ChatMention.where(notification: created_notification, user: user_2, chat_message: message)
|
||||
Chat::Mention.where(notification: created_notification, user: user_2, chat_message: message)
|
||||
expect(chat_mention).to be_present
|
||||
end
|
||||
end
|
||||
+11
-11
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::ChatNotifyWatching do
|
||||
RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
fab!(:user3) { Fabricate(:user) }
|
||||
@@ -39,7 +39,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -56,7 +56,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
"discourse_push_notifications.popup.new_chat_message",
|
||||
{ username: user1.username, channel: channel.title(user2) },
|
||||
),
|
||||
tag: Chat::ChatNotifier.push_notification_tag(:message, channel.id),
|
||||
tag: Chat::Notifier.push_notification_tag(:message, channel.id),
|
||||
excerpt: message.message,
|
||||
},
|
||||
)
|
||||
@@ -75,8 +75,8 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
context "when mobile_notification_level is always and desktop_notification_level is none" do
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -93,7 +93,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
"discourse_push_notifications.popup.new_chat_message",
|
||||
{ username: user1.username, channel: channel.title(user2) },
|
||||
),
|
||||
tag: Chat::ChatNotifier.push_notification_tag(:message, channel.id),
|
||||
tag: Chat::Notifier.push_notification_tag(:message, channel.id),
|
||||
excerpt: message.message,
|
||||
},
|
||||
),
|
||||
@@ -179,7 +179,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -196,7 +196,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
"discourse_push_notifications.popup.new_direct_chat_message",
|
||||
{ username: user1.username, channel: channel.title(user2) },
|
||||
),
|
||||
tag: Chat::ChatNotifier.push_notification_tag(:message, channel.id),
|
||||
tag: Chat::Notifier.push_notification_tag(:message, channel.id),
|
||||
excerpt: message.message,
|
||||
},
|
||||
)
|
||||
@@ -215,8 +215,8 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
context "when mobile_notification_level is always and desktop_notification_level is none" do
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -233,7 +233,7 @@ RSpec.describe Jobs::ChatNotifyWatching do
|
||||
"discourse_push_notifications.popup.new_direct_chat_message",
|
||||
{ username: user1.username, channel: channel.title(user2) },
|
||||
),
|
||||
tag: Chat::ChatNotifier.push_notification_tag(:message, channel.id),
|
||||
tag: Chat::Notifier.push_notification_tag(:message, channel.id),
|
||||
excerpt: message.message,
|
||||
},
|
||||
),
|
||||
+4
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::ProcessChatMessage do
|
||||
describe Jobs::Chat::ProcessMessage do
|
||||
fab!(:chat_message) { Fabricate(:chat_message, message: "https://discourse.org/team") }
|
||||
|
||||
it "updates cooked with oneboxes" do
|
||||
@@ -23,7 +23,7 @@ describe Jobs::ProcessChatMessage do
|
||||
fab!(:chat_message) { Fabricate(:chat_message, message: "a very lovely cat") }
|
||||
|
||||
it "publishes the update" do
|
||||
ChatPublisher.expects(:publish_processed!).once
|
||||
Chat::Publisher.expects(:publish_processed!).once
|
||||
described_class.new.execute(chat_message_id: chat_message.id, is_dirty: true)
|
||||
end
|
||||
end
|
||||
@@ -32,14 +32,14 @@ describe Jobs::ProcessChatMessage do
|
||||
fab!(:chat_message) { Fabricate(:chat_message, message: "a very lovely cat") }
|
||||
|
||||
it "doesn’t publish the update" do
|
||||
ChatPublisher.expects(:publish_processed!).never
|
||||
Chat::Publisher.expects(:publish_processed!).never
|
||||
described_class.new.execute(chat_message_id: chat_message.id)
|
||||
end
|
||||
|
||||
context "when the cooked message changed" do
|
||||
it "publishes the update" do
|
||||
chat_message.update!(cooked: "another lovely cat")
|
||||
ChatPublisher.expects(:publish_processed!).once
|
||||
Chat::Publisher.expects(:publish_processed!).once
|
||||
described_class.new.execute(chat_message_id: chat_message.id)
|
||||
end
|
||||
end
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::SendMessageNotifications do
|
||||
RSpec.describe Jobs::Chat::SendMessageNotifications do
|
||||
describe "#execute" do
|
||||
context "when the message doesn't exist" do
|
||||
it "does nothing" do
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_new).never
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_edit).never
|
||||
Chat::Notifier.any_instance.expects(:notify_new).never
|
||||
Chat::Notifier.any_instance.expects(:notify_edit).never
|
||||
|
||||
subject.execute(eason: "new", timestamp: 1.minute.ago)
|
||||
end
|
||||
@@ -15,8 +15,8 @@ RSpec.describe Jobs::SendMessageNotifications do
|
||||
fab!(:chat_message) { Fabricate(:chat_message) }
|
||||
|
||||
it "does nothing when the reason is invalid" do
|
||||
Chat::ChatNotifier.expects(:notify_new).never
|
||||
Chat::ChatNotifier.expects(:notify_edit).never
|
||||
Chat::Notifier.expects(:notify_new).never
|
||||
Chat::Notifier.expects(:notify_edit).never
|
||||
|
||||
subject.execute(
|
||||
chat_message_id: chat_message.id,
|
||||
@@ -26,22 +26,22 @@ RSpec.describe Jobs::SendMessageNotifications do
|
||||
end
|
||||
|
||||
it "does nothing if there is no timestamp" do
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_new).never
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_edit).never
|
||||
Chat::Notifier.any_instance.expects(:notify_new).never
|
||||
Chat::Notifier.any_instance.expects(:notify_edit).never
|
||||
|
||||
subject.execute(chat_message_id: chat_message.id, reason: "new")
|
||||
end
|
||||
|
||||
it "calls notify_new when the reason is 'new'" do
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_new).once
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_edit).never
|
||||
Chat::Notifier.any_instance.expects(:notify_new).once
|
||||
Chat::Notifier.any_instance.expects(:notify_edit).never
|
||||
|
||||
subject.execute(chat_message_id: chat_message.id, reason: "new", timestamp: 1.minute.ago)
|
||||
end
|
||||
|
||||
it "calls notify_edit when the reason is 'edit'" do
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_new).never
|
||||
Chat::ChatNotifier.any_instance.expects(:notify_edit).once
|
||||
Chat::Notifier.any_instance.expects(:notify_new).never
|
||||
Chat::Notifier.any_instance.expects(:notify_edit).once
|
||||
|
||||
subject.execute(chat_message_id: chat_message.id, reason: "edit", timestamp: 1.minute.ago)
|
||||
end
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::UpdateChannelUserCount do
|
||||
RSpec.describe Jobs::Chat::UpdateChannelUserCount do
|
||||
fab!(:channel) { Fabricate(:category_channel, user_count: 0, user_count_stale: true) }
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
@@ -18,18 +18,18 @@ RSpec.describe Jobs::UpdateChannelUserCount do
|
||||
|
||||
it "does nothing if the channel does not exist" do
|
||||
channel.destroy
|
||||
ChatPublisher.expects(:publish_chat_channel_metadata).never
|
||||
Chat::Publisher.expects(:publish_chat_channel_metadata).never
|
||||
expect(described_class.new.execute(chat_channel_id: channel.id)).to eq(nil)
|
||||
end
|
||||
|
||||
it "does nothing if the user count has not been marked stale" do
|
||||
channel.update!(user_count_stale: false)
|
||||
ChatPublisher.expects(:publish_chat_channel_metadata).never
|
||||
Chat::Publisher.expects(:publish_chat_channel_metadata).never
|
||||
expect(described_class.new.execute(chat_channel_id: channel.id)).to eq(nil)
|
||||
end
|
||||
|
||||
it "updates the channel user_count and sets user_count_stale back to false" do
|
||||
ChatPublisher.expects(:publish_chat_channel_metadata).with(channel)
|
||||
Chat::Publisher.expects(:publish_chat_channel_metadata).with(channel)
|
||||
described_class.new.execute(chat_channel_id: channel.id)
|
||||
channel.reload
|
||||
expect(channel.user_count).to eq(3)
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::AutoJoinUsers do
|
||||
describe Jobs::Chat::AutoJoinUsers do
|
||||
it "works" do
|
||||
Jobs.run_immediately!
|
||||
channel = Fabricate(:category_channel, auto_join_users: true)
|
||||
user = Fabricate(:user, last_seen_at: 1.minute.ago, active: true)
|
||||
|
||||
membership = UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
membership = Chat::UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
expect(membership).to be_nil
|
||||
|
||||
subject.execute({})
|
||||
|
||||
membership = UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
membership = Chat::UserChatChannelMembership.find_by(user: user, chat_channel: channel)
|
||||
expect(membership.following).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::DeleteOldChatMessages do
|
||||
describe Jobs::Chat::DeleteOldMessages do
|
||||
base_date = DateTime.parse("2020-12-01 00:00 UTC")
|
||||
|
||||
fab!(:public_channel) { Fabricate(:category_channel) }
|
||||
@@ -85,7 +85,7 @@ describe Jobs::DeleteOldChatMessages do
|
||||
SiteSetting.chat_channel_retention_days = 0
|
||||
SiteSetting.chat_dm_retention_days = 0
|
||||
|
||||
expect { described_class.new.execute }.not_to change { ChatMessage.count }
|
||||
expect { described_class.new.execute }.not_to change { Chat::Message.count }
|
||||
end
|
||||
|
||||
describe "public channels" do
|
||||
@@ -107,7 +107,7 @@ describe Jobs::DeleteOldChatMessages do
|
||||
|
||||
it "does nothing when no messages fall in the time range" do
|
||||
SiteSetting.chat_channel_retention_days = 800
|
||||
expect { described_class.new.execute }.not_to change { ChatMessage.in_public_channel.count }
|
||||
expect { described_class.new.execute }.not_to change { Chat::Message.in_public_channel.count }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -130,7 +130,7 @@ describe Jobs::DeleteOldChatMessages do
|
||||
|
||||
it "does nothing when no messages fall in the time range" do
|
||||
SiteSetting.chat_dm_retention_days = 800
|
||||
expect { described_class.new.execute }.not_to change { ChatMessage.in_dm_channel.count }
|
||||
expect { described_class.new.execute }.not_to change { Chat::Message.in_dm_channel.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
+5
-5
@@ -1,15 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe Jobs::EmailChatNotifications do
|
||||
describe Jobs::Chat::EmailNotifications do
|
||||
before { Jobs.run_immediately! }
|
||||
|
||||
context "when chat is enabled" do
|
||||
before { SiteSetting.chat_enabled = true }
|
||||
|
||||
it "starts the mailer" do
|
||||
Chat::ChatMailer.expects(:send_unread_mentions_summary)
|
||||
Chat::Mailer.expects(:send_unread_mentions_summary)
|
||||
|
||||
Jobs.enqueue(:email_chat_notifications)
|
||||
Jobs.enqueue(Jobs::Chat::EmailNotifications)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,9 +17,9 @@ describe Jobs::EmailChatNotifications do
|
||||
before { SiteSetting.chat_enabled = false }
|
||||
|
||||
it "does nothing" do
|
||||
Chat::ChatMailer.expects(:send_unread_mentions_summary).never
|
||||
Chat::Mailer.expects(:send_unread_mentions_summary).never
|
||||
|
||||
Jobs.enqueue(:email_chat_notifications)
|
||||
Jobs.enqueue(Jobs::Chat::EmailNotifications)
|
||||
end
|
||||
end
|
||||
end
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::ChatPeriodicalUpdates do
|
||||
RSpec.describe Jobs::Chat::PeriodicalUpdates do
|
||||
it "works" do
|
||||
# does not blow up, no mocks, everything is called
|
||||
Jobs::ChatPeriodicalUpdates.new.execute(nil)
|
||||
Jobs::Chat::PeriodicalUpdates.new.execute(nil)
|
||||
end
|
||||
end
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Jobs::UpdateUserCountsForChatChannels do
|
||||
describe Jobs::Chat::UpdateUserCountsForChannels do
|
||||
fab!(:chat_channel_1) { Fabricate(:category_channel, user_count: 0) }
|
||||
fab!(:chat_channel_2) { Fabricate(:category_channel, user_count: 0) }
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
@@ -24,7 +24,7 @@ describe Jobs::UpdateUserCountsForChatChannels do
|
||||
it "sets the user_count correctly for each chat channel" do
|
||||
create_memberships
|
||||
|
||||
Jobs::UpdateUserCountsForChatChannels.new.execute
|
||||
Jobs::Chat::UpdateUserCountsForChannels.new.execute
|
||||
|
||||
expect(chat_channel_1.reload.user_count).to eq(2)
|
||||
expect(chat_channel_2.reload.user_count).to eq(3)
|
||||
@@ -39,7 +39,7 @@ describe Jobs::UpdateUserCountsForChatChannels do
|
||||
user_3.update(staged: true)
|
||||
user_4.update(active: false)
|
||||
|
||||
Jobs::UpdateUserCountsForChatChannels.new.execute
|
||||
Jobs::Chat::UpdateUserCountsForChannels.new.execute
|
||||
|
||||
expect(chat_channel_1.reload.user_count).to eq(1)
|
||||
expect(chat_channel_2.reload.user_count).to eq(0)
|
||||
@@ -49,11 +49,11 @@ describe Jobs::UpdateUserCountsForChatChannels do
|
||||
create_memberships
|
||||
|
||||
chat_channel_1.update!(status: :archived)
|
||||
Jobs::UpdateUserCountsForChatChannels.new.execute
|
||||
Jobs::Chat::UpdateUserCountsForChannels.new.execute
|
||||
expect(chat_channel_1.reload.user_count).to eq(0)
|
||||
|
||||
chat_channel_1.update!(status: :read_only)
|
||||
Jobs::UpdateUserCountsForChatChannels.new.execute
|
||||
Jobs::Chat::UpdateUserCountsForChannels.new.execute
|
||||
expect(chat_channel_1.reload.user_count).to eq(0)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user