Avoid crash validating event type with blank length
The `length_step` validator runs unconditionally for every record and calls `length % program.schedule_interval`. When the length field is left blank in the admin form, `length` is nil and `length %` raises NoMethodError, returning a 500 Internal Server Error instead of a regular validation failure. Skip the divisor check unless `length` is numeric so that the `numericality` validator on `:length` can produce a proper error message, restoring the usual validation feedback.
This commit is contained in:
parent
c8e6fabed1
commit
11e7c27759
2 changed files with 12 additions and 1 deletions
|
|
@ -44,6 +44,13 @@ describe EventType do
|
|||
it 'is not valid when length is not multiple of LENGTH_STEP' do
|
||||
expect(build(:event_type, program: conference.program, length: 37)).not_to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid when length is blank and does not raise during validation' do
|
||||
event_type = build(:event_type, program: conference.program, length: nil)
|
||||
expect { event_type.valid? }.not_to raise_error
|
||||
expect(event_type).not_to be_valid
|
||||
expect(event_type.errors[:length]).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue