Skip to content

Commit a34dfd9

Browse files
committed
Fix subclasses not inheriting headers set in the superclass
The implementation of InheritedHash worked fine when look up individual keys, but when it was merged into the request headers inside the Connection class, it didn't consider the @parent_hash.
1 parent 9dfc15e commit a34dfd9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/active_resource/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def default_header
211211

212212
# Builds headers for request to remote service.
213213
def build_request_headers(headers, http_method, uri)
214-
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers)
214+
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers.to_hash)
215215
end
216216

217217
def response_auth_header

lib/active_resource/inheriting_hash.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,24 @@ def initialize(parent_hash = {})
1111
def [](key)
1212
super || @parent_hash[key]
1313
end
14+
15+
# Merges the flattened parent hash (if it's an InheritingHash)
16+
# with ourself
17+
def to_hash
18+
@parent_hash.to_hash.merge(self)
19+
end
20+
21+
# So we can see the merged object in IRB or the Rails console
22+
def pretty_print(pp)
23+
pp.pp_hash to_hash
24+
end
25+
26+
def inspect
27+
to_hash.inspect
28+
end
29+
30+
def to_s
31+
inspect
32+
end
1433
end
1534
end

0 commit comments

Comments
 (0)