mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Write more tests
This commit is contained in:
parent
2bae9363c7
commit
cb316b00f7
@ -82,6 +82,23 @@ class AssociationTest < ActiveModel::TestCase
|
|||||||
}, @root_hash)
|
}, @root_hash)
|
||||||
end
|
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
|
def test_include_bang_has_one_associations
|
||||||
include! :comment, :value => @post.comment
|
include! :comment, :value => @post.comment
|
||||||
|
|
||||||
@ -216,6 +233,17 @@ class AssociationTest < ActiveModel::TestCase
|
|||||||
assert_equal({}, @root_hash)
|
assert_equal({}, @root_hash)
|
||||||
end
|
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
|
def test_embed_ids_include_true_for_has_many_associations
|
||||||
@post_serializer_class.class_eval do
|
@post_serializer_class.class_eval do
|
||||||
has_many :comments, :embed => :ids, :include => true
|
has_many :comments, :embed => :ids, :include => true
|
||||||
@ -233,5 +261,48 @@ class AssociationTest < ActiveModel::TestCase
|
|||||||
]
|
]
|
||||||
}, @root_hash)
|
}, @root_hash)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user