Commit 36b6acfcd3f11eb8f7260080995cc0e029037865
1 parent
7c9e07f7
Exists in
master
and in
28 other branches
Don't accept borth dates with empty year
When the year is empty, it ends up as 1 in the date object.
Showing
2 changed files
with
12 additions
and
0 deletions
Show diff stats
app/models/person.rb
@@ -120,6 +120,12 @@ class Person < Profile | @@ -120,6 +120,12 @@ class Person < Profile | ||
120 | 120 | ||
121 | validates_multiparameter_assignments | 121 | validates_multiparameter_assignments |
122 | 122 | ||
123 | + validates_each :birth_date do |record,attr,value| | ||
124 | + if value && value.year == 1 | ||
125 | + record.errors.add(attr, _('%{fn} is invalid')) | ||
126 | + end | ||
127 | + end | ||
128 | + | ||
123 | def self.fields | 129 | def self.fields |
124 | FIELDS | 130 | FIELDS |
125 | end | 131 | end |
test/unit/person_test.rb
@@ -1193,6 +1193,12 @@ class PersonTest < ActiveSupport::TestCase | @@ -1193,6 +1193,12 @@ class PersonTest < ActiveSupport::TestCase | ||
1193 | end | 1193 | end |
1194 | end | 1194 | end |
1195 | 1195 | ||
1196 | + should 'not accept an empty year on birth date' do | ||
1197 | + p = Person.new({"birth_date(2i)"=>"11", "birth_date(3i)"=>"15", "birth_date(1i)"=>""}) | ||
1198 | + p.valid? | ||
1199 | + assert p.errors.invalid?(:birth_date) | ||
1200 | + end | ||
1201 | + | ||
1196 | should 'associate report with the correct complaint' do | 1202 | should 'associate report with the correct complaint' do |
1197 | p1 = create_user('user1').person | 1203 | p1 = create_user('user1').person |
1198 | p2 = create_user('user2').person | 1204 | p2 = create_user('user2').person |