From d41fa579c87b5b461c8f9316c77f46ab0d979d3c Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 6 Jul 2023 21:44:53 +0200 Subject: [PATCH] DEV: more resilient auto remove spec (#22472) We have no guarantees on the last record here, it's easier and more stable to check all created records. --- .../handle_user_removed_from_group_spec.rb | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/chat/spec/services/auto_remove/handle_user_removed_from_group_spec.rb b/plugins/chat/spec/services/auto_remove/handle_user_removed_from_group_spec.rb index 54d01b51b67..2c904bcf3d0 100644 --- a/plugins/chat/spec/services/auto_remove/handle_user_removed_from_group_spec.rb +++ b/plugins/chat/spec/services/auto_remove/handle_user_removed_from_group_spec.rb @@ -33,8 +33,6 @@ RSpec.describe Chat::AutoRemove::HandleUserRemovedFromGroup do end context "when the user is no longer in any of the chat_allowed_groups" do - let(:action) { UserHistory.where(custom_type: "chat_auto_remove_membership").last } - before do SiteSetting.chat_allowed_groups = Fabricate(:group).id public_channel_1.add(removed_user) @@ -88,13 +86,20 @@ RSpec.describe Chat::AutoRemove::HandleUserRemovedFromGroup do ).to eq(true) end - it "logs a staff action" do + it "logs staff actions" do result - expect(action).to have_attributes( - details: - "users_removed: 1\nchannel_id: #{public_channel_2.id}\nevent: user_removed_from_group", - acting_user_id: Discourse.system_user.id, - custom_type: "chat_auto_remove_membership", + + expect( + UserHistory + .where( + acting_user_id: Discourse.system_user.id, + custom_type: "chat_auto_remove_membership", + ) + .last(2) + .map(&:details), + ).to contain_exactly( + "users_removed: 1\nchannel_id: #{public_channel_1.id}\nevent: user_removed_from_group", + "users_removed: 1\nchannel_id: #{public_channel_2.id}\nevent: user_removed_from_group", ) end