DEV: fix and enable flaky specs (#21753)

These specs were disabled in 786f7503. While investigating this, I found out that at some point `:user_membership` got deleted. It's hard to tell why exactly without investing more time, but it seems using `let!` instead of `fab!` solves the issue.

If in the future we decide to investigate why these tests were flaky with `fab!` to reproduce the failure run:

    LOAD_PLUGINS=1 rspec --seed 46586  plugins/chat/spec/mailers/user_notifications_spec.rb
This commit is contained in:
Andrei Prigorshnev 2023-05-30 14:25:14 +04:00 committed by GitHub
parent deda61b3a4
commit 6491be9f2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 49 deletions

View File

@ -149,7 +149,8 @@ describe UserNotifications do
context "with public channel" do
fab!(:channel) { Fabricate(:category_channel) }
fab!(:chat_message) { Fabricate(:chat_message, user: sender, chat_channel: channel) }
fab!(:user_membership) do
# using fab! for user_membership below makes these specs flaky
let!(:user_membership) do
Fabricate(
:user_chat_channel_membership,
chat_channel: channel,
@ -164,71 +165,71 @@ describe UserNotifications do
expect(email.to).to be_blank
end
# context "with channel-wide mentions" do
# before { Jobs.run_immediately! }
context "with channel-wide mentions" do
before { Jobs.run_immediately! }
# def create_chat_message_with_mentions_and_notifications(content)
# # Sometimes it's not enough to just fabricate a message
# # and we have to create it like here. In this case all the necessary
# # db records for mentions and notifications will be created under the hood.
# Chat::MessageCreator.create(chat_channel: channel, user: sender, content: content)
# end
def create_chat_message_with_mentions_and_notifications(content)
# Sometimes it's not enough to just fabricate a message
# and we have to create it like here. In this case all the necessary
# db records for mentions and notifications will be created under the hood.
Chat::MessageCreator.create(chat_channel: channel, user: sender, content: content)
end
# it "returns email for @all mention by default" do
# create_chat_message_with_mentions_and_notifications("Mentioning @all")
# email = described_class.chat_summary(user, {})
# expect(email.to).to contain_exactly(user.email)
# end
it "returns email for @all mention by default" do
create_chat_message_with_mentions_and_notifications("Mentioning @all")
email = described_class.chat_summary(user, {})
expect(email.to).to contain_exactly(user.email)
end
# it "returns email for @here mention by default" do
# user.update(last_seen_at: 1.second.ago)
it "returns email for @here mention by default" do
user.update(last_seen_at: 1.second.ago)
# create_chat_message_with_mentions_and_notifications("Mentioning @here")
# email = described_class.chat_summary(user, {})
create_chat_message_with_mentions_and_notifications("Mentioning @here")
email = described_class.chat_summary(user, {})
# expect(email.to).to contain_exactly(user.email)
# end
expect(email.to).to contain_exactly(user.email)
end
# context "when channel-wide mentions are disabled in a channel" do
# before { channel.update!(allow_channel_wide_mentions: false) }
context "when channel-wide mentions are disabled in a channel" do
before { channel.update!(allow_channel_wide_mentions: false) }
# it "doesn't return email for @all mention" do
# create_chat_message_with_mentions_and_notifications("Mentioning @all")
# email = described_class.chat_summary(user, {})
it "doesn't return email for @all mention" do
create_chat_message_with_mentions_and_notifications("Mentioning @all")
email = described_class.chat_summary(user, {})
# expect(email.to).to be_blank
# end
expect(email.to).to be_blank
end
# it "doesn't return email for @here mention" do
# user.update(last_seen_at: 1.second.ago)
it "doesn't return email for @here mention" do
user.update(last_seen_at: 1.second.ago)
# create_chat_message_with_mentions_and_notifications("Mentioning @here")
# email = described_class.chat_summary(user, {})
create_chat_message_with_mentions_and_notifications("Mentioning @here")
email = described_class.chat_summary(user, {})
# expect(email.to).to be_blank
# end
# end
expect(email.to).to be_blank
end
end
# context "when user has disabled channel-wide mentions" do
# before { user.user_option.update!(ignore_channel_wide_mention: true) }
context "when user has disabled channel-wide mentions" do
before { user.user_option.update!(ignore_channel_wide_mention: true) }
# it "doesn't return email for @all mention" do
# create_chat_message_with_mentions_and_notifications("Mentioning @all")
# email = described_class.chat_summary(user, {})
it "doesn't return email for @all mention" do
create_chat_message_with_mentions_and_notifications("Mentioning @all")
email = described_class.chat_summary(user, {})
# expect(email.to).to be_blank
# end
expect(email.to).to be_blank
end
# it "doesn't return email for @here mention" do
# user.update(last_seen_at: 1.second.ago)
it "doesn't return email for @here mention" do
user.update(last_seen_at: 1.second.ago)
# create_chat_message_with_mentions_and_notifications("Mentioning @here")
# email = described_class.chat_summary(user, {})
create_chat_message_with_mentions_and_notifications("Mentioning @here")
email = described_class.chat_summary(user, {})
# expect(email.to).to be_blank
# end
# end
# end
expect(email.to).to be_blank
end
end
end
describe "email subject" do
context "with regular mentions" do