From 19b8b6623793b7be69c3dd31ceea5543a474c036 Mon Sep 17 00:00:00 2001 From: Justin French Date: Wed, 4 Mar 2009 18:07:01 +1100 Subject: [PATCH] Changed ActiveRecord::Base.human_name to underscore the class name before it humanizes it ('Post comment' rather than 'Postcomment') by default, with a spec, since there wasn't one already. --- activerecord/lib/active_record/base.rb | 4 ++-- activerecord/test/cases/reflection_test.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index edc1459..b3a06bf 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1378,14 +1378,14 @@ module ActiveRecord #:nodoc: end # Transform the modelname into a more humane format, using I18n. - # Defaults to the basic humanize method. + # By default, it will underscore then humanize the class name (BlogPost.human_name #=> "Blog post"). # Default scope of the translation is activerecord.models # Specify +options+ with additional translating options. def human_name(options = {}) defaults = self_and_descendents_from_active_record.map do |klass| :"#{klass.name.underscore}" end - defaults << self.name.humanize + defaults << self.name.underscore.humanize I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options)) end diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index db64bbb..0e39267 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -5,9 +5,10 @@ require 'models/company' require 'models/company_in_module' require 'models/subscriber' require 'models/pirate' +require 'models/price_estimate' class ReflectionTest < ActiveRecord::TestCase - fixtures :topics, :customers, :companies, :subscribers + fixtures :topics, :customers, :companies, :subscribers, :price_estimates def setup @first = Topic.find(1) @@ -52,7 +53,12 @@ class ReflectionTest < ActiveRecord::TestCase assert subscriber.column_for_attribute("name").null assert !subscriber.column_for_attribute("nick").null end - + + def test_human_name + assert_equal "Price estimate", PriceEstimate.human_name + assert_equal "Subscriber", Subscriber.human_name + end + def test_human_name_for_column assert_equal "Author name", @first.column_for_attribute("author_name").human_name end -- 1.5.5.3