2017-05-11 12:52:15 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::DeleteTopic do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
let(:topic) do
|
|
|
|
Fabricate(:topic,
|
2017-05-11 18:23:18 -04:00
|
|
|
topic_timers: [Fabricate(:topic_timer, user: admin)]
|
2017-05-11 12:52:15 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:first_post) { create_post(topic: topic) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.queue_jobs = true
|
|
|
|
end
|
|
|
|
|
2017-05-11 22:28:51 -04:00
|
|
|
it "can delete a topic" do
|
2017-05-11 12:52:15 -04:00
|
|
|
first_post
|
2017-05-11 22:28:51 -04:00
|
|
|
|
2017-05-11 12:52:15 -04:00
|
|
|
Timecop.freeze(2.hours.from_now) do
|
2017-05-16 14:49:42 -04:00
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
2017-05-11 12:52:15 -04:00
|
|
|
expect(topic.reload).to be_trashed
|
|
|
|
expect(first_post.reload).to be_trashed
|
2017-05-16 14:49:42 -04:00
|
|
|
expect(topic.reload.public_topic_timer).to eq(nil)
|
2017-05-11 12:52:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing if topic is already deleted" do
|
|
|
|
first_post
|
|
|
|
topic.trash!
|
|
|
|
Timecop.freeze(2.hours.from_now) do
|
|
|
|
Topic.any_instance.expects(:trash!).never
|
2017-05-16 14:49:42 -04:00
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
2017-05-11 12:52:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing if it's too early" do
|
|
|
|
t = Fabricate(:topic,
|
2017-05-11 18:23:18 -04:00
|
|
|
topic_timers: [Fabricate(:topic_timer, user: admin, execute_at: 5.hours.from_now)]
|
2017-05-11 12:52:15 -04:00
|
|
|
)
|
|
|
|
create_post(topic: t)
|
|
|
|
Timecop.freeze(4.hours.from_now) do
|
2017-05-16 14:49:42 -04:00
|
|
|
described_class.new.execute(topic_timer_id: t.public_topic_timer.id)
|
2017-05-11 12:52:15 -04:00
|
|
|
expect(t.reload).to_not be_trashed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user isn't authorized to delete topics" do
|
|
|
|
let(:topic) {
|
|
|
|
Fabricate(:topic,
|
2017-05-11 18:23:18 -04:00
|
|
|
topic_timers: [Fabricate(:topic_timer, user: Fabricate(:user))]
|
2017-05-11 12:52:15 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
it "shouldn't delete the topic" do
|
|
|
|
create_post(topic: topic)
|
|
|
|
Timecop.freeze(2.hours.from_now) do
|
2017-05-16 14:49:42 -04:00
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
2017-05-11 12:52:15 -04:00
|
|
|
expect(topic.reload).to_not be_trashed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|