sitehub 0.4.3 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +31 -0
  3. data/.gitignore +2 -1
  4. data/.reek +41 -0
  5. data/.simplecov +7 -0
  6. data/Gemfile.lock +61 -33
  7. data/README.md +4 -0
  8. data/Rakefile +1 -1
  9. data/circle.yml +1 -1
  10. data/lib/sitehub/builder.rb +19 -36
  11. data/lib/sitehub/collection/split_route_collection.rb +18 -13
  12. data/lib/sitehub/collection/split_route_collection/split.rb +6 -4
  13. data/lib/sitehub/constants.rb +2 -1
  14. data/lib/sitehub/constants/http_header_keys.rb +2 -0
  15. data/lib/sitehub/constants/rack_http_header_keys.rb +2 -0
  16. data/lib/sitehub/cookie.rb +4 -13
  17. data/lib/sitehub/cookie/attribute.rb +10 -9
  18. data/lib/sitehub/cookie/flag.rb +5 -8
  19. data/lib/sitehub/cookie_rewriting.rb +12 -5
  20. data/lib/sitehub/downstream_client.rb +37 -0
  21. data/lib/sitehub/equality.rb +28 -0
  22. data/lib/sitehub/forward_proxy.rb +19 -62
  23. data/lib/sitehub/forward_proxy_builder.rb +70 -49
  24. data/lib/sitehub/getter_setter_methods.rb +21 -0
  25. data/lib/sitehub/http_headers.rb +45 -48
  26. data/lib/sitehub/location_rewriter.rb +29 -0
  27. data/lib/sitehub/location_rewriters.rb +23 -0
  28. data/lib/sitehub/memoize.rb +25 -0
  29. data/lib/sitehub/middleware.rb +16 -6
  30. data/lib/sitehub/middleware/error_handling.rb +20 -0
  31. data/lib/sitehub/middleware/forward_proxies.rb +54 -0
  32. data/lib/sitehub/{logging.rb → middleware/logging.rb} +0 -0
  33. data/lib/sitehub/middleware/logging/access_logger.rb +36 -0
  34. data/lib/sitehub/middleware/logging/error_logger.rb +38 -0
  35. data/lib/sitehub/middleware/logging/log_entry.rb +16 -0
  36. data/lib/sitehub/middleware/logging/log_stash.rb +12 -0
  37. data/lib/sitehub/middleware/logging/log_wrapper.rb +24 -0
  38. data/lib/sitehub/middleware/logging/request_log.rb +74 -0
  39. data/lib/sitehub/middleware/reverse_proxy.rb +37 -0
  40. data/lib/sitehub/middleware/transaction_id.rb +18 -0
  41. data/lib/sitehub/nil_location_rewriter.rb +7 -0
  42. data/lib/sitehub/nil_proxy.rb +11 -0
  43. data/lib/sitehub/request.rb +101 -0
  44. data/lib/sitehub/request_mapping.rb +16 -18
  45. data/lib/sitehub/resolver.rb +1 -1
  46. data/lib/sitehub/response.rb +10 -0
  47. data/lib/sitehub/string_utils.rb +13 -0
  48. data/lib/sitehub/version.rb +1 -1
  49. data/sitehub.gemspec +4 -1
  50. data/spec/equality_spec.rb +32 -0
  51. data/spec/sitehub/builder_spec.rb +29 -22
  52. data/spec/sitehub/collection/route_collection_spec.rb +15 -14
  53. data/spec/sitehub/collection/split_route_collection/split_spec.rb +26 -0
  54. data/spec/sitehub/collection/split_route_collection_spec.rb +15 -3
  55. data/spec/sitehub/cookie/flag_spec.rb +1 -1
  56. data/spec/sitehub/cookie_rewriting_spec.rb +6 -10
  57. data/spec/sitehub/downstream_client_spec.rb +72 -0
  58. data/spec/sitehub/equality_spec.rb +32 -0
  59. data/spec/sitehub/forward_proxy_builder_spec.rb +92 -55
  60. data/spec/sitehub/forward_proxy_spec.rb +29 -97
  61. data/spec/sitehub/http_headers_spec.rb +32 -52
  62. data/spec/sitehub/integration_spec.rb +1 -1
  63. data/spec/sitehub/location_rewriter_spec.rb +46 -0
  64. data/spec/sitehub/{path_directives_spec.rb → location_rewriters_spec.rb} +8 -8
  65. data/spec/sitehub/memoize_spec.rb +56 -0
  66. data/spec/sitehub/middleware/error_handling_spec.rb +34 -0
  67. data/spec/sitehub/middleware/forward_proxies_spec.rb +105 -0
  68. data/spec/sitehub/middleware/logging/access_logger_spec.rb +51 -0
  69. data/spec/sitehub/middleware/logging/error_logger_spec.rb +84 -0
  70. data/spec/sitehub/middleware/logging/log_entry_spec.rb +33 -0
  71. data/spec/sitehub/middleware/logging/log_stash_spec.rb +21 -0
  72. data/spec/sitehub/middleware/logging/log_wrapper_spec.rb +31 -0
  73. data/spec/sitehub/middleware/logging/request_log_spec.rb +108 -0
  74. data/spec/sitehub/middleware/reverse_proxy_spec.rb +113 -0
  75. data/spec/sitehub/middleware/transaction_id_spec.rb +30 -0
  76. data/spec/sitehub/middleware_spec.rb +23 -13
  77. data/spec/sitehub/nil_location_rewriter_spec.rb +10 -0
  78. data/spec/sitehub/nil_proxy_spec.rb +14 -0
  79. data/spec/sitehub/request_mapping_spec.rb +21 -23
  80. data/spec/sitehub/request_spec.rb +228 -0
  81. data/spec/sitehub/resolver_spec.rb +2 -5
  82. data/spec/sitehub/response_spec.rb +30 -0
  83. data/spec/spec_helper.rb +12 -6
  84. data/spec/support/async/middleware.rb +1 -0
  85. data/spec/support/patch/rack/response.rb +7 -5
  86. data/spec/support/shared_contexts.rb +3 -0
  87. data/spec/support/shared_contexts/http_proxy_rules_context.rb +36 -0
  88. data/spec/support/shared_contexts/middleware_context.rb +6 -6
  89. data/spec/support/shared_contexts/module_spec_context.rb +7 -0
  90. data/spec/support/shared_contexts/rack_request_context.rb +18 -0
  91. data/spec/support/shared_contexts/rack_test_context.rb +0 -1
  92. data/spec/support/shared_examples.rb +3 -0
  93. data/spec/support/shared_examples/memoized_helpers.rb +7 -0
  94. data/spec/support/shared_examples/prohibited_http_header_filter.rb +16 -0
  95. data/spec/support/silent_warnings.rb +1 -1
  96. data/tasks/code_quality.rake +6 -0
  97. metadata +99 -29
  98. data/lib/sitehub/forward_proxies.rb +0 -49
  99. data/lib/sitehub/logging/access_logger.rb +0 -78
  100. data/lib/sitehub/logging/error_logger.rb +0 -36
  101. data/lib/sitehub/logging/log_entry.rb +0 -15
  102. data/lib/sitehub/logging/log_stash.rb +0 -10
  103. data/lib/sitehub/logging/log_wrapper.rb +0 -23
  104. data/lib/sitehub/path_directive.rb +0 -32
  105. data/lib/sitehub/path_directives.rb +0 -22
  106. data/lib/sitehub/reverse_proxy.rb +0 -57
  107. data/lib/sitehub/string_sanitiser.rb +0 -7
  108. data/lib/sitehub/transaction_id.rb +0 -16
  109. data/spec/sitehub/error_handling_spec.rb +0 -20
  110. data/spec/sitehub/forward_proxies_spec.rb +0 -103
  111. data/spec/sitehub/logging/access_logger_spec.rb +0 -128
  112. data/spec/sitehub/logging/error_logger_spec.rb +0 -78
  113. data/spec/sitehub/logging/log_entry_spec.rb +0 -31
  114. data/spec/sitehub/logging/log_stash_spec.rb +0 -19
  115. data/spec/sitehub/logging/log_wrapper_spec.rb +0 -29
  116. data/spec/sitehub/path_directive_spec.rb +0 -47
  117. data/spec/sitehub/reverse_proxy_spec.rb +0 -111
  118. data/spec/sitehub/transaction_id_spec.rb +0 -28
  119. data/spec/support/async/response_handler.rb +0 -16
  120. data/spec/support/shared_contexts/async_context.rb +0 -14
@@ -1,9 +1,18 @@
1
1
  require 'sitehub/collection/route_collection'
2
- require 'sitehub/forward_proxy'
3
2
 
4
3
  class SiteHub
5
4
  describe Collection::RouteCollection do
6
- let(:route_without_rule) { ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name) }
5
+ let(:collection_entry) do
6
+ Class.new do
7
+ include Rules, Resolver
8
+
9
+ def initialize(rule = nil)
10
+ @rule = rule
11
+ end
12
+ end
13
+ end
14
+
15
+ let(:route_without_rule) { collection_entry.new }
7
16
 
8
17
  it 'is a collection' do
9
18
  expect(subject).to be_a(Collection)
@@ -47,7 +56,7 @@ class SiteHub
47
56
  describe '#resolve' do
48
57
  context 'no rule on route' do
49
58
  it 'returns the route' do
50
- route_without_rule = ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name)
59
+ route_without_rule = collection_entry.new
51
60
  subject.add(:id, route_without_rule)
52
61
  expect(subject.resolve({})).to be(route_without_rule)
53
62
  end
@@ -57,9 +66,7 @@ class SiteHub
57
66
  request_env = {}
58
67
  rule = proc { |env| env[:env_passed_in] = true }
59
68
 
60
- proxy = ForwardProxy.new(url: :url,
61
- id: :id,
62
- sitehub_cookie_name: :cookie_name)
69
+ proxy = collection_entry.new
63
70
  proxy.rule(rule)
64
71
  subject.add(:id, proxy)
65
72
  subject.resolve(env: request_env)
@@ -68,10 +75,7 @@ class SiteHub
68
75
 
69
76
  context 'rule applies' do
70
77
  it 'returns the route' do
71
- route_with_rule = ForwardProxy.new(url: :url,
72
- id: :id,
73
- rule: proc { true },
74
- sitehub_cookie_name: :cookie_name)
78
+ route_with_rule = collection_entry.new(proc { true })
75
79
  subject.add(:id, route_with_rule)
76
80
  expect(subject.resolve({})).to be(route_with_rule)
77
81
  end
@@ -79,10 +83,7 @@ class SiteHub
79
83
 
80
84
  context 'rule does not apply' do
81
85
  it 'returns nil' do
82
- route_with_rule = ForwardProxy.new(url: :url,
83
- id: :id,
84
- sitehub_cookie_name: :cookie_name,
85
- rule: proc { false })
86
+ route_with_rule = collection_entry.new(proc { false })
86
87
  subject.add(:id, route_with_rule)
87
88
  expect(subject.resolve({})).to eq(nil)
88
89
  end
@@ -0,0 +1,26 @@
1
+ require 'sitehub/collection/split_route_collection/split.rb'
2
+
3
+ class SiteHub
4
+ class Collection
5
+ class SplitRouteCollection < Collection
6
+ describe Split do
7
+ describe '#update_value' do
8
+ subject do
9
+ described_class.new(:lower, :upper, :original)
10
+ end
11
+
12
+ it 'sets the value to be the out of the supplied block' do
13
+ subject.update_value { :new }
14
+ expect(subject.value).to eq(:new)
15
+ end
16
+
17
+ it 'passes the current value to the block' do
18
+ subject.update_value do |value|
19
+ expect(value).to eq(:original)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,10 +1,22 @@
1
1
  require 'sitehub/collection/split_route_collection'
2
- require 'sitehub/forward_proxy'
3
2
 
4
3
  class SiteHub
5
4
  describe Collection::SplitRouteCollection do
6
- let(:route_1) { ForwardProxy.new(url: :url, id: :id1, sitehub_cookie_name: :cookie_name) }
7
- let(:route_2) { ForwardProxy.new(url: :url, id: :id2, sitehub_cookie_name: :cookie_name) }
5
+ let(:collection_entry) do
6
+ Class.new do
7
+ include Rules, Resolver
8
+
9
+ attr_reader :id
10
+
11
+ def initialize(rule = nil, id:)
12
+ @id = id
13
+ @rule = rule
14
+ end
15
+ end
16
+ end
17
+
18
+ let(:route_1) { collection_entry.new(id: :id1) }
19
+ let(:route_2) { collection_entry.new(id: :id2) }
8
20
 
9
21
  it 'is a collection' do
10
22
  expect(subject).to be_a(Collection)
@@ -2,7 +2,7 @@ class SiteHub
2
2
  class Cookie
3
3
  describe Flag do
4
4
  let(:name) { 'flag' }
5
- let(:string_sanitiser) { Object.new.tap { |o| o.extend(StringSanitiser) } }
5
+ let(:string_sanitiser) { Object.new.tap { |object| object.extend(StringUtils) } }
6
6
  subject do
7
7
  described_class.new(name)
8
8
  end
@@ -2,6 +2,8 @@ require 'sitehub/cookie_rewriting'
2
2
 
3
3
  class SiteHub
4
4
  describe CookieRewriting do
5
+ include_context :module_spec
6
+
5
7
  let(:downstream_domain) { '.downstream_domain.com' }
6
8
 
7
9
  let(:request_mapping) do
@@ -15,12 +17,6 @@ class SiteHub
15
17
  let(:downstream_response) { Rack::Response.new }
16
18
  let(:downstream_domain_cookie_name) { 'downstream.cookie' }
17
19
 
18
- subject do
19
- Object.new.tap do |o|
20
- o.extend(described_class)
21
- end
22
- end
23
-
24
20
  before do
25
21
  downstream_response.set_cookie(downstream_domain_cookie_name, domain: downstream_domain, value: 'value')
26
22
  downstream_response.set_cookie('downstream.cookie2', domain: downstream_domain, value: 'value2', httponly: true)
@@ -31,11 +27,11 @@ class SiteHub
31
27
  cookie_header = downstream_response.headers['Set-Cookie']
32
28
 
33
29
  cookie_strings = cookie_header.lines
34
- cookie1 = SiteHub::Cookie.new(cookie_strings[0])
35
- cookie2 = SiteHub::Cookie.new(cookie_strings[1])
30
+ first_cookie = SiteHub::Cookie.new(cookie_strings[0])
31
+ second_cookie = SiteHub::Cookie.new(cookie_strings[1])
36
32
  expected = {
37
- cookie1.name => cookie1,
38
- cookie2.name => cookie2
33
+ first_cookie.name => first_cookie,
34
+ second_cookie.name => second_cookie
39
35
  }
40
36
  result = subject.cookies_string_as_hash(cookie_header)
41
37
  expect(result).to eq(expected)
@@ -0,0 +1,72 @@
1
+ require 'sitehub/downstream_client'
2
+
3
+ class SiteHub
4
+ describe DownstreamClient do
5
+ include_context :rack_request
6
+ include_context :http_proxy_rules
7
+
8
+ let(:current_version_url) { 'http://127.0.0.1:10111' }
9
+ let(:mapped_path) { '/path' }
10
+
11
+ let(:app) do
12
+ described_class.new
13
+ end
14
+
15
+ let(:body) { 'body' }
16
+ let(:http_headers) { {} }
17
+ let(:http_method) { :get }
18
+ let(:env) { env_for(path: mapped_path, env: http_headers, method: http_method) }
19
+
20
+ let(:request) do
21
+ SiteHub::Request.new(env: env).tap do |request|
22
+ request.map(mapped_path, current_version_url)
23
+ end
24
+ end
25
+
26
+ describe '#call' do
27
+ context 'downstream request' do
28
+ before do
29
+ stub_request(http_method, current_version_url).to_return(body: 'body')
30
+ end
31
+
32
+ context 'non get request' do
33
+ let(:http_method) { :put }
34
+ let(:env) do
35
+ env_for(path: mapped_path,
36
+ env: http_headers,
37
+ params_or_body: body,
38
+ method: http_method)
39
+ end
40
+
41
+ it 'preserves the body when forwarding request' do
42
+ stub_request(http_method, current_version_url)
43
+ subject.call(request)
44
+ assert_requested http_method, current_version_url, body: body
45
+ end
46
+ end
47
+
48
+ it 'preserves the headers when forwarding request' do
49
+ http_headers['HTTP_HEADER'] = 'value'
50
+ subject.call(request)
51
+ assert_requested http_method, current_version_url, headers: { 'Header' => 'value' }
52
+ end
53
+
54
+ it_behaves_like 'prohibited_header_filter' do
55
+ include_context :rack_request
56
+
57
+ subject do
58
+ headers = format_http_to_rack_headers(prohibited_headers.merge(permitted_header => 'value'))
59
+ headers.each do |key, value|
60
+ http_headers[key] = value
61
+ end
62
+
63
+ subject = described_class.new
64
+ subject.call(request)
65
+
66
+ WebMock::RequestRegistry.instance.requested_signatures.hash.keys.first.headers
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ class SiteHub
2
+ describe Equality do
3
+ subject(:test_class) do
4
+ Class.new do
5
+ include Equality
6
+
7
+ def initialize(first_attribute, second_attribute)
8
+ @first_attribute = first_attribute
9
+ @second_attribute = second_attribute
10
+ end
11
+ end
12
+ end
13
+ subject do
14
+ test_class.new(:foo, :bar)
15
+ end
16
+
17
+ describe '#==' do
18
+ context 'match' do
19
+ it 'returns true' do
20
+ match = test_class.new(:foo, :bar)
21
+ expect(subject).to eq(match)
22
+ end
23
+ end
24
+ context 'mismatch' do
25
+ it 'returns false' do
26
+ match = test_class.new(:wrong, :bar)
27
+ expect(subject).to_not eq(match)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -6,7 +6,7 @@ class SiteHub
6
6
  include_context :middleware_test
7
7
 
8
8
  subject do
9
- described_class.new(mapped_path: '/path')
9
+ described_class.new(mapped_path: '/path', sitehub_cookie_name: :cookie_name)
10
10
  end
11
11
 
12
12
  it 'supports middleware' do
@@ -70,42 +70,55 @@ class SiteHub
70
70
  end
71
71
 
72
72
  context 'split supplied' do
73
+ let(:block) do
74
+ proc do
75
+ default url: :url
76
+ end
77
+ end
78
+
79
+ context 'url' do
80
+ it 'gives a warning to say that the url will not be used' do
81
+ expect(subject).to receive(:warn).with(described_class::IGNORING_URL_LABEL_MSG)
82
+ subject.split(percentage: 50, url: :url, &block)
83
+ end
84
+ end
85
+
86
+ context 'label' do
87
+ it 'gives a warning to say that the url will not be used' do
88
+ expect(subject).to receive(:warn).with(described_class::IGNORING_URL_LABEL_MSG)
89
+ subject.split(percentage: 50, label: :label, &block)
90
+ end
91
+ end
92
+
73
93
  context 'block supplied' do
74
94
  it 'stores a forward proxy builder' do
75
- proc = proc do
76
- default url: :url
77
- end
78
-
79
- subject.split(percentage: 50, &proc)
95
+ subject.split(percentage: 50, &block)
80
96
 
81
- expected_builder = described_class.new(mapped_path: subject.mapped_path, &proc)
97
+ expected_builder = described_class.new(mapped_path: subject.mapped_path, &block).build
82
98
  expected_split = SiteHub::Collection::SplitRouteCollection::Split.new(0, 50, expected_builder)
83
99
  expect(subject.endpoints.values).to eq([expected_split])
84
100
  end
85
101
  end
102
+ end
86
103
 
87
- context 'block not supplied' do
88
- it 'stores a split for the version' do
89
- subject.split url: :url, label: :label, percentage: 50
104
+ context 'block not supplied' do
105
+ it 'stores a split for the version' do
106
+ subject.split url: :url, label: :label, percentage: 50
90
107
 
91
- expected_proxy = { ForwardProxy.new(url: :url, id: :label, sitehub_cookie_name: :cookie_name) => 50 }
92
- expected = Collection::SplitRouteCollection.new(expected_proxy)
108
+ expected_proxy = ForwardProxy.new(id: :label,
109
+ sitehub_cookie_name: :cookie_name,
110
+ mapped_url: :url,
111
+ mapped_path: subject.mapped_path)
93
112
 
94
- expect(subject.endpoints).to eq(expected)
95
- end
113
+ expected = Collection::SplitRouteCollection.new(expected_proxy => 50)
96
114
 
97
- context 'label not supplied' do
98
- it 'raises an error' do
99
- expect { subject.split(url: :url, percentage: 50) }
100
- .to raise_error(ForwardProxyBuilder::InvalidDefinitionException)
101
- end
102
- end
115
+ expect(subject.endpoints).to eq(expected)
116
+ end
103
117
 
104
- context 'url not supplied' do
105
- it 'raises an error' do
106
- expect { subject.split(label: :label, percentage: 50) }
107
- .to raise_error(ForwardProxyBuilder::InvalidDefinitionException)
108
- end
118
+ context 'url not supplied' do
119
+ it 'raises an error' do
120
+ expect { subject.split(label: :label, percentage: 50) }
121
+ .to raise_error(ForwardProxyBuilder::InvalidDefinitionException)
109
122
  end
110
123
  end
111
124
  end
@@ -120,30 +133,53 @@ class SiteHub
120
133
  end
121
134
  end
122
135
 
123
- describe 'route' do
136
+ describe '#route' do
124
137
  it 'accepts a rule' do
125
138
  subject.route url: :url, label: :current, rule: :rule
126
- expected_route = ForwardProxy.new(url: :url, id: :current, rule: :rule, sitehub_cookie_name: :cookie_name)
127
- expect(subject.endpoints).to eq(expected_route.id => expected_route)
139
+ expected_route = ForwardProxy.new(sitehub_cookie_name: :cookie_name,
140
+ id: :current,
141
+ rule: :rule,
142
+ mapped_url: :url,
143
+ mapped_path: subject.mapped_path)
144
+ expect(subject.endpoints).to eq(current: expected_route)
128
145
  end
129
146
 
130
147
  context 'block supplied' do
131
- context 'rule not supplied' do
132
- it 'raise an error' do
133
- expected_message = described_class::INVALID_ROUTE_DEF_MSG
134
- expect { subject.route {} }.to raise_exception described_class::InvalidDefinitionException, expected_message
148
+ let(:block) do
149
+ proc do
150
+ route url: :url, label: :label1
135
151
  end
136
152
  end
137
153
 
138
- it 'stores a proxy builder' do
139
- rule = proc { true }
140
- proc = proc do
141
- route url: :url, label: :label1
154
+ describe '#errors and warnings' do
155
+ context 'rule not supplied' do
156
+ it 'raise an error' do
157
+ expected_message = described_class::INVALID_ROUTE_DEF_MSG
158
+ expect { subject.route {} }
159
+ .to raise_exception described_class::InvalidDefinitionException, expected_message
160
+ end
142
161
  end
143
162
 
144
- subject.route(rule: rule, &proc)
163
+ context 'url' do
164
+ it 'gives a warning to say that the url will not be used' do
165
+ expect(subject).to receive(:warn).with(described_class::IGNORING_URL_LABEL_MSG)
166
+ subject.route(rule: :rule, url: :url, &block)
167
+ end
168
+ end
169
+
170
+ context 'label' do
171
+ it 'gives a warning to say that the url will not be used' do
172
+ expect(subject).to receive(:warn).with(described_class::IGNORING_URL_LABEL_MSG)
173
+ subject.route(rule: :rule, label: :label, &block)
174
+ end
175
+ end
176
+ end
177
+
178
+ it 'stores a proxy builder' do
179
+ rule = proc { true }
180
+ subject.route(rule: rule, &block)
145
181
 
146
- expected_builder = described_class.new(mapped_path: subject.mapped_path, &proc)
182
+ expected_builder = described_class.new(rule: rule, mapped_path: subject.mapped_path, &block).build
147
183
  expect(subject.endpoints.values).to eq([expected_builder])
148
184
  end
149
185
 
@@ -223,6 +259,7 @@ class SiteHub
223
259
  end
224
260
  end
225
261
  end
262
+
226
263
  describe '#resolve' do
227
264
  subject { described_class.new(mapped_path: '/') }
228
265
 
@@ -233,7 +270,7 @@ class SiteHub
233
270
  end
234
271
 
235
272
  it 'passes the env to the when resolving the correct route' do
236
- expect_any_instance_of(subject.routes.class).to receive(:resolve).with(env: :env).and_call_original
273
+ expect_any_instance_of(subject.endpoints.class).to receive(:resolve).with(env: :env).and_call_original
237
274
  subject.resolve(env: :env)
238
275
  end
239
276
  end
@@ -253,22 +290,6 @@ class SiteHub
253
290
  end
254
291
  end
255
292
 
256
- context 'endpoints' do
257
- context 'called with a collection' do
258
- it 'sets endpoints to be that collection' do
259
- subject.endpoints(:collection)
260
- expect(subject.endpoints).to eq(:collection)
261
- end
262
- end
263
-
264
- context 'already set with a different collection' do
265
- it 'raise an error' do
266
- subject.endpoints(:collection1)
267
- expect { subject.endpoints(:collection2) }.to raise_exception described_class::InvalidDefinitionException
268
- end
269
- end
270
- end
271
-
272
293
  context 'version selected' do
273
294
  context 'version applies to a route' do
274
295
  before do
@@ -298,6 +319,22 @@ class SiteHub
298
319
  end
299
320
  end
300
321
 
322
+ context '#endpoints' do
323
+ context 'called with a collection' do
324
+ it 'sets endpoints to be that collection' do
325
+ subject.endpoints(:collection)
326
+ expect(subject.endpoints).to eq(:collection)
327
+ end
328
+ end
329
+
330
+ context 'already set with a different collection' do
331
+ it 'raise an error' do
332
+ subject.endpoints(:collection1)
333
+ expect { subject.endpoints(:collection2) }.to raise_exception described_class::InvalidDefinitionException
334
+ end
335
+ end
336
+ end
337
+
301
338
  describe '#forward_proxy' do
302
339
  subject do
303
340
  described_class.new(mapped_path: '/path', sitehub_cookie_name: :expected_cookie_name)