Skip to content

Commit 0bcabfb

Browse files
committed
Add tests to ensure subclasses inherit the headers from their superclass
1 parent 9592ac6 commit 0bcabfb

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

test/abstract_unit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def setup_response
141141
mock.get "/posts/1.json", {}, @post
142142
mock.get "/posts/1/comments.json", {}, @comments
143143
# products
144-
mock.get "/products/1.json", {}, @product
144+
mock.get "/products/1.json", {"Accept"=>"application/json", "X-Inherited-Header"=>"present"}, @product
145145
mock.get "/products/1/inventory.json", {}, @inventory
146146
# pets
147147
mock.get "/people/1/pets.json", {}, @pets

test/cases/inheritence_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "abstract_unit"
4+
5+
require "fixtures/product"
6+
7+
class InheritenceTest < ActiveSupport::TestCase
8+
def test_sub_class_retains_ancestor_headers
9+
ActiveResource::HttpMock.respond_to do |mock|
10+
mock.get "/sub_products/1.json",
11+
{ "Accept" => "application/json", "X-Inherited-Header" => "present" },
12+
{ id: 1, name: "Sub Product" }.to_json,
13+
200
14+
end
15+
16+
sub_product = SubProduct.find(1)
17+
assert_equal "SubProduct", sub_product.class.to_s
18+
end
19+
end

test/fixtures/product.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22

33
class Product < ActiveResource::Base
44
self.site = "http://37s.sunrise.i:3000"
5+
# X-Inherited-Header is for testing that any subclasses
6+
# include the headers of this class
7+
self.headers["X-Inherited-Header"] = 'present'
8+
end
9+
10+
class SubProduct < Product
511
end

0 commit comments

Comments
 (0)