2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2014-04-04 02:34:21 +08:00
|
|
|
|
|
|
|
describe Jobs::PendingFlagsReminder do
|
|
|
|
context "notify_about_flags_after is 0" do
|
2017-07-07 14:09:14 +08:00
|
|
|
before { SiteSetting.notify_about_flags_after = 0 }
|
2014-04-04 02:34:21 +08:00
|
|
|
|
2017-04-20 04:16:27 +08:00
|
|
|
it "never notifies" do
|
2014-04-04 02:34:21 +08:00
|
|
|
PostAction.stubs(:flagged_posts_count).returns(1)
|
2017-04-20 04:16:27 +08:00
|
|
|
PostCreator.expects(:create).never
|
2014-04-04 02:34:21 +08:00
|
|
|
described_class.new.execute({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "notify_about_flags_after is 48" do
|
2017-04-20 04:16:27 +08:00
|
|
|
before do
|
|
|
|
SiteSetting.notify_about_flags_after = 48
|
|
|
|
$redis.del described_class.last_notified_key
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
$redis.del described_class.last_notified_key
|
|
|
|
end
|
2014-04-04 02:34:21 +08:00
|
|
|
|
2016-02-20 04:21:05 +08:00
|
|
|
it "doesn't send message when flags are less than 48 hours old" do
|
2014-04-04 02:34:21 +08:00
|
|
|
Fabricate(:flag, created_at: 47.hours.ago)
|
|
|
|
PostAction.stubs(:flagged_posts_count).returns(1)
|
2016-02-20 04:21:05 +08:00
|
|
|
PostCreator.expects(:create).never
|
2014-04-04 02:34:21 +08:00
|
|
|
described_class.new.execute({})
|
|
|
|
end
|
|
|
|
|
2016-02-20 04:21:05 +08:00
|
|
|
it "sends message when there is a flag older than 48 hours" do
|
2014-04-04 02:34:21 +08:00
|
|
|
Fabricate(:flag, created_at: 49.hours.ago)
|
|
|
|
PostAction.stubs(:flagged_posts_count).returns(1)
|
2016-02-20 04:21:05 +08:00
|
|
|
PostCreator.expects(:create).once.returns(true)
|
2014-04-04 02:34:21 +08:00
|
|
|
described_class.new.execute({})
|
|
|
|
end
|
2017-04-20 04:16:27 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
job = described_class.new
|
|
|
|
job.last_notified_id = old_flag.id
|
|
|
|
PostCreator.expects(:create).never
|
|
|
|
job.execute({})
|
|
|
|
expect(job.last_notified_id).to eq(old_flag.id)
|
|
|
|
end
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
end
|