alephant-preview 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/preview/server.rb +36 -0
- data/lib/alephant/preview/version.rb +1 -1
- data/spec/fixture_loader_spec.rb +6 -2
- data/spec/integration/preview_spec.rb +74 -0
- 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: 6ca1569d4f9ca20e48a9d00ef981602422a237b9
|
4
|
+
data.tar.gz: 4056520bbdf02527bcdd07e5f9428b9e43b6b898
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a388bca06b68b45e6e92a75aaad037b806dd78c1119905a609e53898b7a89fc305e02b4f2d5a0cb6dd6e48b8e1e95c7083cb376bf0365cf5f2b07780fc53d11a
|
7
|
+
data.tar.gz: 84646ac9db16888430e8ea03b6d792c6ac3972b672dd13eaf84698160a05553eb4e1d46910ccf349483cf414f2ed8697dad3daa75bd0ce41e41332775d80961e
|
@@ -27,6 +27,10 @@ module Alephant
|
|
27
27
|
|
28
28
|
BASE_LOCATION = "#{(ENV['BASE_LOCATION'] || Dir.pwd)}/components"
|
29
29
|
|
30
|
+
before do
|
31
|
+
response["Access-Control-Allow-Origin"] = "*"
|
32
|
+
end
|
33
|
+
|
30
34
|
get '/preview/:id/:template/:region/?:fixture?' do
|
31
35
|
render_preview
|
32
36
|
end
|
@@ -41,6 +45,20 @@ module Alephant
|
|
41
45
|
render_component
|
42
46
|
end
|
43
47
|
|
48
|
+
post "/components/batch" do
|
49
|
+
batch_components = []
|
50
|
+
|
51
|
+
batched_components.each do |component|
|
52
|
+
options = component.fetch(:options, {}) || {}
|
53
|
+
params["template"] = component.fetch(:component)
|
54
|
+
params["id"] = find_id_from_template params["template"]
|
55
|
+
params["fixture"] = options.fetch(:fixture, "responsive") || "responsive"
|
56
|
+
batch_components << render_batch_component
|
57
|
+
end
|
58
|
+
|
59
|
+
{ :components => batch_components }.to_json
|
60
|
+
end
|
61
|
+
|
44
62
|
get '/status' do
|
45
63
|
'ok'
|
46
64
|
end
|
@@ -63,7 +81,25 @@ module Alephant
|
|
63
81
|
view_mapper.generate(fixture_data)[template].render
|
64
82
|
end
|
65
83
|
|
84
|
+
def render_batch_component
|
85
|
+
{
|
86
|
+
:component => template,
|
87
|
+
:options => {},
|
88
|
+
:status => 200,
|
89
|
+
:body => render_component
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
66
93
|
private
|
94
|
+
|
95
|
+
def request_body
|
96
|
+
JSON.parse(request.body.read, :symbolize_names => true) || {}
|
97
|
+
end
|
98
|
+
|
99
|
+
def batched_components
|
100
|
+
request_body.fetch(:components, [])
|
101
|
+
end
|
102
|
+
|
67
103
|
def model
|
68
104
|
require model_location
|
69
105
|
Alephant::Renderer::Views.get_registered_class(template).new(fixture_data)
|
data/spec/fixture_loader_spec.rb
CHANGED
@@ -38,10 +38,14 @@ describe Alephant::Preview::FixtureLoader do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
41
|
+
context "using incorrect amount of fixtures" do
|
42
42
|
it "should raise an exception" do
|
43
43
|
(0..2).each { |index| subject.get(uri).body }
|
44
|
-
expect
|
44
|
+
expect do
|
45
|
+
subject.get(uri).body
|
46
|
+
end.to raise_error(
|
47
|
+
RuntimeError, "There isn't a fixture matching the request call, please add one"
|
48
|
+
)
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -59,6 +59,80 @@ describe Alephant::Preview::Server do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
describe "component batch endpoint (POST /components/batch" do
|
63
|
+
|
64
|
+
describe "content" do
|
65
|
+
before(:each) do
|
66
|
+
post "/components/batch", {
|
67
|
+
:components => [
|
68
|
+
{
|
69
|
+
:component => id,
|
70
|
+
:options => {
|
71
|
+
:fixture => id
|
72
|
+
}
|
73
|
+
}
|
74
|
+
]
|
75
|
+
}.to_json
|
76
|
+
end
|
77
|
+
|
78
|
+
let (:response) { JSON.parse(last_response.body.chomp, :symbolize_names => true) }
|
79
|
+
|
80
|
+
context "without a data mapper" do
|
81
|
+
let(:id) { "foo" }
|
82
|
+
|
83
|
+
expected = {
|
84
|
+
:components => [
|
85
|
+
{
|
86
|
+
:component => "foo",
|
87
|
+
:options => {},
|
88
|
+
:status => 200,
|
89
|
+
:body => "content\n"
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
|
94
|
+
specify { expect(response).to eq(expected) }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with a data mapper" do
|
98
|
+
|
99
|
+
context "using a single fixture" do
|
100
|
+
let (:id) { "bar" }
|
101
|
+
|
102
|
+
expected = {
|
103
|
+
:components => [
|
104
|
+
{
|
105
|
+
:component => "bar",
|
106
|
+
:options => {},
|
107
|
+
:status => 200,
|
108
|
+
:body => "data mapped content\n"
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}
|
112
|
+
|
113
|
+
specify { expect(response).to eq(expected) }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "using multiple fixtures" do
|
117
|
+
let (:id) { "baz" }
|
118
|
+
|
119
|
+
expected = {
|
120
|
+
:components => [
|
121
|
+
{
|
122
|
+
:component => "baz",
|
123
|
+
:options => {},
|
124
|
+
:status => 200,
|
125
|
+
:body => "multiple endpoint data mapped content\n"
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
|
130
|
+
specify { expect(response).to eq(expected) }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
62
136
|
describe "status endpoint (GET /status)" do
|
63
137
|
before(:each) do
|
64
138
|
get "/status"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC News
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|