|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +describe Scheduler::AutoCloseRegistrationsScheduler do |
| 6 | + subject { described_class.new } |
| 7 | + |
| 8 | + describe '#perform' do |
| 9 | + let(:moderator_activity_date) { Time.now.utc } |
| 10 | + |
| 11 | + before do |
| 12 | + Fabricate(:user, role: UserRole.find_by(name: 'Owner'), current_sign_in_at: 10.years.ago) |
| 13 | + Fabricate(:user, role: UserRole.find_by(name: 'Moderator'), current_sign_in_at: moderator_activity_date) |
| 14 | + end |
| 15 | + |
| 16 | + context 'when registrations are open' do |
| 17 | + before do |
| 18 | + Setting.registrations_mode = 'open' |
| 19 | + end |
| 20 | + |
| 21 | + context 'when a moderator has logged in recently' do |
| 22 | + let(:moderator_activity_date) { Time.now.utc } |
| 23 | + |
| 24 | + it 'does not change registrations mode' do |
| 25 | + expect { subject.perform }.to_not change(Setting, :registrations_mode) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + context 'when a moderator has not recently signed in' do |
| 30 | + let(:moderator_activity_date) { 1.year.ago } |
| 31 | + |
| 32 | + it 'changes registrations mode from open to approved' do |
| 33 | + expect { subject.perform }.to change(Setting, :registrations_mode).from('open').to('approved') |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context 'when registrations are closed' do |
| 39 | + before do |
| 40 | + Setting.registrations_mode = 'none' |
| 41 | + end |
| 42 | + |
| 43 | + context 'when a moderator has logged in recently' do |
| 44 | + let(:moderator_activity_date) { Time.now.utc } |
| 45 | + |
| 46 | + it 'does not change registrations mode' do |
| 47 | + expect { subject.perform }.to_not change(Setting, :registrations_mode) |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context 'when a moderator has not recently signed in' do |
| 52 | + let(:moderator_activity_date) { 1.year.ago } |
| 53 | + |
| 54 | + it 'does not change registrations mode' do |
| 55 | + expect { subject.perform }.to_not change(Setting, :registrations_mode) |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | + end |
| 60 | +end |
0 commit comments