alephant-broker 3.12.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/alephant/broker/environment.rb +4 -0
- data/lib/alephant/broker/response/asset.rb +1 -1
- data/lib/alephant/broker/response/base.rb +7 -1
- data/lib/alephant/broker/response/batch.rb +4 -4
- data/lib/alephant/broker/version.rb +1 -1
- data/spec/integration/rack_spec.rb +88 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 322bf8631f67f58a89b60648ab6b0b961a9689f9
|
4
|
+
data.tar.gz: b6651329e8bd41d6a5ee5da9dc2d6daa9cb0aa91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90d3ef9cb6e911103e32fff97933f259748961b24d7795c3a0a496b2131a6c5b1a3ace6c7055dba98fc6baa633e9621a32839994a8c377853b764add970ab00
|
7
|
+
data.tar.gz: 854e7f0e904af1e61389b1849d4f15aa6a83c614ed4093f40a430650a8612b4725de40caa2dd320a206fa69908500fe12aba8338e433da0ab3afd88483da05c4
|
@@ -11,7 +11,7 @@ module Alephant
|
|
11
11
|
|
12
12
|
@status = self.class.component_not_modified(@component.headers, request_env) ? NOT_MODIFIED_STATUS_CODE : component.status
|
13
13
|
|
14
|
-
super
|
14
|
+
super(@status, component.content_type, request_env)
|
15
15
|
|
16
16
|
@headers.merge!(@component.headers)
|
17
17
|
end
|
@@ -21,7 +21,7 @@ module Alephant
|
|
21
21
|
500 => "Error retrieving content"
|
22
22
|
}
|
23
23
|
|
24
|
-
def initialize(status = 200, content_type = "text/html")
|
24
|
+
def initialize(status = 200, content_type = "text/html", request_env = nil)
|
25
25
|
@content = STATUS_CODE_MAPPING[status]
|
26
26
|
@headers = {
|
27
27
|
"Content-Type" => content_type,
|
@@ -34,6 +34,8 @@ module Alephant
|
|
34
34
|
add_no_cache_headers if should_add_no_cache_headers?(status)
|
35
35
|
add_etag_allow_header if headers.has_key?("ETag")
|
36
36
|
setup if status == 200
|
37
|
+
|
38
|
+
@content = "" if self.class.options?(request_env)
|
37
39
|
end
|
38
40
|
|
39
41
|
protected
|
@@ -61,6 +63,10 @@ module Alephant
|
|
61
63
|
})
|
62
64
|
end
|
63
65
|
|
66
|
+
def self.options?(request_env)
|
67
|
+
request_env && request_env.respond_to?(:options?) && request_env.options?
|
68
|
+
end
|
69
|
+
|
64
70
|
def self.component_not_modified(headers, request_env)
|
65
71
|
return false unless allow_not_modified_response_status
|
66
72
|
return false if request_env.post?
|
@@ -10,11 +10,11 @@ module Alephant
|
|
10
10
|
attr_reader :components, :batch_id
|
11
11
|
|
12
12
|
def initialize(components, batch_id, request_env)
|
13
|
-
@components
|
14
|
-
@batch_id
|
15
|
-
@status
|
13
|
+
@components = components
|
14
|
+
@batch_id = batch_id
|
15
|
+
@status = self.class.component_not_modified(batch_response_headers, request_env) ? NOT_MODIFIED_STATUS_CODE : 200
|
16
16
|
|
17
|
-
super(@status, "application/json")
|
17
|
+
super(@status, "application/json", request_env)
|
18
18
|
|
19
19
|
@headers.merge!(batch_response_headers)
|
20
20
|
end
|
@@ -4,7 +4,7 @@ require "alephant/broker"
|
|
4
4
|
describe Alephant::Broker::Application do
|
5
5
|
include Rack::Test::Methods
|
6
6
|
|
7
|
-
let(:
|
7
|
+
let(:config) do
|
8
8
|
{
|
9
9
|
:lookup_table_name => "test_table",
|
10
10
|
:bucket_id => "test_bucket",
|
@@ -15,7 +15,7 @@ describe Alephant::Broker::Application do
|
|
15
15
|
let(:app) do
|
16
16
|
described_class.new(
|
17
17
|
Alephant::Broker::LoadStrategy::S3::Sequenced.new,
|
18
|
-
|
18
|
+
config
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
@@ -73,7 +73,7 @@ describe Alephant::Broker::Application do
|
|
73
73
|
specify { expect(last_response.headers).to include("Expires") }
|
74
74
|
end
|
75
75
|
|
76
|
-
describe "Component endpoint '/component/...'" do
|
76
|
+
describe "Component endpoint '/component/...' GET" do
|
77
77
|
before do
|
78
78
|
allow(Alephant::Storage).to receive(:new) { s3_double }
|
79
79
|
get "/component/test_component"
|
@@ -96,6 +96,45 @@ describe Alephant::Broker::Application do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
describe "Component endpoint '/component/...' OPTIONS" do
|
100
|
+
before do
|
101
|
+
allow(Alephant::Storage).to receive(:new) { s3_double }
|
102
|
+
options "/component/test_component"
|
103
|
+
end
|
104
|
+
|
105
|
+
context "for a valid component ID" do
|
106
|
+
specify { expect(last_response.status).to eql 200 }
|
107
|
+
specify { expect(last_response.body).to eql "" }
|
108
|
+
specify { expect(last_response.headers).to_not include("Cache-Control") }
|
109
|
+
specify { expect(last_response.headers).to_not include("Pragma") }
|
110
|
+
specify { expect(last_response.headers).to_not include("Expires") }
|
111
|
+
specify { expect(last_response.headers["ETag"]).to eq("123") }
|
112
|
+
specify { expect(last_response.headers["Last-Modified"]).to eq("Mon, 11 Apr 2016 10:39:57 GMT") }
|
113
|
+
specify { expect(last_response.headers["Content-Type"]).to eq("test/content") }
|
114
|
+
specify { expect(last_response.headers["Content-Length"]).to eq("0") }
|
115
|
+
end
|
116
|
+
|
117
|
+
context "for valid URL parameters in request" do
|
118
|
+
before { options "/component/test_component?variant=test_variant" }
|
119
|
+
specify { expect(last_response.status).to eq 200 }
|
120
|
+
specify { expect(last_response.body).to eq "" }
|
121
|
+
specify { expect(last_response.headers["Content-Type"]).to eq("test/content") }
|
122
|
+
specify { expect(last_response.headers["Content-Length"]).to eq("0") }
|
123
|
+
end
|
124
|
+
|
125
|
+
context "for invalid URL parameters in request" do
|
126
|
+
before {
|
127
|
+
content[:meta]["status"] = 404
|
128
|
+
allow(Alephant::Storage).to receive(:new) { s3_double }
|
129
|
+
options "/component/invalid_component"
|
130
|
+
}
|
131
|
+
specify { expect(last_response.status).to eq 404 }
|
132
|
+
specify { expect(last_response.body).to eq "" }
|
133
|
+
specify { expect(last_response.headers["Content-Type"]).to eq("test/content") }
|
134
|
+
specify { expect(last_response.headers["Content-Length"]).to eq("0") }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
99
138
|
describe "Components endpoint '/components' POST" do
|
100
139
|
let(:fixture_path) { "#{File.dirname(__FILE__)}/../fixtures/json" }
|
101
140
|
let(:batch_json) do
|
@@ -197,6 +236,52 @@ describe Alephant::Broker::Application do
|
|
197
236
|
end
|
198
237
|
end
|
199
238
|
|
239
|
+
describe "Components endpoint '/components' OPTIONS" do
|
240
|
+
let(:fixture_path) { "#{File.dirname(__FILE__)}/../fixtures/json" }
|
241
|
+
let(:s3_double_batch) { instance_double("Alephant::Storage") }
|
242
|
+
|
243
|
+
before do
|
244
|
+
allow(s3_double_batch).to receive(:get).and_return(
|
245
|
+
content,
|
246
|
+
AWS::Core::Data.new(
|
247
|
+
:content_type => "test/content",
|
248
|
+
:content => "Test",
|
249
|
+
:meta => {
|
250
|
+
:head_ETag => "\"abc\"",
|
251
|
+
:"head_Last-Modified" => "Mon, 11 Apr 2016 09:39:57 GMT"
|
252
|
+
}
|
253
|
+
)
|
254
|
+
)
|
255
|
+
|
256
|
+
allow(Alephant::Storage).to receive(:new) { s3_double_batch }
|
257
|
+
end
|
258
|
+
|
259
|
+
context "when using valid batch asset data" do
|
260
|
+
let(:path) { "/components/batch?batch_id=baz&components[ni_council_results_table][component]=ni_council_results_table&components[ni_council_results_table][options][foo]=bar&components[ni_council_results_table_no_options][component]=ni_council_results_table" }
|
261
|
+
let(:content_type) { "application/json" }
|
262
|
+
|
263
|
+
before { options path, {}, "CONTENT_TYPE" => content_type }
|
264
|
+
|
265
|
+
specify { expect(last_response.status).to eql 200 }
|
266
|
+
specify { expect(last_response.body).to eq "" }
|
267
|
+
|
268
|
+
describe "response should have headers" do
|
269
|
+
it "should have content headers" do
|
270
|
+
expect(last_response.headers["Content-Type"]).to eq("application/json")
|
271
|
+
expect(last_response.headers["Content-Length"]).to eq("0")
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should have ETag cache header" do
|
275
|
+
expect(last_response.headers["ETag"]).to eq('"34774567db979628363e6e865127623f"')
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should have most recent Last-Modified header" do
|
279
|
+
expect(last_response.headers["Last-Modified"]).to eq("Mon, 11 Apr 2016 10:39:57 GMT")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
200
285
|
describe "S3 headers" do
|
201
286
|
let(:content) do
|
202
287
|
AWS::Core::Data.new(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC News
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|