discourse/spec/jobs/remove_banner_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

46 lines
1.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
RSpec.describe Jobs::RemoveBanner do
fab!(:topic)
fab!(:user) { topic.user }
context "when topic is not bannered until" do
it "doesnt enqueue a future job to remove it" do
expect do topic.make_banner!(user) end.not_to change { Jobs::RemoveBanner.jobs.size }
end
end
context "when topic is bannered until" do
context "when bannered_until is a valid date" do
it "enqueues a future job to remove it" do
bannered_until = 5.days.from_now
expect(topic.archetype).to eq(Archetype.default)
expect do topic.make_banner!(user, bannered_until.to_s) end.to change {
Jobs::RemoveBanner.jobs.size
}.by(1)
topic.reload
expect(topic.archetype).to eq(Archetype.banner)
job = Jobs::RemoveBanner.jobs[0]
expect(Time.at(job["at"])).to be_within_one_minute_of(bannered_until)
expect(job["args"][0]["topic_id"]).to eq(topic.id)
job["class"].constantize.new.perform(*job["args"])
topic.reload
expect(topic.archetype).to eq(Archetype.default)
end
end
context "when bannered_until is an invalid date" do
it "doesnt enqueue a future job to remove it" do
expect do
expect do topic.make_banner!(user, "xxx") end.to raise_error(Discourse::InvalidParameters)
end.not_to change { Jobs::RemoveBanner.jobs.size }
end
end
end
end