2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-11 11:52:15 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::DeleteTopic do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2017-05-11 11:52:15 -05:00
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:topic) do
|
2017-07-21 16:14:06 -05:00
|
|
|
Fabricate(:topic_timer, user: admin).topic
|
2017-05-11 11:52:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:first_post) { create_post(topic: topic) }
|
|
|
|
|
2017-05-11 21:28:51 -05:00
|
|
|
it "can delete a topic" do
|
2017-05-11 11:52:15 -05:00
|
|
|
first_post
|
2017-05-11 21:28:51 -05:00
|
|
|
|
2017-07-24 08:17:42 -05:00
|
|
|
freeze_time (2.hours.from_now)
|
|
|
|
|
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
|
|
expect(topic.reload).to be_trashed
|
|
|
|
expect(first_post.reload).to be_trashed
|
|
|
|
expect(topic.reload.public_topic_timer).to eq(nil)
|
|
|
|
|
2017-05-11 11:52:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing if topic is already deleted" do
|
|
|
|
first_post
|
|
|
|
topic.trash!
|
2017-07-24 08:17:42 -05:00
|
|
|
|
|
|
|
freeze_time 2.hours.from_now
|
|
|
|
|
|
|
|
Topic.any_instance.expects(:trash!).never
|
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
2017-05-11 11:52:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing if it's too early" do
|
2017-07-22 21:00:58 -05:00
|
|
|
t = Fabricate(:topic_timer, user: admin, execute_at: 5.hours.from_now).topic
|
2017-05-11 11:52:15 -05:00
|
|
|
create_post(topic: t)
|
2017-07-24 08:17:42 -05:00
|
|
|
|
|
|
|
freeze_time 4.hours.from_now
|
|
|
|
|
|
|
|
described_class.new.execute(topic_timer_id: t.public_topic_timer.id)
|
|
|
|
expect(t.reload).to_not be_trashed
|
2017-05-11 11:52:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "user isn't authorized to delete topics" do
|
|
|
|
let(:topic) {
|
2017-07-22 21:49:04 -05:00
|
|
|
Fabricate(:topic_timer, user: Fabricate(:user)).topic
|
2017-05-11 11:52:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it "shouldn't delete the topic" do
|
|
|
|
create_post(topic: topic)
|
2017-07-24 08:17:42 -05:00
|
|
|
|
|
|
|
freeze_time 2.hours.from_now
|
|
|
|
|
|
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
|
|
expect(topic.reload).to_not be_trashed
|
2017-05-11 11:52:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|