Permalink
Browse files

Add test for nested included polymoprhic associations

  • Loading branch information...
1 parent c4e5cd5 commit cbd7d7d38553bdbf70ff35e46dd419a09aa712f9 twinturbo committed Apr 24, 2012
Showing with 22 additions and 12 deletions.
  1. +22 −12 test/serializer_test.rb
@@ -1093,7 +1093,10 @@ def test_multiple_polymorphic_associations
end
orange_serializer = Class.new(ActiveModel::Serializer) do
+ embed :ids, :include => true
+
attributes :plu, :id
+ has_one :readable, :polymorphic => true
end
email_class = Class.new(Model) do
@@ -1111,8 +1114,12 @@ def self.to_s
"Orange"
end
+ def readable
+ @attributes[:readable]
+ end
+
define_method :active_model_serializer do
- orange_serializer
+ orange_serializer
end
end
@@ -1128,7 +1135,7 @@ def self.to_s
end
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({
:name => 'logo.png',
@@ -1141,22 +1148,25 @@ def self.to_s
actual = attachment_serializer.new(attachment, {}).as_json
assert_equal({
+ :emails => [{
+ :subject => "Hello",
+ :body => "World",
+ :id => 1
+ }],
+
+ :oranges => [{
+ :plu => "3027",
+ :id => 1,
+ :readable => { :email => 1 }
+ }],
+
:attachment => {
:name => 'logo.png',
:url => 'http://example.com/logo.png',
:attachable => { :email => 1 },
:readable => { :email => 1 },
:edible => { :orange => 1 }
- },
- :emails => [{
- :id => 1,
- :subject => "Hello",
- :body => "World"
- }],
- :oranges => [{
- :id => 1,
- :plu => "3027"
- }]
+ }
}, actual)
end
end

0 comments on commit cbd7d7d

Please sign in to comment.