discourse/spec/jobs/clean_up_post_reply_keys_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
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.
2022-03-01 17:50:50 +00:00

26 lines
739 B
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::CleanUpPostReplyKeys do
it 'removes old post_reply_keys' do
freeze_time
reply_key1 = Fabricate(:post_reply_key, created_at: 1.day.ago)
reply_key2 = Fabricate(:post_reply_key, created_at: 2.days.ago)
Fabricate(:post_reply_key, created_at: 3.days.ago)
SiteSetting.disallow_reply_by_email_after_days = 0
expect { Jobs::CleanUpPostReplyKeys.new.execute({}) }
.to change { PostReplyKey.count }.by(0)
SiteSetting.disallow_reply_by_email_after_days = 2
expect { Jobs::CleanUpPostReplyKeys.new.execute({}) }
.to change { PostReplyKey.count }.by(-1)
expect(PostReplyKey.all).to contain_exactly(
reply_key1, reply_key2
)
end
end