alephant-broker 3.4.0 → 3.4.1

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: 55407571edbd3971d9cb25088a13dfd7d3f12b29
4
- data.tar.gz: 47983affb51ca481661ebc44cfc126fb52b61b5f
3
+ metadata.gz: 66e7169ca6dccf162a18d99cd370e664743f7368
4
+ data.tar.gz: ed5178f9dc74b2f4b339ceffe9c2a1aff969c566
5
5
  SHA512:
6
- metadata.gz: 206a138ba862747567bfb62461eb5553b3634cb3339ce52f39d2de769b4a661bf370cbc8dc609792960397185cf244912a41898ec07dccb6f11fcb604222aec4
7
- data.tar.gz: 8f248bff62598414cec9a7889dcde5ed2a732a2ff33c12a616bcd708127dc93c45aee26f4e6c8e56ebc3d63c8aab2c5ab19c7e400fb92e673903728dcaede428
6
+ metadata.gz: d761eaba217f4f256ccd1544063d237624af19f4609d9880cfc09694d15c8767c80b423bc8974e6d235d9603c28e808f79d9f358a61b59bad4ca93e0674f324b
7
+ data.tar.gz: 12b02ddece7cdd609f018b99a080e735bc57993ec472409bc492f6a68418f0bbd95c8635e37154ec92b87c2d62d56f33c999fcce06045df17b0a32cb6ea7df49
@@ -10,6 +10,8 @@ module Alephant
10
10
  class Component
11
11
  attr_reader :id, :batch_id, :options, :content, :opts_hash
12
12
 
13
+ HEADER_PREFIX = "head_"
14
+
13
15
  def initialize(meta, data)
14
16
  @id = meta.id
15
17
  @batch_id = meta.batch_id
@@ -29,11 +31,11 @@ module Alephant
29
31
  "Content-Type" => data[:content_type].to_s
30
32
  }
31
33
  .merge(data[:headers] || {})
32
- .merge(stripped_headers)
34
+ .merge(meta_data_headers)
33
35
  end
34
36
 
35
37
  def status
36
- meta_data_headers.key?("Status") ? meta_data_headers["Status"] : 200
38
+ data[:meta].key?("status") ? data[:meta]["status"] : 200
37
39
  end
38
40
 
39
41
  private
@@ -41,11 +43,15 @@ module Alephant
41
43
  attr_reader :meta, :data
42
44
 
43
45
  def meta_data_headers
44
- @meta_data_headers ||= data[:meta].fetch(:headers, {})
46
+ @meta_data_headers ||= data[:meta].to_h.reduce({}) do |accum, (k, v)|
47
+ accum.tap do |a|
48
+ a[header_key(k)] = v.to_s if k.start_with?(HEADER_PREFIX)
49
+ end
50
+ end
45
51
  end
46
52
 
47
- def stripped_headers
48
- meta_data_headers.reject { |k, _| k == "Status" }
53
+ def header_key(key)
54
+ key.gsub(HEADER_PREFIX, "").split("-").map(&:capitalize).join("-")
49
55
  end
50
56
 
51
57
  def symbolize(hash)
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "3.4.0"
3
+ VERSION = "3.4.1"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require_relative "spec_helper"
2
2
 
3
3
  describe Alephant::Broker::Application do
4
4
  include Rack::Test::Methods
@@ -17,11 +17,11 @@ describe Alephant::Broker::Application do
17
17
  )
18
18
  end
19
19
  let(:content) do
20
- {
20
+ AWS::Core::Data.new(
21
21
  :content_type => "test/content",
22
22
  :content => "Test",
23
23
  :meta => {}
24
- }
24
+ )
25
25
  end
26
26
  let(:sequencer_double) do
27
27
  instance_double(
@@ -104,12 +104,10 @@ describe Alephant::Broker::Application do
104
104
 
105
105
  describe "S3 headers" do
106
106
  let(:content) do
107
- {
107
+ AWS::Core::Data.new(
108
108
  :content => "missing_content",
109
- :meta => {
110
- :headers => {}
111
- }
112
- }
109
+ :meta => {}
110
+ )
113
111
  end
114
112
  let(:s3_cache_double) do
115
113
  instance_double(
@@ -120,7 +118,7 @@ describe Alephant::Broker::Application do
120
118
 
121
119
  context "with 404 status code set" do
122
120
  before do
123
- content[:meta][:headers]["Status"] = 404
121
+ content[:meta]["status"] = 404
124
122
  allow(Alephant::Cache).to receive(:new) { s3_cache_double }
125
123
  get "/component/test_component"
126
124
  end
@@ -130,17 +128,39 @@ describe Alephant::Broker::Application do
130
128
 
131
129
  context "with cache and additional headers set" do
132
130
  before do
133
- content[:meta][:headers] = {
134
- "Cache-Control" => "max-age=60",
135
- "X-Some-Header" => "foo",
136
- "Status" => 200
131
+ content[:meta] = {
132
+ "head_cache-control" => "max-age=60",
133
+ "head_x-some-header" => "foo",
134
+ "head_header_without_dash" => "bar",
135
+ "status" => 200
137
136
  }
138
137
  allow(Alephant::Cache).to receive(:new) { s3_cache_double }
139
138
  get "/component/test_component"
140
139
  end
141
140
 
142
- specify { expect(last_response.headers).to include("Cache-Control") }
143
- specify { expect(last_response.headers).to include("X-Some-Header") }
141
+ specify do
142
+ expect(
143
+ last_response.headers
144
+ ).to include_case_sensitive("Cache-Control")
145
+ end
146
+ specify do
147
+ expect(
148
+ last_response.headers["Cache-Control"]
149
+ ).to eq(content[:meta]["head_cache-control"])
150
+ end
151
+
152
+ specify do
153
+ expect(
154
+ last_response.headers
155
+ ).to include_case_sensitive("X-Some-Header")
156
+ end
157
+
158
+ specify do
159
+ expect(
160
+ last_response.headers
161
+ ).to include_case_sensitive("Header_without_dash")
162
+ end
163
+
144
164
  specify { expect(last_response.headers).to_not include("Status") }
145
165
  specify { expect(last_response.status).to eq 200 }
146
166
  end
@@ -1 +1,8 @@
1
- require_relative '../spec_helper'
1
+ require_relative "../spec_helper"
2
+ require "rspec/expectations"
3
+
4
+ RSpec::Matchers.define :include_case_sensitive do |expected|
5
+ match do |actual|
6
+ actual.keys.one? { |k| expected == k }
7
+ end
8
+ end
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.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec