2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2019-04-01 14:46:56 -04:00
|
|
|
describe Jobs::PendingReviewablesReminder do
|
2019-01-03 12:03:01 -05:00
|
|
|
let(:job) { described_class.new }
|
|
|
|
|
|
|
|
def create_flag(created_at)
|
|
|
|
PostActionCreator.create(Fabricate(:user), Fabricate(:post), :spam, created_at: created_at).reviewable
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
job.tap { job.execute({}) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify when there are no flags" do
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
|
|
|
end
|
|
|
|
|
2014-04-03 14:34:21 -04:00
|
|
|
context "notify_about_flags_after is 0" do
|
2017-07-07 02:09:14 -04:00
|
|
|
before { SiteSetting.notify_about_flags_after = 0 }
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2017-04-19 16:16:27 -04:00
|
|
|
it "never notifies" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(50.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "notify_about_flags_after is 48" do
|
2017-04-19 16:16:27 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.notify_about_flags_after = 48
|
2019-01-03 12:03:01 -05:00
|
|
|
described_class.clear_key
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2019-01-03 12:03:01 -05:00
|
|
|
described_class.clear_key
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2016-02-19 15:21:05 -05:00
|
|
|
it "doesn't send message when flags are less than 48 hours old" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(47.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
|
2017-04-19 16:16:27 -04:00
|
|
|
it "doesn't send a message if there are no new flags older than 48 hours old" do
|
2019-01-03 12:03:01 -05:00
|
|
|
old_reviewable = create_flag(50.hours.ago)
|
|
|
|
create_flag(47.hours.ago)
|
|
|
|
|
|
|
|
described_class.last_notified_id = old_reviewable.id
|
|
|
|
execute
|
|
|
|
expect(job.sent_reminder).to eq(false)
|
|
|
|
expect(described_class.last_notified_id).to eq(old_reviewable.id)
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
2019-01-22 11:01:18 -05:00
|
|
|
|
2019-01-25 11:25:30 -05:00
|
|
|
it "sends message when there is a flag older than 48 hours" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(49.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-24 13:39:21 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
context "min_score_default_visibility" do
|
|
|
|
before do
|
|
|
|
create_flag(49.hours.ago)
|
|
|
|
create_flag(51.hours.ago)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
it "doesn't send a message when min_score_default_visibility is not met" do
|
|
|
|
SiteSetting.min_score_default_visibility = 3.0
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
it "sends a message when min_score_default_visibility is met" do
|
|
|
|
SiteSetting.min_score_default_visibility = 2.0
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
2019-01-22 11:01:18 -05:00
|
|
|
end
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
end
|