Merge pull request #1651 from NullVoxPopuli/deserialization-error-with-no-attributes

Fix for Deserialization erroring when a relationship is null in the json api document.
This commit is contained in:
Benjamin Fleischer
2016-04-03 14:32:24 -05:00
3 changed files with 44 additions and 1 deletions

View File

@@ -9,10 +9,50 @@ module ActionController
parsed_hash = ActiveModelSerializers::Deserialization.jsonapi_parse(params)
render json: parsed_hash
end
def render_polymorphic_parsed_payload
parsed_hash = ActiveModelSerializers::Deserialization.jsonapi_parse(
params,
polymorphic: [:restriction_for, :restricted_to]
)
render json: parsed_hash
end
end
tests DeserializationTestController
def test_deserialization_of_relationship_only_object
hash = {
'data' => {
'type' => 'restraints',
'relationships' => {
'restriction_for' => {
'data' => {
'type' => 'discounts',
'id' => '67'
}
},
'restricted_to' => {
'data' => nil
}
}
},
'restraint' => {}
}
post :render_polymorphic_parsed_payload, params: hash
response = JSON.parse(@response.body)
expected = {
'restriction_for_id' => '67',
'restriction_for_type' => 'discounts',
'restricted_to_id' => nil,
'restricted_to_type' => nil
}
assert_equal(expected, response)
end
def test_deserialization
hash = {
'data' => {