-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from meanphil/fix-header-inheritance
Fix subclasses not inheriting headers set in the superclass
- Loading branch information
Showing
7 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "abstract_unit" | ||
|
||
require "fixtures/product" | ||
|
||
class InheritenceTest < ActiveSupport::TestCase | ||
def test_sub_class_retains_ancestor_headers | ||
ActiveResource::HttpMock.respond_to do |mock| | ||
mock.get "/sub_products/1.json", | ||
{ "Accept" => "application/json", "X-Inherited-Header" => "present" }, | ||
{ id: 1, name: "Sub Product" }.to_json, | ||
200 | ||
end | ||
|
||
sub_product = SubProduct.find(1) | ||
assert_equal "SubProduct", sub_product.class.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class InheritingHashTest < ActiveSupport::TestCase | ||
def setup | ||
@parent = ActiveResource::InheritingHash.new({ override_me: "foo", parent_key: "parent_value" }) | ||
@child = ActiveResource::InheritingHash.new(@parent) | ||
@child[:override_me] = "bar" | ||
@child[:child_only] = "baz" | ||
end | ||
|
||
def test_child_key_overrides_parent_key | ||
assert_equal "bar", @child[:override_me] | ||
end | ||
|
||
def test_parent_key_available_on_lookup | ||
assert_equal "parent_value", @child[:parent_key] | ||
end | ||
|
||
def test_conversion_to_regular_hash_includes_parent_keys | ||
hash = @child.to_hash | ||
|
||
assert_equal 3, hash.keys.length | ||
assert_equal "parent_value", hash[:parent_key] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters