Stringify ids

This commit is contained in:
Benjamin Fleischer 2017-07-11 15:51:28 -05:00
parent ffb94290e0
commit 94bf22ae2a
3 changed files with 13 additions and 13 deletions

View File

@ -324,7 +324,7 @@ module AMS
# using id, type, attributes, relationships
def to_h
{
id: id,
id: id.to_s,
type: type
}.merge({
attributes: attributes,
@ -412,7 +412,7 @@ module AMS
# resource linkage
def relationship_data(id, type)
{ "id": id, "type": type }
{ id: id.to_s, type: type }
end
# Dumps obj to JSON

View File

@ -27,29 +27,29 @@ module AMS
def test_model_instance_as_json
expected = {
id: 1, type: :profiles,
id: "1", type: :profiles,
attributes: { name: "name", summary: "description" },
relationships:
{ child_models: { data: [{ id: 2, type: "comments" }] } }
{ child_models: { data: [{ id: "2", type: "comments" }] } }
}
assert_equal expected, @serializer_instance.as_json
end
def test_model_instance_to_json
expected = {
id: 1, type: :profiles,
id: "1", type: :profiles,
attributes: { name: "name", summary: "description" },
relationships:
{ child_models: { data: [{ id: 2, type: "comments" }] } }
{ child_models: { data: [{ id: "2", type: "comments" }] } }
}.to_json
assert_equal expected, @serializer_instance.to_json
end
def test_model_instance_dump
expected = {
id: 1, type: :profiles
id: "1", type: :profiles
}.to_json
assert_equal expected, @serializer_instance.dump(id: 1, type: :profiles)
assert_equal expected, @serializer_instance.dump(id: "1", type: :profiles)
end
end
end

View File

@ -25,10 +25,10 @@ module AMS
def test_model_instance_relations
expected_relations = {
child_models: {
data: [{ type: "comments", id: 2 }]
data: [{ type: "comments", id: "2" }]
},
child_model: {
data: { type: "comments", id: 1 }
data: { type: "comments", id: "1" }
}
}
assert_equal expected_relations, @serializer_instance.relations
@ -36,14 +36,14 @@ module AMS
def test_model_instance_relationship_data
expected = {
type: :bananas, id: 5
type: :bananas, id: "5"
}
assert_equal expected, @serializer_instance.relationship_data(5, :bananas)
end
def test_model_instance_relationship_to_one
expected = {
data: { id: @object.child_model.id, type: "comments" }
data: { id: @object.child_model.id.to_s, type: "comments" }
}
assert_equal expected, @serializer_instance.child_model
end
@ -55,7 +55,7 @@ module AMS
def test_model_instance_relationship_to_many
expected = {
data: [{ id: @object.child_models.first.id, type: "comments" }]
data: [{ id: @object.child_models.first.id.to_s, type: "comments" }]
}
assert_equal expected, @serializer_instance.child_models
end