From 3e19ec1a365e2fe91ac09d9ddff7c82a849be65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 4 Dec 2009 16:29:08 -0200 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). --- activerecord/lib/active_record/validations.rb | 9 +-------- activerecord/test/cases/validations_i18n_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 1dc7c96..3468af8 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -153,16 +153,9 @@ module ActiveRecord # error can be added to the same +attribute+ in which case an array will be returned on a call to on(attribute). # If no +messsage+ is supplied, :invalid is assumed. # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error). - # def add(attribute, message = nil, options = {}) - # message ||= :invalid - # message = generate_message(attribute, message, options)) if message.is_a?(Symbol) - # @errors[attribute.to_s] ||= [] - # @errors[attribute.to_s] << message - # end - def add(error_or_attr, message = nil, options = {}) error, attribute = error_or_attr.is_a?(Error) ? [error_or_attr, error_or_attr.attribute] : [nil, error_or_attr] - options[:message] = options.delete(:default) if options.has_key?(:default) + options[:message] = options.delete(:default) if options[:default].is_a?(Symbol) @errors[attribute.to_s] ||= [] @errors[attribute.to_s] << (error || Error.new(@base, attribute, message, options)) diff --git a/activerecord/test/cases/validations_i18n_test.rb b/activerecord/test/cases/validations_i18n_test.rb index f2e3e5a..9d29385 100644 --- a/activerecord/test/cases/validations_i18n_test.rb +++ b/activerecord/test/cases/validations_i18n_test.rb @@ -521,6 +521,12 @@ class ActiveRecordErrorI18nTests < ActiveSupport::TestCase 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" -- 1.6.5