alephant-broker 0.1.6 → 1.0.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.rb +40 -5
- data/lib/alephant/broker/component.rb +74 -0
- data/lib/alephant/broker/{call_environment.rb → environment.rb} +11 -7
- data/lib/alephant/broker/request.rb +13 -0
- data/lib/alephant/broker/request/asset.rb +37 -0
- data/lib/alephant/broker/request/batch.rb +38 -0
- data/lib/alephant/broker/request/factory.rb +24 -0
- data/lib/alephant/broker/request/handler.rb +35 -0
- data/lib/alephant/broker/response.rb +23 -0
- data/lib/alephant/broker/response/asset.rb +28 -0
- data/lib/alephant/broker/response/base.rb +60 -0
- data/lib/alephant/broker/response/batch.rb +45 -0
- data/lib/alephant/broker/response/factory.rb +27 -0
- data/lib/alephant/broker/version.rb +1 -1
- data/spec/rack_spec.rb +14 -15
- data/spec/spec_helper.rb +0 -1
- metadata +14 -27
- data/lib/alephant/broker/app.rb +0 -20
- data/lib/alephant/broker/app/rack.rb +0 -25
- data/lib/alephant/broker/models/request.rb +0 -41
- data/lib/alephant/broker/models/request/error_request.rb +0 -11
- data/lib/alephant/broker/models/request/get_request.rb +0 -38
- data/lib/alephant/broker/models/request/notfound_request.rb +0 -11
- data/lib/alephant/broker/models/request/post_request.rb +0 -50
- data/lib/alephant/broker/models/request/status_request.rb +0 -11
- data/lib/alephant/broker/models/request_factory.rb +0 -26
- data/lib/alephant/broker/models/request_handler.rb +0 -50
- data/lib/alephant/broker/models/response.rb +0 -27
- data/lib/alephant/broker/models/response/asset_response.rb +0 -90
- data/lib/alephant/broker/models/response/batch_response.rb +0 -61
- data/lib/alephant/broker/models/response_factory.rb +0 -39
- data/spec/asset_response_spec.rb +0 -78
- data/spec/batch_response_spec.rb +0 -87
- data/spec/get_request_spec.rb +0 -72
- data/spec/post_request_spec.rb +0 -49
- data/spec/response_factory_spec.rb +0 -60
data/spec/get_request_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Alephant::Broker::GetRequest do
|
4
|
-
subject { Alephant::Broker::GetRequest }
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
subject.any_instance.stub(:initialize)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#requested_components" do
|
11
|
-
it "returns hash of component parts" do
|
12
|
-
result = subject.new.requested_components('/foo/bar', 'baz=qux')
|
13
|
-
hash = {
|
14
|
-
:type => "foo",
|
15
|
-
:component_id => "bar",
|
16
|
-
:extension => :html,
|
17
|
-
:options => { :baz => "qux" }
|
18
|
-
}
|
19
|
-
|
20
|
-
expect(result).to eq(hash)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#parse" do
|
25
|
-
context "when component_id is nil" do
|
26
|
-
it "raise error" do
|
27
|
-
expect {
|
28
|
-
subject.new.parse :extension => :foobar
|
29
|
-
}.to raise_exception
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when component_id is not nil" do
|
34
|
-
it "sets values for attr_reader's" do
|
35
|
-
request = {
|
36
|
-
:component_id => 'foo',
|
37
|
-
:extension => 'bar',
|
38
|
-
:options => 'baz'
|
39
|
-
}
|
40
|
-
|
41
|
-
instance = subject.new
|
42
|
-
instance.parse(request)
|
43
|
-
|
44
|
-
expect(instance.component_id).to eq('foo')
|
45
|
-
expect(instance.extension).to eq('bar')
|
46
|
-
expect(instance.options).to eq('baz')
|
47
|
-
end
|
48
|
-
|
49
|
-
context "and extension is recognised" do
|
50
|
-
it "sets appropriate value for instance attribute" do
|
51
|
-
request = { :extension => 'json', :component_id => 'foo' }
|
52
|
-
|
53
|
-
instance = subject.new
|
54
|
-
instance.parse(request)
|
55
|
-
|
56
|
-
expect(instance.content_type).to eq('application/json')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "and extension is not recognised" do
|
61
|
-
it "sets default value for instance attribute" do
|
62
|
-
request = { :extension => 'foobar', :component_id => 'foo' }
|
63
|
-
|
64
|
-
instance = subject.new
|
65
|
-
instance.parse(request)
|
66
|
-
|
67
|
-
expect(instance.content_type).to eq('text/html')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/spec/post_request_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Alephant::Broker::PostRequest do
|
4
|
-
subject { Alephant::Broker::PostRequest }
|
5
|
-
|
6
|
-
describe "#components" do
|
7
|
-
it "returns hash of component parts + sub components" do
|
8
|
-
components = [{
|
9
|
-
"component" => "qux",
|
10
|
-
"options" => { "variant" => "cor" }
|
11
|
-
}]
|
12
|
-
|
13
|
-
env = (Struct.new(:path, :data)).new("/foo/bar", {
|
14
|
-
'batch_id' => :foobar,
|
15
|
-
'components' => components
|
16
|
-
})
|
17
|
-
|
18
|
-
hash = {
|
19
|
-
:batch_id => :foobar,
|
20
|
-
:type => "foo",
|
21
|
-
:component_id => "bar",
|
22
|
-
:components => components
|
23
|
-
}
|
24
|
-
|
25
|
-
RequestStore
|
26
|
-
.stub(:store)
|
27
|
-
.and_return({
|
28
|
-
:env => env
|
29
|
-
})
|
30
|
-
|
31
|
-
instance = subject.new
|
32
|
-
expect(instance.components).to eq(hash)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#set_component(id, options)" do
|
37
|
-
it "sets instance attribute values" do
|
38
|
-
subject
|
39
|
-
.any_instance
|
40
|
-
.stub(:initialize)
|
41
|
-
|
42
|
-
instance = subject.new
|
43
|
-
instance.set_component(:foo, :bar)
|
44
|
-
|
45
|
-
expect(instance.component_id).to eq(:foo)
|
46
|
-
expect(instance.options).to eq(:bar)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Alephant::Broker::ResponseFactory do
|
4
|
-
describe "#response_from(request)" do
|
5
|
-
let (:request) { double("Alephant::Broker::Request") }
|
6
|
-
let (:post_request) { double("Alephant::Broker::PostRequest").as_null_object }
|
7
|
-
|
8
|
-
it "should return asset response" do
|
9
|
-
instance = Alephant::Broker::ResponseFactory.new({})
|
10
|
-
allow(request).to receive(:type).and_return(:asset)
|
11
|
-
|
12
|
-
Alephant::Broker::AssetResponse
|
13
|
-
.any_instance
|
14
|
-
.stub(:initialize)
|
15
|
-
.with(request, {})
|
16
|
-
|
17
|
-
expect(instance.response_from(request))
|
18
|
-
.to be_a Alephant::Broker::AssetResponse
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return batched response" do
|
22
|
-
instance = Alephant::Broker::ResponseFactory.new({})
|
23
|
-
allow(post_request).to receive(:type).and_return(:batch)
|
24
|
-
allow(post_request).to receive(:content_type).and_return('application/json')
|
25
|
-
allow(post_request).to receive(:set_component)
|
26
|
-
allow(post_request).to receive(:components).and_return({
|
27
|
-
:batch_id => 'baz',
|
28
|
-
:components => [
|
29
|
-
{ 'component' => 'foo1', 'variant' => 'bar1' },
|
30
|
-
{ 'component' => 'foo2', 'variant' => 'bar2' }
|
31
|
-
]
|
32
|
-
})
|
33
|
-
|
34
|
-
Alephant::Broker::AssetResponse
|
35
|
-
.any_instance
|
36
|
-
.stub(:initialize)
|
37
|
-
|
38
|
-
expect(instance.response_from(post_request))
|
39
|
-
.to be_a Alephant::Broker::BatchResponse
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return status response" do
|
43
|
-
allow(request).to receive(:type).and_return(:status)
|
44
|
-
response = subject.response_from(request)
|
45
|
-
expect(response.status).to eq(200)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return 404 response" do
|
49
|
-
allow(request).to receive(:type).and_return(:notfound)
|
50
|
-
response = subject.response_from(request)
|
51
|
-
expect(response.status).to eq(404)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should return 500 response" do
|
55
|
-
allow(request).to receive(:type).and_return(:error)
|
56
|
-
response = subject.response_from(request)
|
57
|
-
expect(response.status).to eq(500)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|