use model name to determine the type

This commit is contained in:
Lachlan Sylvester 2015-06-12 18:53:47 +10:00
parent de23501995
commit 97e82c3eb7
3 changed files with 7 additions and 3 deletions

View File

@ -188,7 +188,7 @@ module ActiveModel
end
def type
object.class.to_s.demodulize.underscore.pluralize
object.class.model_name.plural
end
def attributes(options = {})

View File

@ -203,7 +203,7 @@ module ActiveModel
assert_equal expected, alt_adapter.serializable_hash[:included]
end
def test_ignore_model_namespace_for_linked_resource_type
def test_underscore_model_namespace_for_linked_resource_type
spammy_post = Post.new(id: 123)
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
serializer = SpammyPostSerializer.new(spammy_post)
@ -212,7 +212,7 @@ module ActiveModel
expected = {
related: {
data: [{
type: 'unrelated_links',
type: 'spam_unrelated_links',
id: '456'
}]
}

View File

@ -1,6 +1,10 @@
class Model
FILE_DIGEST = Digest::MD5.hexdigest(File.open(__FILE__).read)
def self.model_name
@_model_name ||= ActiveModel::Name.new(self)
end
def initialize(hash={})
@attributes = hash
end