From dc96280141715fa531665faada63e88ce356dc92 Mon Sep 17 00:00:00 2001 From: Paul Springett Date: Mon, 9 Aug 2021 15:26:03 +0100 Subject: [PATCH] Fix missing Location header in 0.9.x (#1362) * Add failing test to demonstrate regression It looks like this test was originally added as part of the Location header work, but was subsequently removed. See: https://github.com/cerebris/jsonapi-resources/commit/933750c1aba43f6db2a0cc2a782be5caa902c359 * Fix location header to be set correctly, fixes #1361 Previously, a change had been make to use string keys instead of symbol keys, see https://github.com/cerebris/jsonapi-resources/commit/010f024758a41460ebe51f13b35e0b3136a95e79 The change did not update how the location header was set to also use string keys. This PR resolves the issue by also using a string key. --- lib/jsonapi/acts_as_resource_controller.rb | 2 +- test/controllers/controller_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jsonapi/acts_as_resource_controller.rb b/lib/jsonapi/acts_as_resource_controller.rb index a999d43d8..580b8e9a4 100644 --- a/lib/jsonapi/acts_as_resource_controller.rb +++ b/lib/jsonapi/acts_as_resource_controller.rb @@ -234,7 +234,7 @@ def render_results(operation_results) render_options[:body] = JSON.generate(content) end - render_options[:location] = content[:data]["links"][:self] if ( + render_options[:location] = content[:data]["links"]["self"] if ( response_doc.status == :created && content[:data].class != Array && content[:data]["links"] ) diff --git a/test/controllers/controller_test.rb b/test/controllers/controller_test.rb index c9355cfd9..c69b5eb8b 100644 --- a/test/controllers/controller_test.rb +++ b/test/controllers/controller_test.rb @@ -591,6 +591,7 @@ def test_create_simple assert_equal 'JR is Great', json_response['data']['attributes']['title'] assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body'] assert_equal "http://test.host/posts/#{json_response['data']['id']}", json_response['data']['links']['self'] + assert_equal json_response['data']['links']['self'], response.location end def test_create_simple_id_not_allowed