Permalink
Browse files

Fix error_messages_for i18n issue if object_name has underscores [#3629

… status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 4158282 commit 6227ec11f0bd10e0b987e2dc9030e57de6d46d54 @m4n m4n committed with josevalim Feb 17, 2010
View
4 actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -193,8 +193,8 @@ def error_messages_for(*params)
header_message = if options.include?(:header_message)
options[:header_message]
else
- object_name = options[:object_name].to_s.gsub('_', ' ')
- object_name = I18n.t(object_name, :default => object_name, :scope => [:activerecord, :models], :count => 1)
+ object_name = options[:object_name].to_s
+ object_name = I18n.t(object_name, :default => object_name.gsub('_', ' '), :scope => [:activerecord, :models], :count => 1)
locale.t :header, :count => count, :model => object_name
end
message = options.include?(:message) ? options[:message] : locale.t(:body)
View
11 actionpack/test/template/active_record_helper_i18n_test.rb
@@ -2,7 +2,7 @@
class ActiveRecordHelperI18nTest < Test::Unit::TestCase
include ActionView::Helpers::ActiveRecordHelper
-
+
attr_reader :request
def setup
@object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
@@ -35,10 +35,17 @@ def test_error_messages_for_given_no_message_option_it_translates_message
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
error_messages_for(:object => @object, :locale => 'en')
end
-
+
def test_error_messages_for_given_object_name_it_translates_object_name
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
end
+
+ def test_error_messages_for_given_object_name_with_underscore_it_translates_object_name
+ I18n.expects(:t).with('bank_account', :default => 'bank account', :count => 1, :scope => [:activerecord, :models]).once.returns 'bank account'
+ I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => 'bank account').returns "1 error prohibited this bank account from being saved"
+ error_messages_for(:object => @object, :locale => 'en', :object_name => 'bank_account')
+ end
end
+

0 comments on commit 6227ec1

Please sign in to comment.