mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 22:28:34 +08:00
41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
describe "BannerTopic" do
|
||
|
before { automation.upsert_field!("topic_id", "text", { value: topic.id }) }
|
||
|
|
||
|
fab!(:automation) { Fabricate(:automation, script: DiscourseAutomation::Scripts::BANNER_TOPIC) }
|
||
|
fab!(:topic)
|
||
|
|
||
|
context "when banner until is set" do
|
||
|
before do
|
||
|
freeze_time
|
||
|
automation.upsert_field!("banner_until", "date_time", { value: 10.days.from_now })
|
||
|
automation.upsert_field!("topic_id", "text", { value: topic.id })
|
||
|
end
|
||
|
|
||
|
it "banners the topic" do
|
||
|
expect(topic.bannered_until).to be_nil
|
||
|
expect(topic.archetype).to eq(Archetype.default)
|
||
|
|
||
|
automation.trigger!
|
||
|
topic.reload
|
||
|
|
||
|
expect(topic.bannered_until).to be_within_one_minute_of(10.days.from_now)
|
||
|
expect(topic.archetype).to eq(Archetype.banner)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when banner until is not set" do
|
||
|
it "banners the topic" do
|
||
|
expect(topic.bannered_until).to be_nil
|
||
|
expect(topic.archetype).to eq(Archetype.default)
|
||
|
|
||
|
automation.trigger!
|
||
|
topic.reload
|
||
|
|
||
|
expect(topic.bannered_until).to be_nil
|
||
|
expect(topic.archetype).to eq(Archetype.banner)
|
||
|
end
|
||
|
end
|
||
|
end
|