Simplify model validation specs for `ScheduledStatus`

Matt Jankowski 2024-09-05 13:45:47 -04:00
parent a1ac2a73ff
commit 7d63f916d1
1 changed files with 8 additions and 19 deletions

View File

@ -5,31 +5,23 @@ require 'rails_helper'
RSpec.describe ScheduledStatus do RSpec.describe ScheduledStatus do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
describe 'validations' do describe 'Validations' do
context 'when scheduled_at is less than minimum offset' do subject { Fabricate.build :scheduled_status }
subject { Fabricate.build(:scheduled_status, scheduled_at: 4.minutes.from_now, account: account) }
it 'is not valid', :aggregate_failures do context 'when scheduled_at is less than minimum offset' do
expect(subject).to_not be_valid it { is_expected.to_not allow_value(4.minutes.from_now).for(:scheduled_at).with_message(I18n.t('scheduled_statuses.too_soon')) }
expect(subject.errors[:scheduled_at]).to include(I18n.t('scheduled_statuses.too_soon'))
end
end end
context 'when account has reached total limit' do context 'when account has reached total limit' do
subject { Fabricate.build(:scheduled_status, account: account) }
before do before do
allow(account.scheduled_statuses).to receive(:count).and_return(described_class::TOTAL_LIMIT) stub_const('ScheduledStatus::TOTAL_LIMIT', 0)
end end
it 'is not valid', :aggregate_failures do it { is_expected.to_not allow_value(account).for(:account).against(:base).with_message(I18n.t('scheduled_statuses.over_total_limit', limit: ScheduledStatus::TOTAL_LIMIT)) }
expect(subject).to_not be_valid
expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_total_limit', limit: ScheduledStatus::TOTAL_LIMIT))
end
end end
context 'when account has reached daily limit' do context 'when account has reached daily limit' do
subject { Fabricate.build(:scheduled_status, account: account, scheduled_at: base_time + 10.minutes) } subject { Fabricate.build(:scheduled_status, scheduled_at: base_time + 10.minutes) }
let(:base_time) { Time.current.change(hour: 12) } let(:base_time) { Time.current.change(hour: 12) }
@ -41,10 +33,7 @@ RSpec.describe ScheduledStatus do
end end
end end
it 'is not valid', :aggregate_failures do it { is_expected.to_not allow_value(account).for(:account).against(:base).with_message(I18n.t('scheduled_statuses.over_daily_limit', limit: ScheduledStatus::DAILY_LIMIT)) }
expect(subject).to_not be_valid
expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_daily_limit', limit: ScheduledStatus::DAILY_LIMIT))
end
end end
end end
end end