mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #953 from lsylvester/use-active-model-name-for-type
use model name to determine the type
This commit is contained in:
commit
7fa123bd6b
@ -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 = {})
|
||||
|
||||
@ -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'
|
||||
}]
|
||||
}
|
||||
|
||||
4
test/fixtures/poro.rb
vendored
4
test/fixtures/poro.rb
vendored
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user