mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add test for nested included polymoprhic associations
This commit is contained in:
parent
c4e5cd547b
commit
cbd7d7d385
@ -1093,7 +1093,10 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
orange_serializer = Class.new(ActiveModel::Serializer) do
|
orange_serializer = Class.new(ActiveModel::Serializer) do
|
||||||
|
embed :ids, :include => true
|
||||||
|
|
||||||
attributes :plu, :id
|
attributes :plu, :id
|
||||||
|
has_one :readable, :polymorphic => true
|
||||||
end
|
end
|
||||||
|
|
||||||
email_class = Class.new(Model) do
|
email_class = Class.new(Model) do
|
||||||
@ -1111,8 +1114,12 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
"Orange"
|
"Orange"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def readable
|
||||||
|
@attributes[:readable]
|
||||||
|
end
|
||||||
|
|
||||||
define_method :active_model_serializer do
|
define_method :active_model_serializer do
|
||||||
orange_serializer
|
orange_serializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1128,7 +1135,7 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
email = email_class.new :id => 1, :subject => "Hello", :body => "World"
|
email = email_class.new :id => 1, :subject => "Hello", :body => "World"
|
||||||
orange = orange_class.new :id => 1, :plu => "3027"
|
orange = orange_class.new :id => 1, :plu => "3027", readable: email
|
||||||
|
|
||||||
attachment = Attachment.new({
|
attachment = Attachment.new({
|
||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
@ -1141,22 +1148,25 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
actual = attachment_serializer.new(attachment, {}).as_json
|
actual = attachment_serializer.new(attachment, {}).as_json
|
||||||
|
|
||||||
assert_equal({
|
assert_equal({
|
||||||
|
:emails => [{
|
||||||
|
:subject => "Hello",
|
||||||
|
:body => "World",
|
||||||
|
:id => 1
|
||||||
|
}],
|
||||||
|
|
||||||
|
:oranges => [{
|
||||||
|
:plu => "3027",
|
||||||
|
:id => 1,
|
||||||
|
:readable => { :email => 1 }
|
||||||
|
}],
|
||||||
|
|
||||||
:attachment => {
|
:attachment => {
|
||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
:url => 'http://example.com/logo.png',
|
:url => 'http://example.com/logo.png',
|
||||||
:attachable => { :email => 1 },
|
:attachable => { :email => 1 },
|
||||||
:readable => { :email => 1 },
|
:readable => { :email => 1 },
|
||||||
:edible => { :orange => 1 }
|
:edible => { :orange => 1 }
|
||||||
},
|
}
|
||||||
:emails => [{
|
|
||||||
:id => 1,
|
|
||||||
:subject => "Hello",
|
|
||||||
:body => "World"
|
|
||||||
}],
|
|
||||||
:oranges => [{
|
|
||||||
:id => 1,
|
|
||||||
:plu => "3027"
|
|
||||||
}]
|
|
||||||
}, actual)
|
}, actual)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user