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
|
# using id, type, attributes, relationships
|
||||||
def to_h
|
def to_h
|
||||||
{
|
{
|
||||||
id: id,
|
id: id.to_s,
|
||||||
type: type
|
type: type
|
||||||
}.merge({
|
}.merge({
|
||||||
attributes: attributes,
|
attributes: attributes,
|
||||||
@ -412,7 +412,7 @@ module AMS
|
|||||||
|
|
||||||
# resource linkage
|
# resource linkage
|
||||||
def relationship_data(id, type)
|
def relationship_data(id, type)
|
||||||
{ "id": id, "type": type }
|
{ id: id.to_s, type: type }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dumps obj to JSON
|
# Dumps obj to JSON
|
||||||
|
|||||||
@ -27,29 +27,29 @@ module AMS
|
|||||||
|
|
||||||
def test_model_instance_as_json
|
def test_model_instance_as_json
|
||||||
expected = {
|
expected = {
|
||||||
id: 1, type: :profiles,
|
id: "1", type: :profiles,
|
||||||
attributes: { name: "name", summary: "description" },
|
attributes: { name: "name", summary: "description" },
|
||||||
relationships:
|
relationships:
|
||||||
{ child_models: { data: [{ id: 2, type: "comments" }] } }
|
{ child_models: { data: [{ id: "2", type: "comments" }] } }
|
||||||
}
|
}
|
||||||
assert_equal expected, @serializer_instance.as_json
|
assert_equal expected, @serializer_instance.as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_model_instance_to_json
|
def test_model_instance_to_json
|
||||||
expected = {
|
expected = {
|
||||||
id: 1, type: :profiles,
|
id: "1", type: :profiles,
|
||||||
attributes: { name: "name", summary: "description" },
|
attributes: { name: "name", summary: "description" },
|
||||||
relationships:
|
relationships:
|
||||||
{ child_models: { data: [{ id: 2, type: "comments" }] } }
|
{ child_models: { data: [{ id: "2", type: "comments" }] } }
|
||||||
}.to_json
|
}.to_json
|
||||||
assert_equal expected, @serializer_instance.to_json
|
assert_equal expected, @serializer_instance.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_model_instance_dump
|
def test_model_instance_dump
|
||||||
expected = {
|
expected = {
|
||||||
id: 1, type: :profiles
|
id: "1", type: :profiles
|
||||||
}.to_json
|
}.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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,10 +25,10 @@ module AMS
|
|||||||
def test_model_instance_relations
|
def test_model_instance_relations
|
||||||
expected_relations = {
|
expected_relations = {
|
||||||
child_models: {
|
child_models: {
|
||||||
data: [{ type: "comments", id: 2 }]
|
data: [{ type: "comments", id: "2" }]
|
||||||
},
|
},
|
||||||
child_model: {
|
child_model: {
|
||||||
data: { type: "comments", id: 1 }
|
data: { type: "comments", id: "1" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_equal expected_relations, @serializer_instance.relations
|
assert_equal expected_relations, @serializer_instance.relations
|
||||||
@ -36,14 +36,14 @@ module AMS
|
|||||||
|
|
||||||
def test_model_instance_relationship_data
|
def test_model_instance_relationship_data
|
||||||
expected = {
|
expected = {
|
||||||
type: :bananas, id: 5
|
type: :bananas, id: "5"
|
||||||
}
|
}
|
||||||
assert_equal expected, @serializer_instance.relationship_data(5, :bananas)
|
assert_equal expected, @serializer_instance.relationship_data(5, :bananas)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_model_instance_relationship_to_one
|
def test_model_instance_relationship_to_one
|
||||||
expected = {
|
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
|
assert_equal expected, @serializer_instance.child_model
|
||||||
end
|
end
|
||||||
@ -55,7 +55,7 @@ module AMS
|
|||||||
|
|
||||||
def test_model_instance_relationship_to_many
|
def test_model_instance_relationship_to_many
|
||||||
expected = {
|
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
|
assert_equal expected, @serializer_instance.child_models
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user