sitehub 0.5.0.alpha4 → 0.5.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ede66ca937a51aa4de571db5f3080113198429c
4
- data.tar.gz: 91540d0d051530439cd2979ba054e5478cb215b6
3
+ metadata.gz: d7189b64635170892f88906d52c53a757bdffd12
4
+ data.tar.gz: c928e7fb8bcb65d9375b6ac448298de8f6d6449f
5
5
  SHA512:
6
- metadata.gz: 8d1c08d30bcf5f0c95b20a7a49433ee214c65afa6d917eb04c5ca869d29fe3bff2bd8afce684b77f9920de2ee2f7f633797ba49b202cf6809fc3a2c25d8b4596
7
- data.tar.gz: 9f2ce2edfb124e6b09b835986dd96a224bc7e403afbb20a808f19a0c5b0be83a5b044272b72680db17522b841ac3bbfbe03d982578d2666fd93db1b4f125a6e9
6
+ metadata.gz: 9c57e15219c0a8f28e450b294b143db8b6d9b7851cbca600618c174533020116eda0dbbfb989c7179f827b8c4e3f95fe7b47bc129b3a4a7be05f339b34148640
7
+ data.tar.gz: d87d4cab4c1d81cea2cd40d269a579e916d89e023d598e44fe2210500981a317237508b3bbca11ed467b28d8da337c80afa0ed4a84dec655ccb5aacdfb33c20a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sitehub (0.5.0.alpha4)
4
+ sitehub (0.5.0.alpha5)
5
5
  activesupport
6
6
  em-http-request
7
7
  em-synchrony
@@ -11,7 +11,7 @@ class SiteHub
11
11
  end
12
12
 
13
13
  def root
14
- components.first
14
+ Identifier.new(components.first)
15
15
  end
16
16
 
17
17
  def sub_id
@@ -33,5 +33,11 @@ class SiteHub
33
33
  def ==(other)
34
34
  other.respond_to?(:to_sym) && to_sym == other.to_sym
35
35
  end
36
+
37
+ def hash
38
+ components.hash
39
+ end
40
+
41
+ alias eql? ==
36
42
  end
37
43
  end
@@ -67,17 +67,18 @@ class SiteHub
67
67
  end
68
68
 
69
69
  def add_route(label:, rule: nil, percentage: nil, url: nil, &block)
70
- label = id.child_label(label)
70
+ child_label = id.child_label(label)
71
+
71
72
  route = if block
72
73
  raise InvalidDefinitionException, RULE_NOT_SPECIFIED_MSG unless percentage || rule
73
74
  warn(IGNORING_URL_MSG) if url
74
- new(rule: rule, id: label, &block).build
75
+ new(rule: rule, id: child_label, &block).build
75
76
  else
76
77
  raise InvalidDefinitionException, RULE_NOT_SPECIFIED_MSG unless url
77
- forward_proxy(url: url, label: label, rule: rule)
78
+ forward_proxy(url: url, label: child_label, rule: rule)
78
79
  end
79
80
 
80
- routes.add(label, route, percentage)
81
+ routes.add(Identifier.new(label), route, percentage)
81
82
  end
82
83
 
83
84
  def default_route
@@ -1,3 +1,3 @@
1
1
  class SiteHub
2
- VERSION = '0.5.0.alpha4'.freeze
2
+ VERSION = '0.5.0.alpha5'.freeze
3
3
  end
@@ -8,6 +8,18 @@ class SiteHub
8
8
  described_class.new(nil)
9
9
  end
10
10
 
11
+ describe '#hash' do
12
+ it 'returns the hash off the components' do
13
+ expect(subject.hash).to be(subject.components.hash)
14
+ end
15
+ end
16
+
17
+ describe '#eql?' do
18
+ it 'is an alias of the #== method' do
19
+ expect(subject.method(:eql?)).to eq(subject.method(:==))
20
+ end
21
+ end
22
+
11
23
  describe '#initialize' do
12
24
  context 'id supplied' do
13
25
  it 'it returns a concatenated id' do
@@ -7,8 +7,8 @@ shared_context :site_hub do
7
7
 
8
8
  before do
9
9
  WebMock.enable!
10
- stub_request(:get, experiment1_url).to_return(body: 'hello')
11
- stub_request(:get, experiment2_url).to_return(body: 'experiment1_body')
10
+ stub_request(:get, experiment1_url).to_return(body: 'experiment1_body')
11
+ stub_request(:get, experiment2_url).to_return(body: 'experiment2_body')
12
12
  end
13
13
 
14
14
  let(:builder) do
@@ -24,7 +24,8 @@ shared_context :site_hub do
24
24
  end
25
25
 
26
26
  split(label: :experiment2, percentage: 0) do
27
- split percentage: 100, label: 'variant1', url: experiment2_url
27
+ split percentage: 0, label: 'variant1', url: experiment2_url
28
+ split percentage: 100, label: 'variant2', url: experiment2_url
28
29
  end
29
30
  end
30
31
  end
@@ -52,7 +53,6 @@ describe 'proxying calls' do
52
53
  describe 'route affinity' do
53
54
  context 'requested route cookie not present' do
54
55
  it 'drops a cookie to keep you on the same path' do
55
- stub_request(:get, downstream_url).to_return(body: 'hello')
56
56
  get('/endpoint')
57
57
  expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment1|variant1')
58
58
  end
@@ -61,7 +61,7 @@ describe 'proxying calls' do
61
61
  context 'requested route cookie present' do
62
62
  it 'proxies to the preselected route' do
63
63
  get('/endpoint', {}, 'HTTP_COOKIE' => "#{SiteHub::RECORDED_ROUTES_COOKIE}=experiment2|variant1")
64
- expect(app.last_response.body).to eq(['experiment1_body'])
64
+ expect(app.last_response.body).to eq(['experiment2_body'])
65
65
 
66
66
  expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment2|variant1')
67
67
  end
@@ -78,13 +78,12 @@ describe 'proxying calls' do
78
78
  # create_middleware.tap do |clazz|
79
79
  # clazz.class_eval do
80
80
  # define_method :call do |env|
81
+ #
81
82
  # callback = env['async.callback'] || env['async.orig_callback']
82
83
  # env['async.orig_callback'] = env['async.callback'] = proc do |status, headers, body|
83
- # if body.is_a?(Rack::BodyProxy)
84
- # body = "#{name}, #{body.body.join}"
85
- # end
84
+ # body = body.body.join if body.is_a?(Rack::BodyProxy)
86
85
  #
87
- # callback.call(status, headers, body)
86
+ # callback.call(status, headers, "#{name}, #{body}")
88
87
  # end
89
88
  # @app.call(env)
90
89
  # end
@@ -153,13 +152,13 @@ describe 'proxying calls' do
153
152
  # use middleware2
154
153
  # route label: :with_middleware, url: downstream_url
155
154
  # end
156
- # # proxy '/2' => downstream_url
155
+ # proxy '/2' => downstream_url
157
156
  # end
158
157
  # end
159
158
  #
160
159
  # it 'adds it to that route only' do
161
160
  # get('/1')
162
- # expect(app.last_response.body.join).to eq('middleware1, middleware2, hello')
161
+ # expect(app.last_response.body.join).to eq('middleware1, middleware2, hello')
163
162
  # get('/2')
164
163
  # expect(app.last_response.body.join).to eq('middleware1, hello')
165
164
  # end
@@ -177,7 +176,7 @@ describe 'proxying calls' do
177
176
  # proxy '/1' do
178
177
  # split percentage: 100, label: :experiment1 do
179
178
  # use middleware1
180
- # split percentage: 100, label: :with_middleware do
179
+ # split percentage: 100, label: :with_middleware do
181
180
  # use middleware2
182
181
  # split percentage: 100, label: :with_nested_middleware, url: downstream_url
183
182
  # end
@@ -69,7 +69,7 @@ class SiteHub
69
69
  context 'mapped_route found' do
70
70
  it 'uses the forward proxy' do
71
71
  subject
72
- expect(forward_proxy_builder.routes[:current]).to receive(:call) do
72
+ expect(forward_proxy_builder.routes[Identifier.new(:current)]).to receive(:call) do
73
73
  [200, {}, []]
74
74
  end
75
75
  expect(get(mapped_path).status).to eq(200)
@@ -9,7 +9,7 @@ class SiteHub
9
9
  include_context :sitehub_json
10
10
 
11
11
  subject do
12
- described_class.from_hash(proxy_1, :expected).routes[route_1[:label]]
12
+ described_class.from_hash(proxy_1, :expected).routes[Identifier.new(route_1[:label])]
13
13
  end
14
14
 
15
15
  context 'splits' do
@@ -164,7 +164,7 @@ class SiteHub
164
164
  sitehub_cookie_name: :cookie_name,
165
165
  sitehub_cookie_path: nil)
166
166
 
167
- expect(subject.routes[:current]).to eq(expected_route)
167
+ expect(subject.routes[Identifier.new(:current)]).to eq(expected_route)
168
168
  end
169
169
 
170
170
  it 'accepts a rule' do
@@ -198,7 +198,7 @@ class SiteHub
198
198
  mapped_path: '/path',
199
199
  &block).build
200
200
 
201
- expect(subject.routes[:label1]).to eq(expected_endpoints)
201
+ expect(subject.routes[Identifier.new(:label1)]).to eq(expected_endpoints)
202
202
  subject.build
203
203
  end
204
204
 
@@ -250,9 +250,9 @@ class SiteHub
250
250
  context 'middleware not specified' do
251
251
  it 'leaves it the proxies alone' do
252
252
  subject.route url: :url, label: :current
253
- expect(subject.routes[:current]).to be_using_rack_stack(ForwardProxy)
253
+ expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(ForwardProxy)
254
254
  subject.build
255
- expect(subject.routes[:current]).to be_using_rack_stack(ForwardProxy)
255
+ expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(ForwardProxy)
256
256
  end
257
257
  end
258
258
 
@@ -264,7 +264,7 @@ class SiteHub
264
264
  it 'wraps the forward proxies in the middleware' do
265
265
  subject.route url: :url, label: :current
266
266
  subject.build
267
- expect(subject.routes[:current]).to be_using_rack_stack(middleware, ForwardProxy)
267
+ expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(middleware, ForwardProxy)
268
268
  end
269
269
 
270
270
  it 'wraps the default in the middleware' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitehub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.alpha4
4
+ version: 0.5.0.alpha5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ladtech