mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 23:06:57 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
60 lines
1.6 KiB
Ruby
60 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe Jobs::TopicReminder do
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:topic) do
|
|
Fabricate(:topic_timer,
|
|
user: admin,
|
|
status_type: TopicTimer.types[:reminder]
|
|
).topic
|
|
end
|
|
|
|
it "should be able to create a reminder" do
|
|
topic_timer = topic.topic_timers.first
|
|
freeze_time 1.day.from_now
|
|
|
|
expect {
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
}.to change { Notification.count }.by(1)
|
|
expect(admin.notifications.where(notification_type: Notification.types[:topic_reminder]).first&.topic_id).to eq(topic.id)
|
|
expect(TopicTimer.where(id: topic_timer.id).first).to be_nil
|
|
end
|
|
|
|
it "does nothing if it was trashed before the scheduled time" do
|
|
topic_timer = topic.topic_timers.first
|
|
topic_timer.trash!(Discourse.system_user)
|
|
|
|
freeze_time(1.day.from_now)
|
|
|
|
expect {
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
}.to_not change { Notification.count }
|
|
end
|
|
|
|
it "does nothing if job runs too early" do
|
|
topic_timer = topic.topic_timers.first
|
|
topic_timer.update_attribute(:execute_at, 8.hours.from_now)
|
|
|
|
freeze_time(6.hours.from_now)
|
|
|
|
expect {
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
}.to_not change { Notification.count }
|
|
end
|
|
|
|
it "does nothing if topic was deleted" do
|
|
topic_timer = topic.topic_timers.first
|
|
topic.trash!
|
|
|
|
freeze_time(1.day.from_now)
|
|
|
|
expect {
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
}.to_not change { Notification.count }
|
|
end
|
|
|
|
end
|