diff --git a/app/models/person.rb b/app/models/person.rb index 6c3c609..02bdf96 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -120,6 +120,12 @@ class Person < Profile validates_multiparameter_assignments + validates_each :birth_date do |record,attr,value| + if value && value.year == 1 + record.errors.add(attr, _('%{fn} is invalid')) + end + end + def self.fields FIELDS end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index c8c4b84..3609fee 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1193,6 +1193,12 @@ class PersonTest < ActiveSupport::TestCase end end + should 'not accept an empty year on birth date' do + p = Person.new({"birth_date(2i)"=>"11", "birth_date(3i)"=>"15", "birth_date(1i)"=>""}) + p.valid? + assert p.errors.invalid?(:birth_date) + end + should 'associate report with the correct complaint' do p1 = create_user('user1').person p2 = create_user('user2').person -- libgit2 0.21.2