alephant-preview 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Guardfile +4 -4
- data/Rakefile +5 -5
- data/bin/alephant-preview +9 -9
- data/lib/alephant/preview.rb +4 -4
- data/lib/alephant/preview/fixture_loader.rb +2 -2
- data/lib/alephant/preview/server.rb +62 -60
- data/lib/alephant/preview/tasks.rb +3 -3
- data/lib/alephant/preview/tasks/preview.rake +2 -2
- data/lib/alephant/preview/template.rb +3 -3
- data/lib/alephant/preview/template/base.rb +2 -2
- data/lib/alephant/preview/template/updater.rb +9 -9
- data/lib/alephant/preview/version.rb +1 -1
- data/spec/fixture_loader_spec.rb +16 -16
- data/spec/fixtures/components/bar/mapper.rb +1 -1
- data/spec/fixtures/components/bar/models/bar.rb +1 -1
- data/spec/fixtures/components/baz/mapper.rb +2 -2
- data/spec/fixtures/components/baz/models/baz.rb +1 -1
- data/spec/fixtures/components/foo/models/foo.rb +2 -2
- data/spec/integration/preview_spec.rb +121 -121
- data/spec/spec_helper.rb +8 -8
- metadata +42 -42
@@ -1,45 +1,45 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Preview::Server do
|
4
4
|
include Rack::Test::Methods
|
5
5
|
let (:app) { subject }
|
6
6
|
|
7
|
-
describe
|
8
|
-
describe
|
9
|
-
expected_time =
|
7
|
+
describe 'preview endpoint (GET /preview/{id}/{template}/{region}/{fixture})' do
|
8
|
+
describe 'content' do
|
9
|
+
expected_time = '123456789'
|
10
10
|
|
11
|
-
context
|
11
|
+
context 'with valid data' do
|
12
12
|
before(:each) do
|
13
13
|
allow(Time).to receive(:now).and_return(expected_time)
|
14
14
|
|
15
15
|
get "/preview/#{id}/#{template}/#{region}/#{fixture}"
|
16
16
|
end
|
17
|
-
let (:id) {
|
17
|
+
let (:id) { 'foo' }
|
18
18
|
let (:template) { id }
|
19
19
|
let (:fixture) { id }
|
20
|
-
let (:region) {
|
20
|
+
let (:region) { 'page_region' }
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should return correct response' do
|
23
23
|
expect(last_response.body).to eq(%(top{"content":"as json"}bottom\n))
|
24
24
|
end
|
25
25
|
|
26
26
|
expected_headers = {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
'Content-Type' => 'application/json',
|
28
|
+
'Access-Control-Allow-Origin' => '*',
|
29
|
+
'X-Sequence' => expected_time,
|
30
|
+
'Content-Length' => '31'
|
31
31
|
}
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'should have correct response headers' do
|
34
34
|
expect(last_response.headers).to include(expected_headers)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
41
|
-
describe
|
42
|
-
expected_time =
|
40
|
+
describe 'component endpoint (GET /component/{id}/{template}/{fixture})' do
|
41
|
+
describe 'content' do
|
42
|
+
expected_time = '123456789'
|
43
43
|
|
44
44
|
before(:each) do
|
45
45
|
allow(Time).to receive(:now).and_return(expected_time)
|
@@ -48,66 +48,66 @@ describe Alephant::Preview::Server do
|
|
48
48
|
end
|
49
49
|
let (:response) { last_response.body.chomp }
|
50
50
|
|
51
|
-
context
|
52
|
-
let (:id) {
|
51
|
+
context 'without a data mapper' do
|
52
|
+
let (:id) { 'foo' }
|
53
53
|
let (:template) { id }
|
54
54
|
let (:fixture) { id }
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'should return correct response' do
|
57
57
|
expect(response).to eq(%({"content":"as json"}))
|
58
58
|
end
|
59
59
|
|
60
60
|
expected_headers = {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
'Content-Type' => 'application/json',
|
62
|
+
'Access-Control-Allow-Origin' => '*',
|
63
|
+
'X-Sequence' => expected_time,
|
64
|
+
'Content-Length' => '21'
|
65
65
|
}
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'should have correct response headers' do
|
68
68
|
expect(last_response.headers).to include(expected_headers)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context
|
73
|
-
context
|
74
|
-
let (:id) {
|
72
|
+
context 'with a data mapper' do
|
73
|
+
context 'using a single fixture' do
|
74
|
+
let (:id) { 'bar' }
|
75
75
|
let (:template) { id }
|
76
76
|
let (:fixture) { id }
|
77
77
|
|
78
|
-
it
|
79
|
-
expect(response).to eq(
|
78
|
+
it 'should return data mapped content' do
|
79
|
+
expect(response).to eq('data mapped content')
|
80
80
|
end
|
81
81
|
|
82
82
|
expected_headers = {
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
'Content-Type' => 'text/html',
|
84
|
+
'Access-Control-Allow-Origin' => '*',
|
85
|
+
'X-Sequence' => expected_time,
|
86
|
+
'Content-Length' => '20'
|
87
87
|
}
|
88
88
|
|
89
|
-
it
|
89
|
+
it 'should have correct response headers' do
|
90
90
|
expect(last_response.headers).to include(expected_headers)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
context
|
95
|
-
let (:id) {
|
94
|
+
context 'using multiple fixtures' do
|
95
|
+
let (:id) { 'baz' }
|
96
96
|
let (:template) { id }
|
97
97
|
let (:fixture) { id }
|
98
98
|
|
99
|
-
it
|
100
|
-
expect(response).to eq(
|
99
|
+
it 'should return multiple mapped content' do
|
100
|
+
expect(response).to eq('multiple endpoint data mapped content')
|
101
101
|
end
|
102
102
|
|
103
103
|
expected_headers = {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
'Content-Type' => 'text/html',
|
105
|
+
'Access-Control-Allow-Origin' => '*',
|
106
|
+
'X-Sequence' => expected_time,
|
107
|
+
'Content-Length' => '38'
|
108
108
|
}
|
109
109
|
|
110
|
-
it
|
110
|
+
it 'should have correct response headers' do
|
111
111
|
expect(last_response.headers).to include(expected_headers)
|
112
112
|
end
|
113
113
|
end
|
@@ -116,8 +116,8 @@ describe Alephant::Preview::Server do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
describe 'component batch endpoint (GET /components/batch?components[#{id}]=#{id})' do
|
119
|
-
describe
|
120
|
-
expected_time =
|
119
|
+
describe 'content' do
|
120
|
+
expected_time = '123456789'
|
121
121
|
|
122
122
|
before(:each) do
|
123
123
|
allow(Time).to receive(:now).and_return(expected_time)
|
@@ -125,74 +125,74 @@ describe Alephant::Preview::Server do
|
|
125
125
|
get "/components/batch?components[#{id}][component]=#{id}&components[#{id}][options][fixture]=#{id}"
|
126
126
|
end
|
127
127
|
|
128
|
-
let (:response) { JSON.parse(last_response.body.chomp, :
|
128
|
+
let (:response) { JSON.parse(last_response.body.chomp, symbolize_names: true) }
|
129
129
|
|
130
|
-
context
|
131
|
-
let (:id) {
|
130
|
+
context 'without a data mapper' do
|
131
|
+
let (:id) { 'foo' }
|
132
132
|
let (:template) { id }
|
133
133
|
let (:fixture) { id }
|
134
134
|
|
135
135
|
expected = {
|
136
|
-
:
|
136
|
+
components: [
|
137
137
|
{
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
138
|
+
component: 'foo',
|
139
|
+
options: {},
|
140
|
+
status: 200,
|
141
|
+
body: %({"content":"as json"}),
|
142
|
+
content_type: 'application/json',
|
143
|
+
sequence_id: expected_time
|
144
144
|
}
|
145
145
|
]
|
146
146
|
}
|
147
147
|
|
148
|
-
it
|
148
|
+
it 'should return correct response' do
|
149
149
|
expect(response).to eq(expected)
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
context
|
154
|
-
context
|
155
|
-
let (:id) {
|
153
|
+
context 'with a data mapper' do
|
154
|
+
context 'using a single fixture' do
|
155
|
+
let (:id) { 'bar' }
|
156
156
|
let (:template) { id }
|
157
157
|
let (:fixture) { id }
|
158
158
|
|
159
159
|
expected = {
|
160
|
-
:
|
160
|
+
components: [
|
161
161
|
{
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
162
|
+
component: 'bar',
|
163
|
+
options: {},
|
164
|
+
status: 200,
|
165
|
+
body: "data mapped content\n",
|
166
|
+
content_type: 'text/html',
|
167
|
+
sequence_id: expected_time
|
168
168
|
}
|
169
169
|
]
|
170
170
|
}
|
171
171
|
|
172
|
-
it
|
172
|
+
it 'should return correct response' do
|
173
173
|
expect(response).to eq(expected)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
context
|
178
|
-
let (:id) {
|
177
|
+
context 'using multiple fixtures' do
|
178
|
+
let (:id) { 'baz' }
|
179
179
|
let (:template) { id }
|
180
180
|
let (:fixture) { id }
|
181
181
|
|
182
182
|
expected = {
|
183
|
-
:
|
183
|
+
components: [
|
184
184
|
{
|
185
|
-
:
|
186
|
-
:
|
187
|
-
:
|
188
|
-
:
|
189
|
-
:
|
190
|
-
:
|
185
|
+
component: 'baz',
|
186
|
+
options: {},
|
187
|
+
status: 200,
|
188
|
+
body: "multiple endpoint data mapped content\n",
|
189
|
+
content_type: 'text/html',
|
190
|
+
sequence_id: expected_time
|
191
191
|
}
|
192
192
|
]
|
193
193
|
}
|
194
194
|
|
195
|
-
it
|
195
|
+
it 'should return correct response' do
|
196
196
|
expect(response).to eq(expected)
|
197
197
|
end
|
198
198
|
end
|
@@ -200,87 +200,87 @@ describe Alephant::Preview::Server do
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
describe
|
204
|
-
describe
|
205
|
-
expected_time =
|
203
|
+
describe 'component batch endpoint (POST /components/batch' do
|
204
|
+
describe 'content' do
|
205
|
+
expected_time = '123456789'
|
206
206
|
|
207
207
|
before(:each) do
|
208
208
|
allow(Time).to receive(:now).and_return(expected_time)
|
209
209
|
|
210
|
-
post
|
211
|
-
:
|
210
|
+
post '/components/batch', {
|
211
|
+
components: [
|
212
212
|
{
|
213
|
-
:
|
214
|
-
:
|
215
|
-
:
|
213
|
+
component: id,
|
214
|
+
options: {
|
215
|
+
fixture: id
|
216
216
|
}
|
217
217
|
}
|
218
218
|
]
|
219
219
|
}.to_json
|
220
220
|
end
|
221
221
|
|
222
|
-
let (:response) { JSON.parse(last_response.body.chomp, :
|
222
|
+
let (:response) { JSON.parse(last_response.body.chomp, symbolize_names: true) }
|
223
223
|
|
224
|
-
context
|
225
|
-
let(:id) {
|
224
|
+
context 'without a data mapper' do
|
225
|
+
let(:id) { 'foo' }
|
226
226
|
|
227
227
|
expected = {
|
228
|
-
:
|
228
|
+
components: [
|
229
229
|
{
|
230
|
-
:
|
231
|
-
:
|
232
|
-
:
|
233
|
-
:
|
234
|
-
:
|
235
|
-
:
|
230
|
+
component: 'foo',
|
231
|
+
options: {},
|
232
|
+
status: 200,
|
233
|
+
body: %({"content":"as json"}),
|
234
|
+
content_type: 'application/json',
|
235
|
+
sequence_id: expected_time
|
236
236
|
}
|
237
237
|
]
|
238
238
|
}
|
239
239
|
|
240
|
-
it
|
240
|
+
it 'should return correct response' do
|
241
241
|
expect(response).to eq(expected)
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
-
context
|
246
|
-
context
|
247
|
-
let (:id) {
|
245
|
+
context 'with a data mapper' do
|
246
|
+
context 'using a single fixture' do
|
247
|
+
let (:id) { 'bar' }
|
248
248
|
|
249
249
|
expected = {
|
250
|
-
:
|
250
|
+
components: [
|
251
251
|
{
|
252
|
-
:
|
253
|
-
:
|
254
|
-
:
|
255
|
-
:
|
256
|
-
:
|
257
|
-
:
|
252
|
+
component: 'bar',
|
253
|
+
options: {},
|
254
|
+
status: 200,
|
255
|
+
body: "data mapped content\n",
|
256
|
+
content_type: 'text/html',
|
257
|
+
sequence_id: expected_time
|
258
258
|
}
|
259
259
|
]
|
260
260
|
}
|
261
261
|
|
262
|
-
it
|
262
|
+
it 'should return correct response' do
|
263
263
|
expect(response).to eq(expected)
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
|
-
context
|
268
|
-
let (:id) {
|
267
|
+
context 'using multiple fixtures' do
|
268
|
+
let (:id) { 'baz' }
|
269
269
|
|
270
270
|
expected = {
|
271
|
-
:
|
271
|
+
components: [
|
272
272
|
{
|
273
|
-
:
|
274
|
-
:
|
275
|
-
:
|
276
|
-
:
|
277
|
-
:
|
278
|
-
:
|
273
|
+
component: 'baz',
|
274
|
+
options: {},
|
275
|
+
status: 200,
|
276
|
+
body: "multiple endpoint data mapped content\n",
|
277
|
+
content_type: 'text/html',
|
278
|
+
sequence_id: expected_time
|
279
279
|
}
|
280
280
|
]
|
281
281
|
}
|
282
282
|
|
283
|
-
it
|
283
|
+
it 'should return correct response' do
|
284
284
|
expect(response).to eq(expected)
|
285
285
|
end
|
286
286
|
end
|
@@ -288,13 +288,13 @@ describe Alephant::Preview::Server do
|
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
|
-
describe
|
291
|
+
describe 'status endpoint (GET /status)' do
|
292
292
|
before(:each) do
|
293
|
-
get
|
293
|
+
get '/status'
|
294
294
|
end
|
295
295
|
|
296
|
-
context
|
297
|
-
it
|
296
|
+
context 'status code' do
|
297
|
+
it 'should return ok status code' do
|
298
298
|
expect(last_response.status).to eq(200)
|
299
299
|
end
|
300
300
|
end
|