From 7d548f795d226f57278f8bdd36298c9552421053 Mon Sep 17 00:00:00 2001 From: Justin French Date: Mon, 29 Jun 2009 15:54:09 +0200 Subject: Changed ActiveRecord::Base.human_name to underscore the class name before it humanizes it This gives you 'Post comment' rather than 'Postcomment' by default. Signed-off-by: Michael Koziarski [#2120 state:committed] --- activerecord/lib/active_record/base.rb | 6 +++--- activerecord/test/cases/reflection_test.rb | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index f1b7c323dc..ff5a836b52 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1404,14 +1404,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_descendants_from_active_record.map do |klass| :"#{klass.name.underscore}" - end - defaults << self.name.humanize + end + 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 db64bbb806..d861b5bb24 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -5,14 +5,20 @@ 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) end + def test_human_name + assert_equal "Price estimate", PriceEstimate.human_name + assert_equal "Subscriber", Subscriber.human_name + end + def test_column_null_not_null subscriber = Subscriber.find(:first) assert subscriber.column_for_attribute("name").null -- cgit v1.2.3