Skip to content

Commit

Permalink
validates_date_time: add support for I18N [Roman Shterenzon]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.viney.net.nz/things/rails/plugins/validates_date_time@407 20afb1e0-9c0e-0410-9884-91ed27886737
  • Loading branch information
jonathan committed Mar 4, 2009
1 parent 34c6c16 commit b301c20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG
@@ -1,4 +1,8 @@
[18 February 2008]
[5 March 2009]

* Add support for I18N [Roman Shterenzon]

[18 February 2009]

* Fix errors caused by assigning values that don't respond to #strip.

Expand Down
4 changes: 2 additions & 2 deletions lib/validates_date_time.rb
Expand Up @@ -114,7 +114,7 @@ def validate_before_and_after_restrictions(record, attr_name, value, options)
if options[:before]
options[:before].each do |r|
if r.value(record) and value >= r.last_value
record.errors.add(attr_name, options[:before_message] % r)
record.errors.add(attr_name, :before, :value => r, :default => options[:before_message] % r)
break
end
end
Expand All @@ -123,7 +123,7 @@ def validate_before_and_after_restrictions(record, attr_name, value, options)
if options[:after]
options[:after].each do |r|
if r.value(record) and value <= r.last_value
record.errors.add(attr_name, options[:after_message] % r)
record.errors.add(attr_name, :after, :value => r, :default => options[:after_message] % r)
break
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/date_test.rb
Expand Up @@ -69,6 +69,19 @@ def test_before_and_after_with_custom_message
assert_invalid_and_errors_match /avant/, :date_of_arrival => 2.years.from_now, :date_of_departure => 2.years.ago
assert_invalid_and_errors_match /apres/, :date_of_arrival => '1792-03-03'
end

def test_before_and_after_with_i18n
original_load_path = I18n.load_path

I18n.load_path = [File.join(File.dirname(__FILE__),'fixtures/en.yml')]
I18n.reload!

assert_invalid_and_errors_match /i18n_before/, :date_of_death => (Date.today + 1).to_s
assert_invalid_and_errors_match /i18n_after/, :date_of_birth => (Date.today + 1).to_s
ensure
I18n.load_path = original_load_path
I18n.reload!
end

def test_dates_with_unknown_year
assert p.update_attributes!(:date_of_birth => '9999-12-11')
Expand Down

0 comments on commit b301c20

Please sign in to comment.