DEV: Remove full group refreshes from tests (#25414)

We have all these calls to Group.refresh_automatic_groups! littered throughout the tests. Including tests that are seemingly unrelated to groups. This is because automatic group memberships aren't fabricated when making a vanilla user. There are two places where you'd want to use this:

You have fabricated a user that needs a certain trust level (which is now based on group membership.)
You need the system user to have a certain trust level.
In the first case, we can pass refresh_auto_groups: true to the fabricator instead. This is a more lightweight operation that only considers a single user, instead of all users in all groups.

The second case is no longer a thing after #25400.
This commit is contained in:
Ted Johansson
2024-01-25 14:28:26 +08:00
committed by GitHub
parent 74fd883a89
commit 57ea56ee05
64 changed files with 131 additions and 269 deletions

View File

@ -8,7 +8,7 @@ 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) }
fab!(:guardian_user) { Fabricate(:user) }
fab!(:guardian_user) { Fabricate(:user, refresh_auto_groups: true) }
let(:guardian) { Guardian.new(guardian_user) }
@ -83,8 +83,6 @@ describe Chat::MessageSerializer do
end
describe "#available_flags" do
before { Group.refresh_automatic_groups! }
context "when flagging on a regular channel" do
let(:options) { { scope: guardian, root: nil, chat_channel: message_1.chat_channel } }
@ -167,7 +165,6 @@ describe Chat::MessageSerializer do
it "doesn't include notify_user if they are not in a PM allowed group" do
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]
Group.refresh_automatic_groups!
serialized = described_class.new(message_1, options).as_json
@ -175,9 +172,8 @@ describe Chat::MessageSerializer do
end
it "returns an empty list if the user needs a higher TL to flag" do
guardian.user.update!(trust_level: TrustLevel[2])
guardian.user.change_trust_level!(TrustLevel[2])
SiteSetting.chat_message_flag_allowed_groups = Group::AUTO_GROUPS[:trust_level_3]
Group.refresh_automatic_groups!
serialized = described_class.new(message_1, options).as_json