Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Delegate #model_name method to self.class

  • Loading branch information...
commit 10adc2ee90c34003edb5850b63c6cae321c09008 1 parent 04b6ae4
Yuki Nishijima yuki24 authored
6 activemodel/lib/active_model/naming.rb
View
@@ -214,6 +214,12 @@ def _singularize(string, replacement='_')
# 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).
6 activemodel/test/cases/naming_test.rb
View
@@ -272,3 +272,9 @@ def test_anonymous_class_with_name_argument
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
Please sign in to comment.
Something went wrong with that request. Please try again.