Simplify model validation specs for Announcement
(#32481)
This commit is contained in:
parent
c0f46e9031
commit
bd0c826a3d
@ -67,18 +67,30 @@ RSpec.describe Announcement do
|
|||||||
it { is_expected.to validate_presence_of(:text) }
|
it { is_expected.to validate_presence_of(:text) }
|
||||||
|
|
||||||
describe 'ends_at' do
|
describe 'ends_at' do
|
||||||
it 'validates presence when starts_at is present' do
|
context 'when starts_at is present' do
|
||||||
record = Fabricate.build(:announcement, starts_at: 1.day.ago)
|
subject { Fabricate.build :announcement, starts_at: 1.day.ago }
|
||||||
|
|
||||||
expect(record).to_not be_valid
|
it { is_expected.to validate_presence_of(:ends_at) }
|
||||||
expect(record.errors[:ends_at]).to be_present
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not validate presence when starts_at is missing' do
|
context 'when starts_at is missing' do
|
||||||
record = Fabricate.build(:announcement, starts_at: nil)
|
subject { Fabricate.build :announcement, starts_at: nil }
|
||||||
|
|
||||||
expect(record).to be_valid
|
it { is_expected.to_not validate_presence_of(:ends_at) }
|
||||||
expect(record.errors[:ends_at]).to_not be_present
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'starts_at' do
|
||||||
|
context 'when ends_at is present' do
|
||||||
|
subject { Fabricate.build :announcement, ends_at: 1.day.ago }
|
||||||
|
|
||||||
|
it { is_expected.to validate_presence_of(:starts_at) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when ends_at is missing' do
|
||||||
|
subject { Fabricate.build :announcement, ends_at: nil }
|
||||||
|
|
||||||
|
it { is_expected.to_not validate_presence_of(:starts_at) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user