A platform for community discussion. Free, open, simple.
REFACTOR: Remove stubbed methods in tests
Robin Warde5a81aeb6e6c
diff --git a/spec/services/flag_sockpuppets_spec.rb b/spec/services/flag_sockpuppets_spec.rbindex 8dcb69fa372..ea875e4b3ba 100644--- a/spec/services/flag_sockpuppets_spec.rb+++ b/spec/services/flag_sockpuppets_spec.rb@@ -112,34 +112,41 @@ describe SpamRule::FlagSockpuppets dodescribe 'flag_sockpuppet_users' dolet(:post2) { Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address), topic: post1.topic) }+ let(:system) { Discourse.system_user }+ let(:spam) { PostActionType.types[:spam] }it 'flags post and first post if both users are new' do- PostAction.expects(:act).with(Discourse.system_user, post1, PostActionType.types[:spam], anything).once- PostAction.expects(:act).with(Discourse.system_user, post2, PostActionType.types[:spam], anything).oncedescribed_class.new(post2).flag_sockpuppet_users++ expect(PostAction.where(user: system, post: post1, post_action_type_id: spam).exists?).to eq(true)+ expect(PostAction.where(user: system, post: post2, post_action_type_id: spam).exists?).to eq(true)endit "doesn't flag the first post more than once" do- PostAction.expects(:act).with(Discourse.system_user, post2, PostActionType.types[:spam], anything).once- PostAction.stubs(:act).with(Discourse.system_user, post1, PostActionType.types[:spam], anything).raises(PostAction::AlreadyActed)described_class.new(post2).flag_sockpuppet_users++ expect(PostAction.where(user: system, post: post2, post_action_type_id: spam).exists?).to eq(true)+ expect(PostAction.where(post: post2, post_action_type_id: spam).count).to eq(1)endit "doesn't flag the first post if the user is not new" doold_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 25.hours.ago, trust_level: TrustLevel[1])first_post = Fabricate(:post, user: old_user, topic: Fabricate(:topic, user: old_user))post2 = Fabricate(:post, user: Fabricate(:user, ip_address: old_user.ip_address), topic: first_post.topic)- PostAction.expects(:act).with(anything, post2, anything, anything).once- PostAction.expects(:act).with(anything, first_post, anything, anything).never+described_class.new(post2).flag_sockpuppet_users++ expect(PostAction.where(user: system, post: post2, post_action_type_id: spam).exists?).to eq(true)+ expect(PostAction.where(user: system, post: first_post, post_action_type_id: spam).exists?).to eq(false)endit "doesn't create a flag if user is nil on first post" dopost1.user_id = nilpost1.save- PostAction.expects(:act).with(anything, post2, anything, anything).once- PostAction.expects(:act).with(anything, post1, anything, anything).neverdescribed_class.new(post2).flag_sockpuppet_users++ expect(PostAction.where(user: system, post: post2, post_action_type_id: spam).exists?).to eq(true)+ expect(PostAction.where(user: system, post: post1, post_action_type_id: spam).exists?).to eq(false)endendend