mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #1169 from senny/specify_a_custom_active_model_name
Specify the name to be used for ActiveModel::Name fixes #1168
This commit is contained in:
commit
19ee8413de
2 changed files with 41 additions and 3 deletions
|
@ -7,8 +7,9 @@ module ActiveModel
|
|||
attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key
|
||||
alias_method :cache_key, :collection
|
||||
|
||||
def initialize(klass, namespace = nil)
|
||||
super(klass.name)
|
||||
def initialize(klass, namespace = nil, name = nil)
|
||||
name ||= klass.name
|
||||
super(name)
|
||||
@unnamespaced = self.sub(/^#{namespace.name}::/, '') if namespace
|
||||
|
||||
@klass = klass
|
||||
|
|
|
@ -114,6 +114,44 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class NamingWithSuppliedModelNameTest < ActiveModel::TestCase
|
||||
def setup
|
||||
@model_name = ActiveModel::Name.new(Blog::Post, nil, 'Article')
|
||||
end
|
||||
|
||||
def test_singular
|
||||
assert_equal 'article', @model_name.singular
|
||||
end
|
||||
|
||||
def test_plural
|
||||
assert_equal 'articles', @model_name.plural
|
||||
end
|
||||
|
||||
def test_element
|
||||
assert_equal 'article', @model_name.element
|
||||
end
|
||||
|
||||
def test_collection
|
||||
assert_equal 'articles', @model_name.collection
|
||||
end
|
||||
|
||||
def test_partial_path
|
||||
assert_equal 'articles/article', @model_name.partial_path
|
||||
end
|
||||
|
||||
def test_human
|
||||
'Article'
|
||||
end
|
||||
|
||||
def test_route_key
|
||||
assert_equal 'articles', @model_name.route_key
|
||||
end
|
||||
|
||||
def test_param_key
|
||||
assert_equal 'article', @model_name.param_key
|
||||
end
|
||||
end
|
||||
|
||||
class NamingHelpersTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@klass = Contact
|
||||
|
@ -171,4 +209,3 @@ class NamingHelpersTest < Test::Unit::TestCase
|
|||
ActiveModel::Naming.send(method, *args)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue