discourse/spec/jobs/delete_topic_spec.rb

60 lines
1.4 KiB
Ruby
Raw Normal View History

2017-05-12 00:52:15 +08:00
require 'rails_helper'
describe Jobs::DeleteTopic do
let(:admin) { Fabricate(:admin) }
let(:topic) do
2017-07-22 05:14:06 +08:00
Fabricate(:topic_timer, user: admin).topic
2017-05-12 00:52:15 +08:00
end
let(:first_post) { create_post(topic: topic) }
it "can delete a topic" do
2017-05-12 00:52:15 +08:00
first_post
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-12 00:52:15 +08:00
end
it "should do nothing if topic is already deleted" do
first_post
topic.trash!
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-12 00:52:15 +08:00
end
it "should do nothing if it's too early" do
2017-07-23 10:00:58 +08:00
t = Fabricate(:topic_timer, user: admin, execute_at: 5.hours.from_now).topic
2017-05-12 00:52:15 +08:00
create_post(topic: t)
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-12 00:52:15 +08:00
end
describe "user isn't authorized to delete topics" do
let(:topic) {
2017-07-23 10:49:04 +08:00
Fabricate(:topic_timer, user: Fabricate(:user)).topic
2017-05-12 00:52:15 +08:00
}
it "shouldn't delete the topic" do
create_post(topic: topic)
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-12 00:52:15 +08:00
end
end
end