mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 09:13:44 +08:00
694b5f108b
These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse: Capybara/VisibilityMatcher Lint/DeprecatedOpenSSLConstant Lint/DisjunctiveAssignmentInConstructor Lint/EmptyConditionalBody Lint/EmptyEnsure Lint/LiteralInInterpolation Lint/NonLocalExitFromIterator Lint/ParenthesesAsGroupedExpression Lint/RedundantCopDisableDirective Lint/RedundantRequireStatement Lint/RedundantSafeNavigation Lint/RedundantStringCoercion Lint/RedundantWithIndex Lint/RedundantWithObject Lint/SafeNavigationChain Lint/SafeNavigationConsistency Lint/SelfAssignment Lint/UnreachableCode Lint/UselessMethodDefinition Lint/Void Previous PRs: Lint/ShadowedArgument Lint/DuplicateMethods Lint/BooleanSymbol RSpec/SpecFilePathSuffix
54 lines
1.4 KiB
Ruby
54 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::DeleteTopic do
|
|
fab!(:admin)
|
|
|
|
fab!(:topic) { Fabricate(:topic_timer, user: admin).topic }
|
|
|
|
let(:first_post) { create_post(topic: topic) }
|
|
|
|
it "can delete a topic" do
|
|
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)
|
|
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)
|
|
end
|
|
|
|
it "should do nothing if it's too early" do
|
|
t = Fabricate(:topic_timer, user: admin, execute_at: 5.hours.from_now).topic
|
|
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
|
|
end
|
|
|
|
describe "user isn't authorized to delete topics" do
|
|
let(:topic) { Fabricate(:topic_timer, user: Fabricate(:user)).topic }
|
|
|
|
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
|
|
end
|
|
end
|
|
end
|