From cb316b00f7b369d93faa577ad50109ac6b6691b8 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 11 Jan 2012 20:28:07 -0700 Subject: [PATCH] Write more tests --- test/association_test.rb | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/association_test.rb b/test/association_test.rb index 036ebacc..dcb8d53e 100644 --- a/test/association_test.rb +++ b/test/association_test.rb @@ -82,6 +82,23 @@ class AssociationTest < ActiveModel::TestCase }, @root_hash) end + def test_include_bang_with_embed_false + include! :comments, :value => @post.comments, :embed => false + + assert_equal({}, @hash) + assert_equal({}, @root_hash) + end + + def test_include_bang_with_embed_ids_include_false + include! :comments, :value => @post.comments, :embed => :ids, :include => false + + assert_equal({ + :comments => [ 1 ] + }, @hash) + + assert_equal({}, @root_hash) + end + def test_include_bang_has_one_associations include! :comment, :value => @post.comment @@ -216,6 +233,17 @@ class AssociationTest < ActiveModel::TestCase assert_equal({}, @root_hash) end + def test_embed_false_for_has_many_associations + @post_serializer_class.class_eval do + has_many :comments, :embed => false + end + + include_bare! :comments + + assert_equal({}, @hash) + assert_equal({}, @root_hash) + end + def test_embed_ids_include_true_for_has_many_associations @post_serializer_class.class_eval do has_many :comments, :embed => :ids, :include => true @@ -233,5 +261,48 @@ class AssociationTest < ActiveModel::TestCase ] }, @root_hash) end + + def test_embed_ids_for_has_one_associations + @post_serializer_class.class_eval do + has_one :comment, :embed => :ids + end + + include_bare! :comment + + assert_equal({ + :comment => 1 + }, @hash) + + assert_equal({}, @root_hash) + end + + def test_embed_false_for_has_one_associations + @post_serializer_class.class_eval do + has_one :comment, :embed => false + end + + include_bare! :comment + + assert_equal({}, @hash) + assert_equal({}, @root_hash) + end + + def test_embed_ids_include_true_for_has_one_associations + @post_serializer_class.class_eval do + has_one :comment, :embed => :ids, :include => true + end + + include_bare! :comment + + assert_equal({ + :comment => 1 + }, @hash) + + assert_equal({ + :comments => [ + { :id => 1, :body => "ZOMG A COMMENT" } + ] + }, @root_hash) + end end end