From 1c3711b21b5c80343a51e19504552b3f6c34ac73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 16 Dec 2009 14:18:46 -0600 Subject: [PATCH] Fix another regression due to the inclusion of ActiveRecord::Error. If a string is supplied to :default, it should not be used a translation key (we already have :message for that). [#3564 status:resolved] Signed-off-by: Joshua Peek --- activerecord/lib/active_record/validations.rb | 2 +- activerecord/test/cases/validations_i18n_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 568e530c95625..41d28f361b805 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -158,7 +158,7 @@ def add_to_base(msg) # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error). # def add(attribute, message = nil, options = {}) - options[:message] = options.delete(:default) if options.has_key?(:default) + options[:message] = options.delete(:default) if options[:default].is_a?(Symbol) error, message = message, nil if message.is_a?(Error) @errors[attribute.to_s] ||= [] diff --git a/activerecord/test/cases/validations_i18n_test.rb b/activerecord/test/cases/validations_i18n_test.rb index f2e3e5aeb4101..9d29385287b83 100644 --- a/activerecord/test/cases/validations_i18n_test.rb +++ b/activerecord/test/cases/validations_i18n_test.rb @@ -521,6 +521,12 @@ def assert_full_message(message, *args) assert_equal message, ActiveRecord::Error.new(@reply, *args).full_message end + test ":default is only given to message if a symbol is supplied" do + store_translations(:errors => { :messages => { :"foo bar" => "You fooed: {{value}}." } }) + @reply.errors.add(:title, :inexistent, :default => "foo bar") + assert_equal "foo bar", @reply.errors[:title] + end + test "#generate_message passes the model attribute value for interpolation" do store_translations(:errors => { :messages => { :foo => "You fooed: {{value}}." } }) @reply.title = "da title"