If an existing association exists, use it to

get the value if none was provided.
This commit is contained in:
Yehuda Katz
2012-01-11 13:06:12 -07:00
parent dd0b56c748
commit 72b8213bee
2 changed files with 89 additions and 53 deletions

View File

@@ -49,41 +49,61 @@ class AssociationTest < ActiveModel::TestCase
@root_hash = {}
end
def test_include_bang_has_many_associations
@post_serializer.include! :comments,
def include!(key, options={})
@post_serializer.include! key, options.merge(
:embed => :ids,
:include => true,
:hash => @root_hash,
:node => @hash,
:value => @post.comments,
:serializer => @comment_serializer_class
assert_equal({
:comments => [ 1 ]
}, @hash)
assert_equal({
:comments => [
{ :body => "ZOMG A COMMENT" }
]
}, @root_hash)
)
end
def test_include_bang_has_one_associations
@post_serializer.include! :comment,
:embed => :ids,
:include => true,
:hash => @root_hash,
:node => @hash,
:value => @post.comment,
:serializer => @comment_serializer_class
class NoDefaults < AssociationTest
def test_include_bang_has_many_associations
include! :comments, :value => @post.comments
assert_equal({
:comment => 1
}, @hash)
assert_equal({
:comments => [ 1 ]
}, @hash)
assert_equal({
:comments => [{ :body => "ZOMG A COMMENT" }]
}, @root_hash)
assert_equal({
:comments => [
{ :body => "ZOMG A COMMENT" }
]
}, @root_hash)
end
def test_include_bang_has_one_associations
include! :comment, :value => @post.comment
assert_equal({
:comment => 1
}, @hash)
assert_equal({
:comments => [{ :body => "ZOMG A COMMENT" }]
}, @root_hash)
end
end
class DefaultsTest < AssociationTest
def test_with_default_has_many
@post_serializer_class.class_eval do
has_many :comments
end
include! :comments
assert_equal({
:comments => [ 1 ]
}, @hash)
assert_equal({
:comments => [
{ :body => "ZOMG A COMMENT" }
]
}, @root_hash)
end
end
end