Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Inherit custom headers (JsonApiClient#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-mer authored and chingor13 committed Apr 13, 2018
1 parent e5325d1 commit 3f36f74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/json_api_client/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def with_headers(headers)
#
# @return [Hash] Headers
def custom_headers
_header_store.to_h
return _header_store.to_h if superclass == Object

superclass.custom_headers.merge(_header_store.to_h)
end

# Returns the requestor for this resource class
Expand Down
18 changes: 18 additions & 0 deletions test/unit/custom_header_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ def test_class_method_headers
end
end

def test_custom_headers_are_inherited
stub_request(:get, "http://example.com/custom_header_resources/1")
.with(headers: {"X-My-Header" => "asdf"})
.to_return(headers: {content_type: "application/vnd.api+json"}, body: {
data: {
type: "custom_header_resources",
id: "1",
attributes: {
title: "Rails is Omakase"
}
}
}.to_json)

JsonApiClient::Resource.with_headers(x_my_header: "asdf") do
CustomHeaderResource.find(1)
end
end

def test_multiple_threads
thread_count = 10

Expand Down

0 comments on commit 3f36f74

Please sign in to comment.