Skip to content

Commit

Permalink
Fix another regression due to the inclusion of ActiveRecord::Error.
Browse files Browse the repository at this point in the history
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 <josh@joshpeek.com>
  • Loading branch information
josevalim authored and josh committed Dec 16, 2009
1 parent b1bbf90 commit 1c3711b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations.rb
Expand Up @@ -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] ||= []
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/validations_i18n_test.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 1c3711b

Please sign in to comment.