From 8cb24697f9d7d144073ffb71ca177bbfa358cbf0 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 25 Apr 2010 12:46:23 -0400 Subject: [PATCH] backport 77c099c231f2efb36a2a77a32138ed5c6761ec19 commit for 2-3-branch --- activerecord/lib/active_record/locale/en.yml | 1 + activerecord/lib/active_record/validations.rb | 2 +- activerecord/test/cases/validations_i18n_test.rb | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/activerecord/lib/active_record/locale/en.yml b/activerecord/lib/active_record/locale/en.yml index 2813524..4050b39 100644 --- a/activerecord/lib/active_record/locale/en.yml +++ b/activerecord/lib/active_record/locale/en.yml @@ -16,6 +16,7 @@ en: wrong_length: "is the wrong length (should be {{count}} characters)" taken: "has already been taken" not_a_number: "is not a number" + not_an_integer: "must be an integer" greater_than: "must be greater than {{count}}" greater_than_or_equal_to: "must be greater than or equal to {{count}}" equal_to: "must be equal to {{count}}" diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 41d28f3..61afa88 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -1022,7 +1022,7 @@ module ActiveRecord if configuration[:only_integer] unless raw_value.to_s =~ /\A[+-]?\d+\Z/ - record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message]) + record.errors.add(attr_name, :not_an_integer, :value => raw_value, :default => configuration[:message]) next end raw_value = raw_value.to_i diff --git a/activerecord/test/cases/validations_i18n_test.rb b/activerecord/test/cases/validations_i18n_test.rb index 9d29385..f10537a 100644 --- a/activerecord/test/cases/validations_i18n_test.rb +++ b/activerecord/test/cases/validations_i18n_test.rb @@ -383,23 +383,23 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase # validates_numericality_of :not_a_number, with :only_integer test "#validates_numericality_of (:not_a_number, with :only_integer) no custom message" do - expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do + expect_error_added(@topic, :title, :not_an_integer, :default => nil, :value => '1.0') do Topic.validates_numericality_of :title, :only_integer => true - @topic.title = 'a' + @topic.title = '1.0' end end test "#validates_numericality_of (:not_a_number, with :only_integer) and a custom message" do - expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do + expect_error_added(@topic, :title, :not_an_integer, :default => 'custom', :value => '1.0') do Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom' - @topic.title = 'a' + @topic.title = '1.0' end end test "#validates_numericality_of (:not_a_number, with :only_integer) finds the correct message translations" do - assert_message_translations(@topic, :title, :not_a_number) do + assert_message_translations(@topic, :title, :not_an_integer) do Topic.validates_numericality_of :title, :only_integer => true - @topic.title = 'a' + @topic.title = '1.0' end end -- 1.6.5.2