REFACTOR: Remove unncessary stubs from pending flags reminder
They seem to be calculated fine by the application, and stubbing makes the tests more brittle and prone to regression.
This commit is contained in:
parent
a518950e52
commit
96b2585a91
|
@ -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(', @')} " : ""
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue