Skip to content

Commit d515fba

Browse files
committed
Validate School rejected/verified timestamps
To ensure only one of these fields can be set at a time.
1 parent 7eaf166 commit d515fba

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/models/school.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class School < ApplicationRecord
1717
validates :creator_id, presence: true, uniqueness: true
1818
validates :creator_agree_authority, presence: true, acceptance: true
1919
validates :creator_agree_terms_and_conditions, presence: true, acceptance: true
20+
validates :rejected_at, absence: { if: proc { |school| school.verified? } }
21+
validates :verified_at, absence: { if: proc { |school| school.rejected? } }
2022

2123
before_validation :normalize_reference
2224

spec/models/school_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@
177177
school.creator_agree_terms_and_conditions = false
178178
expect(school).to be_invalid
179179
end
180+
181+
it 'cannot have #rejected_at set when #verified_at is present' do
182+
school.update!(verified_at: Time.zone.now)
183+
school.update(rejected_at: Time.zone.now)
184+
expect(school.errors[:rejected_at]).to include('must be blank')
185+
end
186+
187+
it 'cannot have #verified_at set when #rejected_at is present' do
188+
school.update!(rejected_at: Time.zone.now)
189+
school.update(verified_at: Time.zone.now)
190+
expect(school.errors[:verified_at]).to include('must be blank')
191+
end
180192
end
181193

182194
describe '#creator' do

0 commit comments

Comments
 (0)