Skip to content

Commit

Permalink
Fix missing Location header in 0.9.x (#1362)
Browse files Browse the repository at this point in the history
* 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: 933750c

* Fix location header to be set correctly, fixes #1361

Previously, a change had been make to use string keys instead of symbol keys, see
010f024

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.
  • Loading branch information
paulspringett authored Aug 9, 2021
1 parent 8cdc9dd commit dc96280
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsonapi/acts_as_resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)

Expand Down
1 change: 1 addition & 0 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc96280

Please sign in to comment.