alephant-broker 3.3.2 → 3.4.0

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: 2751739d9f38c6926ca53bf4df8e7ac644cbf772
4
- data.tar.gz: cf624229dc9294a967fa4df07503d674ad905cfc
3
+ metadata.gz: 55407571edbd3971d9cb25088a13dfd7d3f12b29
4
+ data.tar.gz: 47983affb51ca481661ebc44cfc126fb52b61b5f
5
5
  SHA512:
6
- metadata.gz: a144aa3a3f61fdb65420951514011fce5926a0a4dabd3ecd13d0022251faf0bfded4fc9b4f6b48ef25ddb6b82bac7a5d5a45a63060156ea2f6dc3a3ab6aa5864
7
- data.tar.gz: 3b4428fc19c4d8b4d2ddfb2ea3c1a9cfd280cdcfd23f455ce0aa26f972ee53a8954dfff376d88bbc085f165af9ac1b1a71e91bbcd802f5d90bf9e9ee7f1f3a31
6
+ metadata.gz: 206a138ba862747567bfb62461eb5553b3634cb3339ce52f39d2de769b4a661bf370cbc8dc609792960397185cf244912a41898ec07dccb6f11fcb604222aec4
7
+ data.tar.gz: 8f248bff62598414cec9a7889dcde5ed2a732a2ff33c12a616bcd708127dc93c45aee26f4e6c8e56ebc3d63c8aab2c5ab19c7e400fb92e673903728dcaede428
data/.travis.yml CHANGED
@@ -8,3 +8,4 @@ notifications:
8
8
  on_failure: change
9
9
  on_success: never
10
10
  sudo: false
11
+ script: bundle exec rake all
@@ -1,9 +1,9 @@
1
- require 'crimp'
2
- require 'alephant/cache'
3
- require 'alephant/lookup'
4
- require 'alephant/broker/errors/invalid_cache_key'
5
- require 'alephant/sequencer'
6
- require 'alephant/broker/cache'
1
+ require "crimp"
2
+ require "alephant/cache"
3
+ require "alephant/lookup"
4
+ require "alephant/broker/errors/invalid_cache_key"
5
+ require "alephant/sequencer"
6
+ require "alephant/broker/cache"
7
7
 
8
8
  module Alephant
9
9
  module Broker
@@ -14,32 +14,42 @@ module Alephant
14
14
  @id = meta.id
15
15
  @batch_id = meta.batch_id
16
16
  @options = symbolize(meta.options || {})
17
- @content = data[:content].force_encoding 'UTF-8'
17
+ @content = data[:content].force_encoding "UTF-8"
18
18
  @opts_hash = meta.opts_hash
19
19
  @data = data
20
20
  @meta = meta
21
21
  end
22
22
 
23
23
  def content_type
24
- headers['Content-Type']
24
+ headers["Content-Type"]
25
25
  end
26
26
 
27
27
  def headers
28
28
  {
29
- 'Content-Type' => data[:content_type].to_s,
30
- }.merge(data[:headers] || {})
29
+ "Content-Type" => data[:content_type].to_s
30
+ }
31
+ .merge(data[:headers] || {})
32
+ .merge(stripped_headers)
31
33
  end
32
34
 
33
35
  def status
34
- 200
36
+ meta_data_headers.key?("Status") ? meta_data_headers["Status"] : 200
35
37
  end
36
38
 
37
39
  private
38
40
 
39
41
  attr_reader :meta, :data
40
42
 
43
+ def meta_data_headers
44
+ @meta_data_headers ||= data[:meta].fetch(:headers, {})
45
+ end
46
+
47
+ def stripped_headers
48
+ meta_data_headers.reject { |k, _| k == "Status" }
49
+ end
50
+
41
51
  def symbolize(hash)
42
- Hash[hash.map { |k,v| [k.to_sym, v] }]
52
+ Hash[hash.map { |k, v| [k.to_sym, v] }]
43
53
  end
44
54
  end
45
55
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "3.3.2"
3
+ VERSION = "3.4.0"
4
4
  end
5
5
  end
@@ -1 +1 @@
1
- {"batch_id":"baz","components":[{"component":"ni_council_results_table","options":{"foo" : "bar"},"status":200,"content_type":"foo/bar","body":"Test"},{"component":"ni_council_results_table","options":{},"status":200,"content_type":"foo/bar","body":"Test"}]}
1
+ {"batch_id":"baz","components":[{"component":"ni_council_results_table","options":{"foo":"bar"},"status":200,"content_type":"test/content","body":"Test"},{"component":"ni_council_results_table","options":{},"status":200,"content_type":"test/content","body":"Test"}]}
@@ -0,0 +1,179 @@
1
+ require "spec_helper"
2
+
3
+ describe Alephant::Broker::Application do
4
+ include Rack::Test::Methods
5
+ let(:options) do
6
+ {
7
+ :lookup_table_name => "test_table",
8
+ :bucket_id => "test_bucket",
9
+ :path => "bucket_path"
10
+ }
11
+ end
12
+
13
+ let(:app) do
14
+ described_class.new(
15
+ Alephant::Broker::LoadStrategy::S3::Sequenced.new,
16
+ options
17
+ )
18
+ end
19
+ let(:content) do
20
+ {
21
+ :content_type => "test/content",
22
+ :content => "Test",
23
+ :meta => {}
24
+ }
25
+ end
26
+ let(:sequencer_double) do
27
+ instance_double(
28
+ "Alephant::Sequencer::Sequencer",
29
+ :get_last_seen => "111"
30
+ )
31
+ end
32
+
33
+ let(:lookup_location_double) do
34
+ instance_double("Alephant::Lookup::Location", :location => "test/location")
35
+ end
36
+ let(:lookup_helper_double) do
37
+ instance_double(
38
+ "Alephant::Lookup::LookupHelper",
39
+ :read => lookup_location_double
40
+ )
41
+ end
42
+
43
+ let(:s3_cache_double) { instance_double("Alephant::Cache", :get => content) }
44
+
45
+ before do
46
+ allow_any_instance_of(Logger).to receive(:info)
47
+ allow_any_instance_of(Logger).to receive(:debug)
48
+ allow(Alephant::Lookup).to receive(:create) { lookup_helper_double }
49
+ allow(Alephant::Sequencer).to receive(:create) { sequencer_double }
50
+ end
51
+
52
+ describe "Status endpoint `/status`" do
53
+ before { get "/status" }
54
+ specify { expect(last_response.status).to eql 200 }
55
+ specify { expect(last_response.body).to eql "ok" }
56
+ end
57
+
58
+ describe "404 endpoint `/banana`" do
59
+ before { get "/banana" }
60
+ specify { expect(last_response.status).to eql 404 }
61
+ specify { expect(last_response.body).to eq "Not found" }
62
+ end
63
+
64
+ describe "Component endpoint '/component/...'" do
65
+ before do
66
+ allow(Alephant::Cache).to receive(:new) { s3_cache_double }
67
+ get "/component/test_component"
68
+ end
69
+
70
+ context "for a valid component ID" do
71
+ specify { expect(last_response.status).to eql 200 }
72
+ specify { expect(last_response.body).to eql "Test" }
73
+ end
74
+
75
+ context "for valid URL parameters in request" do
76
+ before { get "/component/test_component?variant=test_variant" }
77
+ specify { expect(last_response.status).to eq 200 }
78
+ specify { expect(last_response.body).to eq "Test" }
79
+ end
80
+ end
81
+
82
+ describe "Components endpoint '/components'" do
83
+ let(:fixture_path) { "#{File.dirname(__FILE__)}/../fixtures/json" }
84
+ let(:batch_json) do
85
+ IO.read("#{fixture_path}/batch.json").strip
86
+ end
87
+ let(:batch_compiled_json) do
88
+ IO.read("#{fixture_path}/batch_compiled.json").strip
89
+ end
90
+
91
+ before do
92
+ allow(Alephant::Cache).to receive(:new) { s3_cache_double }
93
+ end
94
+
95
+ context "when using valid batch asset data" do
96
+ let(:path) { "/components/batch" }
97
+ let(:content_type) { "application/json" }
98
+ before { post path, batch_json, "CONTENT_TYPE" => content_type }
99
+
100
+ specify { expect(last_response.status).to eql 200 }
101
+ specify { expect(last_response.body).to eq batch_compiled_json }
102
+ end
103
+ end
104
+
105
+ describe "S3 headers" do
106
+ let(:content) do
107
+ {
108
+ :content => "missing_content",
109
+ :meta => {
110
+ :headers => {}
111
+ }
112
+ }
113
+ end
114
+ let(:s3_cache_double) do
115
+ instance_double(
116
+ "Alephant::Cache",
117
+ :get => content
118
+ )
119
+ end
120
+
121
+ context "with 404 status code set" do
122
+ before do
123
+ content[:meta][:headers]["Status"] = 404
124
+ allow(Alephant::Cache).to receive(:new) { s3_cache_double }
125
+ get "/component/test_component"
126
+ end
127
+
128
+ specify { expect(last_response.status).to eq 404 }
129
+ end
130
+
131
+ context "with cache and additional headers set" do
132
+ before do
133
+ content[:meta][:headers] = {
134
+ "Cache-Control" => "max-age=60",
135
+ "X-Some-Header" => "foo",
136
+ "Status" => 200
137
+ }
138
+ allow(Alephant::Cache).to receive(:new) { s3_cache_double }
139
+ get "/component/test_component"
140
+ end
141
+
142
+ specify { expect(last_response.headers).to include("Cache-Control") }
143
+ specify { expect(last_response.headers).to include("X-Some-Header") }
144
+ specify { expect(last_response.headers).to_not include("Status") }
145
+ specify { expect(last_response.status).to eq 200 }
146
+ end
147
+ end
148
+
149
+ describe "Cached data" do
150
+ let(:cache_double) do
151
+ instance_double(
152
+ "Alephant::Broker::Cache::Client",
153
+ :set => {
154
+ :content_type => "test/html",
155
+ :content => "<p>Some data</p>",
156
+ :meta => {}
157
+ },
158
+ :get => "<p>Some data</p>"
159
+ )
160
+ end
161
+ let(:s3_cache_double) do
162
+ instance_double(
163
+ "Alephant::Cache",
164
+ :get => "test_content"
165
+ )
166
+ end
167
+
168
+ context "which is old" do
169
+ before do
170
+ allow(Alephant::Broker::Cache::Client).to receive(:new) { cache_double }
171
+ allow(Alephant::Cache).to receive(:new) { s3_cache_double }
172
+ end
173
+ it "should update the cache (call `.set`)" do
174
+ expect(cache_double).to receive(:set).once
175
+ end
176
+ after { get "/component/test_component" }
177
+ end
178
+ end
179
+ end
metadata CHANGED
@@ -1,276 +1,276 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-21 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: rspec
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
19
- name: rspec
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rspec-nc
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: rspec-nc
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: guard
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - '>='
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
- name: guard
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - '>='
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: guard-rspec
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: pry
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - '>='
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: pry
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: pry-remote
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - '>='
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: pry-remote
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
+ name: pry-nav
98
99
  requirement: !ruby/object:Gem::Requirement
99
100
  requirements:
100
101
  - - '>='
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
- name: pry-nav
104
- prerelease: false
105
104
  type: :development
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
+ name: rake-rspec
112
113
  requirement: !ruby/object:Gem::Requirement
113
114
  requirements:
114
115
  - - '>='
115
116
  - !ruby/object:Gem::Version
116
117
  version: 0.0.2
117
- name: rake-rspec
118
- prerelease: false
119
118
  type: :development
119
+ prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.0.2
125
125
  - !ruby/object:Gem::Dependency
126
+ name: bundler
126
127
  requirement: !ruby/object:Gem::Requirement
127
128
  requirements:
128
129
  - - ~>
129
130
  - !ruby/object:Gem::Version
130
131
  version: '1.5'
131
- name: bundler
132
- prerelease: false
133
132
  type: :development
133
+ prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.5'
139
139
  - !ruby/object:Gem::Dependency
140
+ name: rake
140
141
  requirement: !ruby/object:Gem::Requirement
141
142
  requirements:
142
143
  - - '>='
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
- name: rake
146
- prerelease: false
147
146
  type: :development
147
+ prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
+ name: rack-test
154
155
  requirement: !ruby/object:Gem::Requirement
155
156
  requirements:
156
157
  - - '>='
157
158
  - !ruby/object:Gem::Version
158
159
  version: '0'
159
- name: rack-test
160
- prerelease: false
161
160
  type: :development
161
+ prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
+ name: alephant-lookup
168
169
  requirement: !ruby/object:Gem::Requirement
169
170
  requirements:
170
171
  - - '>='
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
- name: alephant-lookup
174
- prerelease: false
175
174
  type: :runtime
175
+ prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '>='
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
+ name: alephant-cache
182
183
  requirement: !ruby/object:Gem::Requirement
183
184
  requirements:
184
185
  - - '>='
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
- name: alephant-cache
188
- prerelease: false
189
188
  type: :runtime
189
+ prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '>='
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
+ name: alephant-logger
196
197
  requirement: !ruby/object:Gem::Requirement
197
198
  requirements:
198
199
  - - ~>
199
200
  - !ruby/object:Gem::Version
200
201
  version: '1'
201
- name: alephant-logger
202
- prerelease: false
203
202
  type: :runtime
203
+ prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ~>
207
207
  - !ruby/object:Gem::Version
208
208
  version: '1'
209
209
  - !ruby/object:Gem::Dependency
210
+ name: alephant-sequencer
210
211
  requirement: !ruby/object:Gem::Requirement
211
212
  requirements:
212
213
  - - '>='
213
214
  - !ruby/object:Gem::Version
214
215
  version: '0'
215
- name: alephant-sequencer
216
- prerelease: false
217
216
  type: :runtime
217
+ prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - '>='
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  - !ruby/object:Gem::Dependency
224
+ name: dalli-elasticache
224
225
  requirement: !ruby/object:Gem::Requirement
225
226
  requirements:
226
227
  - - '>='
227
228
  - !ruby/object:Gem::Version
228
229
  version: '0'
229
- name: dalli-elasticache
230
- prerelease: false
231
230
  type: :runtime
231
+ prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - '>='
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
+ name: pmap
238
239
  requirement: !ruby/object:Gem::Requirement
239
240
  requirements:
240
241
  - - '>='
241
242
  - !ruby/object:Gem::Version
242
243
  version: '0'
243
- name: pmap
244
- prerelease: false
245
244
  type: :runtime
245
+ prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - '>='
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  - !ruby/object:Gem::Dependency
252
+ name: faraday
252
253
  requirement: !ruby/object:Gem::Requirement
253
254
  requirements:
254
255
  - - '>='
255
256
  - !ruby/object:Gem::Version
256
257
  version: '0'
257
- name: faraday
258
- prerelease: false
259
258
  type: :runtime
259
+ prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - '>='
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  - !ruby/object:Gem::Dependency
266
+ name: crimp
266
267
  requirement: !ruby/object:Gem::Requirement
267
268
  requirements:
268
269
  - - '>='
269
270
  - !ruby/object:Gem::Version
270
271
  version: '0'
271
- name: crimp
272
- prerelease: false
273
272
  type: :runtime
273
+ prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
276
  - - '>='
@@ -322,14 +322,14 @@ files:
322
322
  - spec/fixtures/json/batch.json
323
323
  - spec/fixtures/json/batch_compiled.json
324
324
  - spec/http_spec.rb
325
+ - spec/integration/rack_spec.rb
325
326
  - spec/integration/spec_helper.rb
326
- - spec/rack_spec.rb
327
327
  - spec/spec_helper.rb
328
328
  homepage: https://github.com/BBC-News/alephant-broker
329
329
  licenses:
330
330
  - MIT
331
331
  metadata: {}
332
- post_install_message:
332
+ post_install_message:
333
333
  rdoc_options: []
334
334
  require_paths:
335
335
  - lib
@@ -344,9 +344,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
344
  - !ruby/object:Gem::Version
345
345
  version: '0'
346
346
  requirements: []
347
- rubyforge_project:
348
- rubygems_version: 2.1.9
349
- signing_key:
347
+ rubyforge_project:
348
+ rubygems_version: 2.0.14
349
+ signing_key:
350
350
  specification_version: 4
351
351
  summary: Brokers requests for alephant components
352
352
  test_files:
@@ -355,6 +355,6 @@ test_files:
355
355
  - spec/fixtures/json/batch.json
356
356
  - spec/fixtures/json/batch_compiled.json
357
357
  - spec/http_spec.rb
358
+ - spec/integration/rack_spec.rb
358
359
  - spec/integration/spec_helper.rb
359
- - spec/rack_spec.rb
360
360
  - spec/spec_helper.rb
data/spec/rack_spec.rb DELETED
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Alephant::Broker::Application do
4
- include Rack::Test::Methods
5
-
6
- let(:app) do
7
- described_class.new(
8
- Alephant::Broker::LoadStrategy::S3::Sequenced.new,
9
- {
10
- :lookup_table_name => 'test_table',
11
- :bucket_id => 'test_bucket',
12
- :path => 'bucket_path'
13
- }
14
- )
15
- end
16
- let(:cache_hash) do
17
- {
18
- :content_type => 'test/content',
19
- :content => 'Test'
20
- }
21
- end
22
- let(:sequencer_double) do
23
- instance_double(
24
- 'Alephant::Sequencer::Sequencer',
25
- :get_last_seen => '111'
26
- )
27
- end
28
-
29
- before do
30
- allow_any_instance_of(Logger).to receive(:info)
31
- allow_any_instance_of(Logger).to receive(:debug)
32
-
33
- allow_any_instance_of(Alephant::Broker::Cache::Client)
34
- .to receive(:get).and_return(cache_hash)
35
-
36
- allow_any_instance_of(Alephant::Broker::Component)
37
- .to receive_messages(
38
- :content => cache_hash[:content],
39
- :content_type => 'foo/bar',
40
- :version => 1
41
- )
42
-
43
- allow_any_instance_of(Alephant::Broker::Response::Asset)
44
- .to receive(:status).and_return(200)
45
-
46
- allow(Alephant::Sequencer).to receive(:create) { sequencer_double }
47
- end
48
-
49
- describe 'Status endpoint `/status`' do
50
- before { get '/status' }
51
- specify { expect(last_response.status).to eql 200 }
52
- specify { expect(last_response.body).to eql 'ok' }
53
- end
54
-
55
- describe '404 endpoint `/banana`' do
56
- before { get '/banana' }
57
- specify { expect(last_response.status).to eql 404 }
58
- specify { expect(last_response.body).to eq 'Not found' }
59
- end
60
-
61
- describe 'Component endpoint `/component/...`' do
62
- let(:batch_json) do
63
- IO.read("#{File.dirname(__FILE__)}/fixtures/json/batch.json").strip
64
- end
65
- let(:batch_compiled_json) do
66
- IO.read("#{File.dirname(__FILE__)}/fixtures/json/batch_compiled.json").strip
67
- end
68
-
69
- context 'for a valid component ID' do
70
- before { get '/component/test_component' }
71
- specify { expect(last_response.status).to eql 200 }
72
- specify { expect(last_response.body).to eql 'Test' }
73
- end
74
-
75
- context 'for valid URL parameters in request' do
76
- before { get '/component/test_component?variant=test_variant' }
77
- specify { expect(last_response.status).to eq 200 }
78
- specify { expect(last_response.body).to eq 'Test' }
79
- end
80
-
81
- context 'when using valid batch asset data' do
82
- before { post '/components/batch', batch_json, 'CONTENT_TYPE' => 'application/json' }
83
- specify { expect(last_response.status).to eql 200 }
84
- specify { expect(JSON.parse last_response.body).to eq JSON.parse(batch_compiled_json) }
85
- end
86
- end
87
-
88
- describe 'Cached data' do
89
- let(:cache_double) do
90
- instance_double(
91
- 'Alephant::Broker::Cache::Client',
92
- :set => {
93
- :content_type => 'test/html',
94
- :content => '<p>Some data</p>'
95
- },
96
- :get => '<p>Some data</p>'
97
- )
98
- end
99
- let(:lookup_location_double) do
100
- instance_double('Alephant::Lookup::Location', location: 'test/location')
101
- end
102
- let(:lookup_helper_double) do
103
- instance_double('Alephant::Lookup::LookupHelper', read: lookup_location_double)
104
- end
105
- let(:s3_cache_double) do
106
- instance_double(
107
- 'Alephant::Cache',
108
- :get => 'test_content'
109
- )
110
- end
111
-
112
- context 'which is old' do
113
- before do
114
- allow(Alephant::Lookup).to receive(:create) { lookup_helper_double }
115
- allow(Alephant::Broker::Cache::Client).to receive(:new) { cache_double }
116
- allow(Alephant::Cache).to receive(:new) { s3_cache_double }
117
- end
118
- it 'should update the cache (call `.set`)' do
119
- expect(cache_double).to receive(:set).once
120
- end
121
- after { get '/component/test_component' }
122
- end
123
- end
124
- end