Rename some relationship test info

This commit is contained in:
Benjamin Fleischer 2017-08-03 14:36:20 -05:00
parent 5d3194b1dc
commit 155e99cedc
2 changed files with 7 additions and 9 deletions

View File

@ -26,8 +26,8 @@ module AMS
def setup def setup
super super
@to_many_relation = [ChildRecord.new(id: 2, name: "comment")] @to_many_relation = [ChildRecord.new(id: 2, name: "to_many")]
@to_one_relation = ChildRecord.new(id: 3, name: "post") @to_one_relation = ChildRecord.new(id: 3, name: "to_one")
@object = ParentRecord.new( @object = ParentRecord.new(
id: 1, id: 1,
name: "name", name: "name",

View File

@ -5,17 +5,15 @@ module AMS
class Serializer class Serializer
class RelationshipsTest < Test class RelationshipsTest < Test
class ParentModelSerializer < Serializer class ParentModelSerializer < Serializer
# TODO: test to: :many without :ids option
# TODO: test to: :one without :id option
relation :child_models, type: :comments, to: :many, ids: "object.child_models.map(&:id)" relation :child_models, type: :comments, to: :many, ids: "object.child_models.map(&:id)"
relation :child_model, type: :comments, to: :one, id: "object.child_model.id" relation :child_model, type: :posts, to: :one, id: "object.child_model.id"
end end
def setup def setup
super super
@object = ParentModel.new( @object = ParentModel.new(
child_models: [ ChildModel.new(id: 2, name: "comments") ], child_models: [ ChildModel.new(id: 2, name: "to_many") ],
child_model: ChildModel.new(id: 1, name: "comment") child_model: ChildModel.new(id: 1, name: "to_one")
) )
@serializer_class = ParentModelSerializer @serializer_class = ParentModelSerializer
@serializer_instance = @serializer_class.new(@object) @serializer_instance = @serializer_class.new(@object)
@ -48,7 +46,7 @@ module AMS
data: [{ type: "comments", id: "2" }] data: [{ type: "comments", id: "2" }]
}, },
child_model: { child_model: {
data: { type: "comments", id: "1" } data: { type: "posts", id: "1" }
} }
} }
assert_equal expected_relations, @serializer_instance.relations assert_equal expected_relations, @serializer_instance.relations
@ -63,7 +61,7 @@ module AMS
def test_model_instance_relationship_to_one def test_model_instance_relationship_to_one
expected = { expected = {
data: { id: @object.child_model.id.to_s, type: "comments" } data: { id: @object.child_model.id.to_s, type: "posts" }
} }
assert_equal expected, @serializer_instance.child_model assert_equal expected, @serializer_instance.child_model
end end