Browse files

Introduced AR::Base.human_name to validations

  • Loading branch information...
1 parent 81e14fa commit 12d7872071c9d9bd0ba555cd99945690862fa483 Iain Hecker committed with svenfuchs Aug 16, 2008
View
2 activerecord/lib/active_record/validations.rb
@@ -100,7 +100,7 @@ def generate_message(attribute, message = :invalid, options = {})
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
4 activerecord/test/cases/validations_i18n_test.rb
@@ -46,15 +46,15 @@ def test_errors_generate_message_translates_custom_model_attribute_key
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'
end
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'

0 comments on commit 12d7872

Please sign in to comment.