aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@basecamp.com>2014-06-24 13:54:58 +0200
committerDavid Heinemeier Hansson <david@basecamp.com>2014-06-24 13:54:58 +0200
commitd5d94a7750cf2744cc1658dd20fa26c008fb6249 (patch)
tree1c767bd004b25ef857692ead497917a24c0c8f57
parentb27e856d3f736be34b1df885ce6a795c9a015375 (diff)
parent10adc2ee90c34003edb5850b63c6cae321c09008 (diff)
downloadrails-d5d94a7750cf2744cc1658dd20fa26c008fb6249.tar.gz
rails-d5d94a7750cf2744cc1658dd20fa26c008fb6249.tar.bz2
rails-d5d94a7750cf2744cc1658dd20fa26c008fb6249.zip
Merge pull request #15871 from yuki24/add-model-name-instance-method
Add #model_name instance method to ActiveModel::Naming
-rw-r--r--activemodel/lib/active_model/naming.rb6
-rw-r--r--activemodel/test/cases/naming_test.rb6
2 files changed, 12 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
index 5219de2606..8cf1a191f4 100644
--- a/activemodel/lib/active_model/naming.rb
+++ b/activemodel/lib/active_model/naming.rb
@@ -214,6 +214,12 @@ module ActiveModel
# is required to pass the Active Model Lint test. So either extending the
# provided method below, or rolling your own is required.
module Naming
+ def self.extended(base) #:nodoc:
+ base.class_eval do
+ delegate :model_name, to: :class
+ end
+ end
+
# Returns an ActiveModel::Name object for module. It can be
# used to retrieve all kinds of naming-related information
# (See ActiveModel::Name for more information).
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb
index aa683f4152..7b8287edbf 100644
--- a/activemodel/test/cases/naming_test.rb
+++ b/activemodel/test/cases/naming_test.rb
@@ -272,3 +272,9 @@ class NameWithAnonymousClassTest < ActiveModel::TestCase
assert_equal "Anonymous", model_name
end
end
+
+class NamingMethodDelegationTest < ActiveModel::TestCase
+ def test_model_name
+ assert_equal Blog::Post.model_name, Blog::Post.new.model_name
+ end
+end