Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

validates_date_time: add support for I18N [Roman Shterenzon]

git-svn-id: http://svn.viney.net.nz/things/rails/plugins/validates_date_time@407 20afb1e0-9c0e-0410-9884-91ed27886737
  • Loading branch information...
commit b301c2037d05928d558feaf8045baf35c98449a7 1 parent 34c6c16
jonathan authored
Showing with 20 additions and 3 deletions.
  1. +5 −1 CHANGELOG
  2. +2 −2 lib/validates_date_time.rb
  3. +13 −0 test/date_test.rb
View
6 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.
View
4 lib/validates_date_time.rb
@@ -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
@@ -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
View
13 test/date_test.rb
@@ -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')
Please sign in to comment.
Something went wrong with that request. Please try again.