diff --git a/app/jobs/scheduled/pending_flags_reminder.rb b/app/jobs/scheduled/pending_flags_reminder.rb index 50f02a5cac3..a9b1201e4b5 100644 --- a/app/jobs/scheduled/pending_flags_reminder.rb +++ b/app/jobs/scheduled/pending_flags_reminder.rb @@ -8,14 +8,12 @@ module Jobs def execute(args) if SiteSetting.notify_about_flags_after > 0 - flagged_posts_count = PostAction.flagged_posts_count - return unless flagged_posts_count > 0 flag_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.max usernames = active_moderator_usernames mentions = usernames.size > 0 ? "@#{usernames.join(', @')} " : "" diff --git a/spec/jobs/pending_flags_reminder_spec.rb b/spec/jobs/pending_flags_reminder_spec.rb index 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 do before { 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).never described_class.new.execute({}) end @@ -23,15 +23,13 @@ describe Jobs::PendingFlagsReminder do it "doesn't send message when flags are less than 48 hours old" do Fabricate(:flag, created_at: 47.hours.ago) - PostAction.stubs(:flagged_posts_count).returns(1) PostCreator.expects(:create).never described_class.new.execute({}) end it "doesn't send a message if there are no new flags older than 48 hours old" do old_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.new job.last_notified_id = old_flag.id PostCreator.expects(:create).never @@ -42,14 +40,21 @@ describe Jobs::PendingFlagsReminder do it "doesn't send a message when min_flags_staff_visibility is not met" do SiteSetting.min_flags_staff_visibility = 2 Fabricate(:flag, created_at: 49.hours.ago) - PostAction.stubs(:flagged_posts_count).returns(1) + Fabricate(:flag, created_at: 51.hours.ago) PostCreator.expects(:create).never described_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" do Fabricate(:flag, created_at: 49.hours.ago) - PostAction.stubs(:flagged_posts_count).returns(1) PostCreator.expects(:create).once.returns(true) described_class.new.execute({}) end