A platform for community discussion. Free, open, simple.
REFACTOR: Remove unncessary stubs from pending flags reminder
Robin Ward96b2585a91de
diff --git a/app/jobs/scheduled/pending_flags_reminder.rb b/app/jobs/scheduled/pending_flags_reminder.rbindex 50f02a5cac3..a9b1201e4b5 100644--- a/app/jobs/scheduled/pending_flags_reminder.rb+++ b/app/jobs/scheduled/pending_flags_reminder.rb@@ -8,14 +8,12 @@ module Jobsdef execute(args)if SiteSetting.notify_about_flags_after > 0-flagged_posts_count = PostAction.flagged_posts_count-return unless flagged_posts_count > 0flag_ids = pending_flag_ids- if flag_ids.size >= SiteSetting.min_flags_staff_visibility && last_notified_id.to_i < flag_ids.max+ if flag_ids.size > 0 && last_notified_id.to_i < flag_ids.maxusernames = active_moderator_usernamesmentions = usernames.size > 0 ? "@#{usernames.join(', @')} " : ""diff --git a/spec/jobs/pending_flags_reminder_spec.rb b/spec/jobs/pending_flags_reminder_spec.rbindex 6a69defe4ed..dee33a89500 100644--- a/spec/jobs/pending_flags_reminder_spec.rb+++ b/spec/jobs/pending_flags_reminder_spec.rb@@ -5,7 +5,7 @@ describe Jobs::PendingFlagsReminder dobefore { SiteSetting.notify_about_flags_after = 0 }it "never notifies" do- PostAction.stubs(:flagged_posts_count).returns(1)+ Fabricate(:flag, created_at: 50.hours.ago)PostCreator.expects(:create).neverdescribed_class.new.execute({})end@@ -23,15 +23,13 @@ describe Jobs::PendingFlagsReminder doit "doesn't send message when flags are less than 48 hours old" doFabricate(:flag, created_at: 47.hours.ago)- PostAction.stubs(:flagged_posts_count).returns(1)PostCreator.expects(:create).neverdescribed_class.new.execute({})endit "doesn't send a message if there are no new flags older than 48 hours old" doold_flag = Fabricate(:flag, created_at: 50.hours.ago)- new_flag = Fabricate(:flag, created_at: 47.hours.ago)- PostAction.stubs(:flagged_posts_count).returns(2)+ Fabricate(:flag, created_at: 47.hours.ago)job = described_class.newjob.last_notified_id = old_flag.idPostCreator.expects(:create).never@@ -42,14 +40,21 @@ describe Jobs::PendingFlagsReminder doit "doesn't send a message when min_flags_staff_visibility is not met" doSiteSetting.min_flags_staff_visibility = 2Fabricate(:flag, created_at: 49.hours.ago)- PostAction.stubs(:flagged_posts_count).returns(1)+ Fabricate(:flag, created_at: 51.hours.ago)PostCreator.expects(:create).neverdescribed_class.new.execute({})end+ it "sends a message when min_flags_staff_visibility is met" do+ SiteSetting.min_flags_staff_visibility = 2+ f = Fabricate(:flag, created_at: 49.hours.ago)+ Fabricate(:flag, post: f.post, created_at: 51.hours.ago)+ PostCreator.expects(:create).once.returns(true)+ described_class.new.execute({})+ end+it "sends message when there is a flag older than 48 hours" doFabricate(:flag, created_at: 49.hours.ago)- PostAction.stubs(:flagged_posts_count).returns(1)PostCreator.expects(:create).once.returns(true)described_class.new.execute({})end