mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56: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
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
object.class.to_s.demodulize.underscore.pluralize
|
object.class.model_name.plural
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes(options = {})
|
def attributes(options = {})
|
||||||
|
|||||||
@ -203,7 +203,7 @@ module ActiveModel
|
|||||||
assert_equal expected, alt_adapter.serializable_hash[:included]
|
assert_equal expected, alt_adapter.serializable_hash[:included]
|
||||||
end
|
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 = Post.new(id: 123)
|
||||||
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
|
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
|
||||||
serializer = SpammyPostSerializer.new(spammy_post)
|
serializer = SpammyPostSerializer.new(spammy_post)
|
||||||
@ -212,7 +212,7 @@ module ActiveModel
|
|||||||
expected = {
|
expected = {
|
||||||
related: {
|
related: {
|
||||||
data: [{
|
data: [{
|
||||||
type: 'unrelated_links',
|
type: 'spam_unrelated_links',
|
||||||
id: '456'
|
id: '456'
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
4
test/fixtures/poro.rb
vendored
4
test/fixtures/poro.rb
vendored
@ -1,6 +1,10 @@
|
|||||||
class Model
|
class Model
|
||||||
FILE_DIGEST = Digest::MD5.hexdigest(File.open(__FILE__).read)
|
FILE_DIGEST = Digest::MD5.hexdigest(File.open(__FILE__).read)
|
||||||
|
|
||||||
|
def self.model_name
|
||||||
|
@_model_name ||= ActiveModel::Name.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(hash={})
|
def initialize(hash={})
|
||||||
@attributes = hash
|
@attributes = hash
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user