scheduled_status_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ScheduledStatus do
  4. let(:account) { Fabricate(:account) }
  5. describe 'validations' do
  6. context 'when scheduled_at is less than minimum offset' do
  7. subject { Fabricate.build(:scheduled_status, scheduled_at: 4.minutes.from_now, account: account) }
  8. it 'is not valid', :aggregate_failures do
  9. expect(subject).to_not be_valid
  10. expect(subject.errors[:scheduled_at]).to include(I18n.t('scheduled_statuses.too_soon'))
  11. end
  12. end
  13. context 'when account has reached total limit' do
  14. subject { Fabricate.build(:scheduled_status, account: account) }
  15. before do
  16. allow(account.scheduled_statuses).to receive(:count).and_return(described_class::TOTAL_LIMIT)
  17. end
  18. it 'is not valid', :aggregate_failures do
  19. expect(subject).to_not be_valid
  20. expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_total_limit', limit: ScheduledStatus::TOTAL_LIMIT))
  21. end
  22. end
  23. context 'when account has reached daily limit' do
  24. subject { Fabricate.build(:scheduled_status, account: account, scheduled_at: base_time + 10.minutes) }
  25. let(:base_time) { Time.current.change(hour: 12) }
  26. before do
  27. stub_const('ScheduledStatus::DAILY_LIMIT', 3)
  28. travel_to base_time do
  29. Fabricate.times(ScheduledStatus::DAILY_LIMIT, :scheduled_status, account: account, scheduled_at: base_time + 1.hour)
  30. end
  31. end
  32. it 'is not valid', :aggregate_failures do
  33. expect(subject).to_not be_valid
  34. expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_daily_limit', limit: ScheduledStatus::DAILY_LIMIT))
  35. end
  36. end
  37. end
  38. end