mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
c9dab6fd08
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors. By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
describe Jobs::RemoveBanner do
|
||
fab!(:topic) { Fabricate(:topic) }
|
||
fab!(:user) { topic.user }
|
||
|
||
context 'topic is not bannered until' do
|
||
it 'doesn’t enqueue a future job to remove it' do
|
||
expect do
|
||
topic.make_banner!(user)
|
||
end.to change { Jobs::RemoveBanner.jobs.size }.by(0)
|
||
end
|
||
end
|
||
|
||
context 'topic is bannered until' do
|
||
context '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 'bannered_until is an invalid date' do
|
||
it 'doesn’t enqueue a future job to remove it' do
|
||
expect do
|
||
expect do
|
||
topic.make_banner!(user, 'xxx')
|
||
end.to raise_error(Discourse::InvalidParameters)
|
||
end.to change { Jobs::RemoveBanner.jobs.size }.by(0)
|
||
end
|
||
end
|
||
end
|
||
end
|