Skip to content

Commit

Permalink
Object names with underscore do the wrong lookup in I18n on error_mes…
Browse files Browse the repository at this point in the history
…sages_for.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2390 state:committed]
  • Loading branch information
josevalim authored and NZKoz committed Apr 5, 2009
1 parent 42cdc75 commit 1ab7c37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/active_record_helper.rb
Expand Up @@ -194,7 +194,7 @@ def error_messages_for(*params)
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 = I18n.t(options[:object_name].to_s, :default => object_name, :scope => [:activerecord, :models], :count => 1)
locale.t :header, :count => count, :model => object_name
end
message = options.include?(:message) ? options[:message] : locale.t(:body)
Expand Down
9 changes: 6 additions & 3 deletions actionpack/test/template/active_record_helper_i18n_test.rb
Expand Up @@ -4,9 +4,12 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase
include ActionView::Helpers::ActiveRecordHelper

attr_reader :request

def setup
@object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
@object_name = 'book'
@object_name = 'book_seller'
@object_name_without_underscore = 'book seller'

stubs(:content_tag).returns 'content_tag'

I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
Expand Down Expand Up @@ -37,8 +40,8 @@ def test_error_messages_for_given_no_message_option_it_translates_message
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
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name_without_underscore).returns "1 error prohibited this #{@object_name_without_underscore} from being saved"
I18n.expects(:t).with(@object_name, :default => @object_name_without_underscore, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name_without_underscore
error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
end
end

0 comments on commit 1ab7c37

Please sign in to comment.