mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
Add failing test for polymorphic with include
This commit is contained in:
parent
7e96856b87
commit
3ca1621011
@ -1035,4 +1035,45 @@ class SerializerTest < ActiveModel::TestCase
|
||||
}
|
||||
}, actual)
|
||||
end
|
||||
|
||||
def test_polymorphic_associations_are_included_at_root
|
||||
email_serializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :subject, :body
|
||||
end
|
||||
|
||||
email_class = Class.new(Model) do
|
||||
def self.to_s
|
||||
"Email"
|
||||
end
|
||||
|
||||
define_method :active_model_serializer do
|
||||
email_serializer
|
||||
end
|
||||
end
|
||||
|
||||
attachment_serializer = Class.new(ActiveModel::Serializer) do
|
||||
embed :ids, :include => true
|
||||
attributes :name, :url
|
||||
has_one :attachable, :polymorphic => true
|
||||
end
|
||||
|
||||
email = email_class.new :id => 1, :subject => "Hello", :body => "World"
|
||||
|
||||
attachment = Attachment.new :name => 'logo.png', :url => 'http://example.com/logo.png', :attachable => email
|
||||
|
||||
actual = attachment_serializer.new(attachment, {}).as_json
|
||||
|
||||
assert_equal({
|
||||
:name => 'logo.png',
|
||||
:url => 'http://example.com/logo.png',
|
||||
:attachable => {
|
||||
:email => 1
|
||||
},
|
||||
:emails => [{
|
||||
:id => 1,
|
||||
:subject => "Hello",
|
||||
:body => "World"
|
||||
}]
|
||||
}, actual)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user