Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit custom headers #280

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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