diff --git a/app/models/person.rb b/app/models/person.rb index 3bd9f6c..bf1267e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,7 +1,7 @@ # A person is the profile of an user holding all relationships with the rest of the system class Person < Profile - attr_accessible :organization, :contact_information, :sex + attr_accessible :organization, :contact_information, :sex, :birth_date SEARCH_FILTERS += %w[ more_popular @@ -159,9 +159,8 @@ class Person < Profile validates_multiparameter_assignments validates_each :birth_date do |record,attr,value| - if value && value.year == 1 - record.errors.add(attr) - end + date_str = record.birth_date_before_type_cast + record.errors.add(attr) if value.blank? && !date_str.blank? end def self.fields diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index d0208fd..b881106 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1168,14 +1168,14 @@ class PersonTest < ActiveSupport::TestCase should 'handle multiparameter attribute exception on birth date field' do assert_nothing_raised ActiveRecord::MultiparameterAssignmentErrors do p = Person.new( - :name => 'birthday', :identifier => 'birthday', :user_id => 999, + :name => 'birthday', :identifier => 'birthday', 'birth_date(1i)' => '', 'birth_date(2i)' => '6', 'birth_date(3i)' => '16' ) 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 = Person.new(:birth_date => "1115") p.valid? assert p.errors[:birth_date.to_s].present? end -- libgit2 0.21.2