mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Stringify ids
This commit is contained in:
parent
ffb94290e0
commit
94bf22ae2a
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user