1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Introduced AR::Base.human_name to validations

This commit is contained in:
Iain Hecker 2008-08-16 20:22:40 +02:00 committed by Sven Fuchs
parent ae8a35d8f6
commit c531248938
2 changed files with 3 additions and 3 deletions

View file

@ -100,7 +100,7 @@ module ActiveRecord
options.merge!({
:default => defaults,
:model => I18n.translate(model_name.underscore, :default => model_name.humanize, :scope => [:activerecord, :models], :count => 1),
:model => @base.class.human_name,
:attribute => @base.class.human_attribute_name(attribute.to_s),
:scope => [:activerecord, :errors, :messages] })

View file

@ -46,7 +46,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
global_scope = [:activerecord, :errors, :messages]
custom_scope = global_scope + [:custom, 'topic', :title]
I18n.expects(:translate).with('topic', {:count => 1, :default => 'Topic', :scope => [:activerecord, :models]}).returns('Topic')
I18n.expects(:translate).with(:topic, {:count => 1, :default => ['Topic'], :scope => [:activerecord, :models]}).returns('Topic')
I18n.expects(:translate).with(:'topic.title', {:count => 1, :default => ['Title'], :scope => [:activerecord, :attributes]}).returns('Title')
I18n.expects(:translate).with(:"custom.topic.title.invalid", :scope => global_scope, :default => [:"custom.topic.invalid", 'default from class def error 1', :invalid], :attribute => "Title", :model => "Topic").returns('default from class def error 1')
@topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1'
@ -54,7 +54,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
custom_scope = [:activerecord, :errors, :custom, 'topic', :title]
I18n.expects(:translate).with('reply', {:count => 1, :default => 'Reply', :scope => [:activerecord, :models]}).returns('Reply')
I18n.expects(:translate).with(:reply, {:count => 1, :default => [:topic, 'Reply'], :scope => [:activerecord, :models]}).returns('Reply')
I18n.expects(:translate).with(:'reply.title', {:count => 1, :default => [:'topic.title', 'Title'], :scope => [:activerecord, :attributes]}).returns('Title')
I18n.expects(:translate).with(:"custom.reply.title.invalid", :scope => [:activerecord, :errors, :messages], :default => [:"custom.reply.invalid", :"custom.topic.title.invalid", :"custom.topic.invalid", 'default from class def', :invalid], :model => 'Reply', :attribute => 'Title').returns("default from class def")
Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def'