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.
@@ -1,7 +1,7 @@
1
1
  class BarMapper < Alephant::Publisher::Request::DataMapper
2
2
  def data
3
3
  {
4
- :bar => "data mapped content"
4
+ bar: 'data mapped content'
5
5
  }
6
6
  end
7
7
  end
@@ -1,4 +1,4 @@
1
- require "alephant/renderer/views/html"
1
+ require 'alephant/renderer/views/html'
2
2
 
3
3
  module MyApp
4
4
  class Bar < ::Alephant::Renderer::Views::Html
@@ -1,11 +1,11 @@
1
- require "json"
1
+ require 'json'
2
2
 
3
3
  class BazMapper < Alephant::Publisher::Request::DataMapper
4
4
  def data
5
5
  (1..3).reduce({}) do |accum, _index|
6
6
  accum.merge(
7
7
  JSON.parse(
8
- get("/test/call").body
8
+ get('/test/call').body
9
9
  )
10
10
  )
11
11
  end
@@ -1,4 +1,4 @@
1
- require "alephant/renderer/views/html"
1
+ require 'alephant/renderer/views/html'
2
2
 
3
3
  module MyApp
4
4
  class Baz < ::Alephant::Renderer::Views::Html
@@ -1,9 +1,9 @@
1
- require "alephant/renderer/views/json"
1
+ require 'alephant/renderer/views/json'
2
2
 
3
3
  module MyApp
4
4
  class Foo < ::Alephant::Renderer::Views::Json
5
5
  def to_h
6
- { "content" => "as json" }
6
+ { 'content' => 'as json' }
7
7
  end
8
8
  end
9
9
  end
@@ -1,45 +1,45 @@
1
- require "spec_helper"
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 "preview endpoint (GET /preview/{id}/{template}/{region}/{fixture})" do
8
- describe "content" do
9
- expected_time = "123456789"
7
+ describe 'preview endpoint (GET /preview/{id}/{template}/{region}/{fixture})' do
8
+ describe 'content' do
9
+ expected_time = '123456789'
10
10
 
11
- context "with valid data" do
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) { "foo" }
17
+ let (:id) { 'foo' }
18
18
  let (:template) { id }
19
19
  let (:fixture) { id }
20
- let (:region) { "page_region" }
20
+ let (:region) { 'page_region' }
21
21
 
22
- it "should return correct response" do
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
- "Content-Type" => "application/json",
28
- "Access-Control-Allow-Origin" => "*",
29
- "X-Sequence" => expected_time,
30
- "Content-Length" => "31"
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 "should have correct response headers" do
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 "component endpoint (GET /component/{id}/{template}/{fixture})" do
41
- describe "content" do
42
- expected_time = "123456789"
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 "without a data mapper" do
52
- let (:id) { "foo" }
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 "should return correct response" do
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
- "Content-Type" => "application/json",
62
- "Access-Control-Allow-Origin" => "*",
63
- "X-Sequence" => expected_time,
64
- "Content-Length" => "21"
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 "should have correct response headers" do
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 "with a data mapper" do
73
- context "using a single fixture" do
74
- let (:id) { "bar" }
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 "should return data mapped content" do
79
- expect(response).to eq("data mapped content")
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
- "Content-Type" => "text/html",
84
- "Access-Control-Allow-Origin" => "*",
85
- "X-Sequence" => expected_time,
86
- "Content-Length" => "20"
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 "should have correct response headers" do
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 "using multiple fixtures" do
95
- let (:id) { "baz" }
94
+ context 'using multiple fixtures' do
95
+ let (:id) { 'baz' }
96
96
  let (:template) { id }
97
97
  let (:fixture) { id }
98
98
 
99
- it "should return multiple mapped content" do
100
- expect(response).to eq("multiple endpoint data mapped content")
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
- "Content-Type" => "text/html",
105
- "Access-Control-Allow-Origin" => "*",
106
- "X-Sequence" => expected_time,
107
- "Content-Length" => "38"
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 "should have correct response headers" do
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 "content" do
120
- expected_time = "123456789"
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, :symbolize_names => true) }
128
+ let (:response) { JSON.parse(last_response.body.chomp, symbolize_names: true) }
129
129
 
130
- context "without a data mapper" do
131
- let (:id) { "foo" }
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
- :components => [
136
+ components: [
137
137
  {
138
- :component => "foo",
139
- :options => {},
140
- :status => 200,
141
- :body => %({"content":"as json"}),
142
- :content_type => "application/json",
143
- :sequence_id => expected_time
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 "should return correct response" do
148
+ it 'should return correct response' do
149
149
  expect(response).to eq(expected)
150
150
  end
151
151
  end
152
152
 
153
- context "with a data mapper" do
154
- context "using a single fixture" do
155
- let (:id) { "bar" }
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
- :components => [
160
+ components: [
161
161
  {
162
- :component => "bar",
163
- :options => {},
164
- :status => 200,
165
- :body => "data mapped content\n",
166
- :content_type => "text/html",
167
- :sequence_id => expected_time
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 "should return correct response" do
172
+ it 'should return correct response' do
173
173
  expect(response).to eq(expected)
174
174
  end
175
175
  end
176
176
 
177
- context "using multiple fixtures" do
178
- let (:id) { "baz" }
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
- :components => [
183
+ components: [
184
184
  {
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
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 "should return correct response" do
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 "component batch endpoint (POST /components/batch" do
204
- describe "content" do
205
- expected_time = "123456789"
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 "/components/batch", {
211
- :components => [
210
+ post '/components/batch', {
211
+ components: [
212
212
  {
213
- :component => id,
214
- :options => {
215
- :fixture => id
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, :symbolize_names => true) }
222
+ let (:response) { JSON.parse(last_response.body.chomp, symbolize_names: true) }
223
223
 
224
- context "without a data mapper" do
225
- let(:id) { "foo" }
224
+ context 'without a data mapper' do
225
+ let(:id) { 'foo' }
226
226
 
227
227
  expected = {
228
- :components => [
228
+ components: [
229
229
  {
230
- :component => "foo",
231
- :options => {},
232
- :status => 200,
233
- :body => %({"content":"as json"}),
234
- :content_type => "application/json",
235
- :sequence_id => expected_time
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 "should return correct response" do
240
+ it 'should return correct response' do
241
241
  expect(response).to eq(expected)
242
242
  end
243
243
  end
244
244
 
245
- context "with a data mapper" do
246
- context "using a single fixture" do
247
- let (:id) { "bar" }
245
+ context 'with a data mapper' do
246
+ context 'using a single fixture' do
247
+ let (:id) { 'bar' }
248
248
 
249
249
  expected = {
250
- :components => [
250
+ components: [
251
251
  {
252
- :component => "bar",
253
- :options => {},
254
- :status => 200,
255
- :body => "data mapped content\n",
256
- :content_type => "text/html",
257
- :sequence_id => expected_time
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 "should return correct response" do
262
+ it 'should return correct response' do
263
263
  expect(response).to eq(expected)
264
264
  end
265
265
  end
266
266
 
267
- context "using multiple fixtures" do
268
- let (:id) { "baz" }
267
+ context 'using multiple fixtures' do
268
+ let (:id) { 'baz' }
269
269
 
270
270
  expected = {
271
- :components => [
271
+ components: [
272
272
  {
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
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 "should return correct response" do
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 "status endpoint (GET /status)" do
291
+ describe 'status endpoint (GET /status)' do
292
292
  before(:each) do
293
- get "/status"
293
+ get '/status'
294
294
  end
295
295
 
296
- context "status code" do
297
- it "should return ok status code" do
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