auto_close_registrations_scheduler_spec.rb 1.8 KB

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