intranet-pictures 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/intranet/pictures/json_db_provider.rb +41 -71
- data/lib/intranet/pictures/responder.rb +100 -71
- data/lib/intranet/pictures/version.rb +1 -1
- data/lib/intranet/resources/haml/pictures_browse.haml +8 -7
- data/lib/intranet/resources/haml/pictures_home.haml +18 -16
- data/spec/intranet/pictures/json_db_provider_spec.rb +52 -147
- data/spec/intranet/pictures/responder_spec.rb +102 -137
- data/spec/intranet/pictures/sample-db.json +28 -38
- data/spec/spec_helper.rb +6 -8
- metadata +2 -2
@@ -52,7 +52,7 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
52
52
|
context 'when asked for \'/index.html\'' do
|
53
53
|
it 'should return a partial HTML content showing recent groups according to configuration' do
|
54
54
|
# Nominal case with limit
|
55
|
-
recents = [{
|
55
|
+
recents = [{ 'group_by' => 'location', 'sort_by' => 'datetime', 'sort_order' => 'desc', 'limit' => 2 }]
|
56
56
|
@responder.instance_variable_set(:@recents, recents)
|
57
57
|
code, mime, content = @responder.generate_page('/index.html', {})
|
58
58
|
expect(code).to eql(206)
|
@@ -65,12 +65,12 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
65
65
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
66
66
|
"<li>My Gallery</li>\n" \
|
67
67
|
"</ul>\n\n" \
|
68
|
-
"<h3>#{I18n.t('pictures.recents.
|
68
|
+
"<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
|
69
69
|
"<ul class='groups'>\n" \
|
70
|
-
"<li title='
|
71
|
-
"<li title='
|
70
|
+
"<li title='New York, USA'>\n<a onclick='openImagesGallery("location=New York, USA&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=New York, USA")'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
71
|
+
"<li title='Paris, France'>\n<a onclick='openImagesGallery("location=Paris, France&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
72
72
|
"</ul>\n" \
|
73
|
-
"<p class='see_more'>\n<a href='
|
73
|
+
"<p class='see_more'>\n<a href='browse.html?group_by=location&sort_by=datetime&sort_order=desc'>#{I18n.t('pictures.see_more')}</a>\n</p>\n" \
|
74
74
|
"</section>\n",
|
75
75
|
title: 'My Gallery',
|
76
76
|
stylesheets: [
|
@@ -83,7 +83,7 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
83
83
|
)
|
84
84
|
|
85
85
|
# Nominal case with limit
|
86
|
-
recents = [{
|
86
|
+
recents = [{ 'group_by' => 'location', 'sort_by' => 'datetime', 'limit' => 2 }]
|
87
87
|
@responder.instance_variable_set(:@recents, recents)
|
88
88
|
code, mime, content = @responder.generate_page('/index.html', {})
|
89
89
|
expect(code).to eql(206)
|
@@ -96,12 +96,12 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
96
96
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
97
97
|
"<li>My Gallery</li>\n" \
|
98
98
|
"</ul>\n\n" \
|
99
|
-
"<h3>#{I18n.t('pictures.recents.
|
99
|
+
"<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
|
100
100
|
"<ul class='groups'>\n" \
|
101
|
-
"<li title='
|
102
|
-
"<li title='
|
101
|
+
"<li title='Paris, France'>\n<a onclick='openImagesGallery("location=Paris, France&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
102
|
+
"<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery("location=Tokyo, Japan&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Tokyo, Japan")'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
103
103
|
"</ul>\n" \
|
104
|
-
"<p class='see_more'>\n<a href='
|
104
|
+
"<p class='see_more'>\n<a href='browse.html?group_by=location&sort_by=datetime'>#{I18n.t('pictures.see_more')}</a>\n</p>\n" \
|
105
105
|
"</section>\n",
|
106
106
|
title: 'My Gallery',
|
107
107
|
stylesheets: [
|
@@ -114,7 +114,7 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
114
114
|
)
|
115
115
|
|
116
116
|
# Nominal case without limit
|
117
|
-
recents = [{
|
117
|
+
recents = [{ 'group_by' => 'location', 'sort_by' => 'location', 'sort_order' => 'desc' }]
|
118
118
|
@responder.instance_variable_set(:@recents, recents)
|
119
119
|
code, mime, content = @responder.generate_page('/index.html', {})
|
120
120
|
expect(code).to eql(206)
|
@@ -127,11 +127,11 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
127
127
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
128
128
|
"<li>My Gallery</li>\n" \
|
129
129
|
"</ul>\n\n" \
|
130
|
-
"<h3>#{I18n.t('pictures.recents.
|
130
|
+
"<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
|
131
131
|
"<ul class='groups'>\n" \
|
132
|
-
"<li title='
|
133
|
-
"<li title='
|
134
|
-
"<li title='
|
132
|
+
"<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery("location=Tokyo, Japan&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Tokyo, Japan")'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
133
|
+
"<li title='Paris, France'>\n<a onclick='openImagesGallery("location=Paris, France&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
134
|
+
"<li title='New York, USA'>\n<a onclick='openImagesGallery("location=New York, USA&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=New York, USA")'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
135
135
|
"</ul>\n" \
|
136
136
|
"</section>\n",
|
137
137
|
title: 'My Gallery',
|
@@ -145,7 +145,7 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
145
145
|
)
|
146
146
|
|
147
147
|
# Incorrect recents specification
|
148
|
-
recents = [{
|
148
|
+
recents = [{ 'group_by' => 'invalid', 'sort_by' => 'location' }]
|
149
149
|
@responder.instance_variable_set(:@recents, recents)
|
150
150
|
code, mime, content = @responder.generate_page('/index.html', {})
|
151
151
|
expect(code).to eql(404)
|
@@ -155,7 +155,8 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
155
155
|
|
156
156
|
it 'should return a partial HTML content showing all groups according to configuration' do
|
157
157
|
# Nominal case without recents
|
158
|
-
home_groups = [{
|
158
|
+
home_groups = [{ 'group_by' => 'location', 'sort_by' => 'location',
|
159
|
+
'browse_group_by' => 'author' }]
|
159
160
|
@responder.instance_variable_set(:@home_groups, home_groups)
|
160
161
|
code, mime, content = @responder.generate_page('/index.html', {})
|
161
162
|
expect(code).to eql(206)
|
@@ -168,11 +169,11 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
168
169
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
169
170
|
"<li>My Gallery</li>\n" \
|
170
171
|
"</ul>\n\n" \
|
171
|
-
"<h3>#{I18n.t('pictures.browse_by.
|
172
|
+
"<h3>#{I18n.t('pictures.browse_by.location')}</h3>\n" \
|
172
173
|
"<ul class='groups wide'>\n" \
|
173
|
-
"<li title='
|
174
|
-
"<li title='
|
175
|
-
"<li title='
|
174
|
+
"<li title='New York, USA'>\n<a href='browse.html?group_by=author&location=New York, USA'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=New York, USA")'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
175
|
+
"<li title='Paris, France'>\n<a href='browse.html?group_by=author&location=Paris, France'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
176
|
+
"<li title='Tokyo, Japan'>\n<a href='browse.html?group_by=author&location=Tokyo, Japan'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Tokyo, Japan")'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
176
177
|
"</ul>\n" \
|
177
178
|
"</section>\n",
|
178
179
|
title: 'My Gallery',
|
@@ -186,9 +187,10 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
186
187
|
)
|
187
188
|
|
188
189
|
# Nominal case with recents
|
189
|
-
recents = [{
|
190
|
+
recents = [{ 'group_by' => 'location', 'sort_by' => 'location', 'sort_order' => 'asc' }]
|
190
191
|
@responder.instance_variable_set(:@recents, recents)
|
191
|
-
home_groups = [{
|
192
|
+
home_groups = [{ 'group_by' => 'author', 'sort_by' => 'author', 'sort_order' => 'asc',
|
193
|
+
'browse_group_by' => 'location', 'browse_sort_by' => 'location', 'browse_sort_order' => 'desc' }]
|
192
194
|
@responder.instance_variable_set(:@home_groups, home_groups)
|
193
195
|
code, mime, content = @responder.generate_page('/index.html', {})
|
194
196
|
expect(code).to eql(206)
|
@@ -201,16 +203,16 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
201
203
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
202
204
|
"<li>My Gallery</li>\n" \
|
203
205
|
"</ul>\n\n" \
|
204
|
-
"<h3>#{I18n.t('pictures.recents.
|
206
|
+
"<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
|
205
207
|
"<ul class='groups'>\n" \
|
206
|
-
"<li title='
|
207
|
-
"<li title='
|
208
|
-
"<li title='
|
208
|
+
"<li title='New York, USA'>\n<a onclick='openImagesGallery("location=New York, USA&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=New York, USA")'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
209
|
+
"<li title='Paris, France'>\n<a onclick='openImagesGallery("location=Paris, France&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
210
|
+
"<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery("location=Tokyo, Japan&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Tokyo, Japan")'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
209
211
|
"</ul>\n" \
|
210
|
-
"<h3>#{I18n.t('pictures.browse_by.
|
212
|
+
"<h3>#{I18n.t('pictures.browse_by.author')}</h3>\n" \
|
211
213
|
"<ul class='groups wide'>\n" \
|
212
|
-
"<li title='
|
213
|
-
"<li title='
|
214
|
+
"<li title='Jane Doe'>\n<a href='browse.html?group_by=location&sort_by=location&sort_order=desc&author=Jane Doe'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?author=Jane Doe")'></div>\n<figcaption>\nJane Doe\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
215
|
+
"<li title='John Doe'>\n<a href='browse.html?group_by=location&sort_by=location&sort_order=desc&author=John Doe'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?author=John Doe")'></div>\n<figcaption>\nJohn Doe\n<br>\n<em>Best photographer ever</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
214
216
|
"</ul>\n" \
|
215
217
|
"</section>\n",
|
216
218
|
title: 'My Gallery',
|
@@ -225,11 +227,11 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
225
227
|
end
|
226
228
|
end
|
227
229
|
|
228
|
-
context 'when asked for \'/
|
229
|
-
it 'should return a partial HTML content with selected
|
230
|
-
#
|
231
|
-
query = {}
|
232
|
-
code, mime, content = @responder.generate_page('/
|
230
|
+
context 'when asked for \'/browse.html\'' do
|
231
|
+
it 'should return a partial HTML content with selected pictures grouped as requested' do
|
232
|
+
# No selector nor sort order
|
233
|
+
query = { 'group_by' => 'author' }
|
234
|
+
code, mime, content = @responder.generate_page('/browse.html', query)
|
233
235
|
expect(code).to eql(206)
|
234
236
|
expect(mime).to eql('text/html')
|
235
237
|
expect(content).to eql(
|
@@ -239,11 +241,11 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
239
241
|
"<li>\n<a href='/index.html'>#{I18n.t('nav.home')}</a>\n</li>\n" \
|
240
242
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
241
243
|
"<li>\n<a href='index.html'>My Gallery</a>\n</li>\n" \
|
242
|
-
"<li>#{I18n.t('pictures.nav.
|
244
|
+
"<li>#{I18n.t('pictures.nav.author')}</li>\n" \
|
243
245
|
"</ul>\n\n" \
|
244
246
|
"<ul class='groups'>\n" \
|
245
|
-
"<li title='
|
246
|
-
"<li title='
|
247
|
+
"<li title='John Doe'>\n<a onclick='openImagesGallery("author=John Doe&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?author=John Doe")'></div>\n<figcaption>\nJohn Doe\n<br>\n<em>Best photographer ever</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
248
|
+
"<li title='Jane Doe'>\n<a onclick='openImagesGallery("author=Jane Doe&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?author=Jane Doe")'></div>\n<figcaption>\nJane Doe\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
247
249
|
"</ul>\n" \
|
248
250
|
"</section>\n",
|
249
251
|
title: 'My Gallery',
|
@@ -256,9 +258,9 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
256
258
|
}
|
257
259
|
)
|
258
260
|
|
259
|
-
#
|
260
|
-
query = { '
|
261
|
-
code, mime, content = @responder.generate_page('/
|
261
|
+
# Valid selector, valid sort order
|
262
|
+
query = { 'group_by' => 'location', 'author' => 'John Doe', 'sort_by' => 'location', 'sort_order' => 'desc' }
|
263
|
+
code, mime, content = @responder.generate_page('/browse.html', query)
|
262
264
|
expect(code).to eql(206)
|
263
265
|
expect(mime).to eql('text/html')
|
264
266
|
expect(content).to eql(
|
@@ -268,11 +270,11 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
268
270
|
"<li>\n<a href='/index.html'>#{I18n.t('nav.home')}</a>\n</li>\n" \
|
269
271
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
270
272
|
"<li>\n<a href='index.html'>My Gallery</a>\n</li>\n" \
|
271
|
-
"<li>#{I18n.t('pictures.nav.
|
273
|
+
"<li>#{I18n.t('pictures.nav.location')} (John Doe)</li>\n" \
|
272
274
|
"</ul>\n\n" \
|
273
275
|
"<ul class='groups'>\n" \
|
274
|
-
"<li title='
|
275
|
-
"<li title='
|
276
|
+
"<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery("author=John Doe&location=Tokyo, Japan&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Tokyo, Japan")'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
277
|
+
"<li title='Paris, France'>\n<a onclick='openImagesGallery("author=John Doe&location=Paris, France&sort_by=datetime");'>\n<figure>\n<div style='background-image: url("api/group_thumbnail?location=Paris, France")'></div>\n<figcaption>\nParis, France\n<br>\n<em>The City of Light</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
|
276
278
|
"</ul>\n" \
|
277
279
|
"</section>\n",
|
278
280
|
title: 'My Gallery',
|
@@ -286,8 +288,8 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
286
288
|
)
|
287
289
|
|
288
290
|
# Invalid selector
|
289
|
-
query = { 'foo' => 'bar' }
|
290
|
-
code, mime, content = @responder.generate_page('/
|
291
|
+
query = { 'group_by' => 'location', 'foo' => 'bar' }
|
292
|
+
code, mime, content = @responder.generate_page('/browse.html', query)
|
291
293
|
expect(code).to eql(206)
|
292
294
|
expect(mime).to eql('text/html')
|
293
295
|
expect(content).to eql(
|
@@ -297,7 +299,7 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
297
299
|
"<li>\n<a href='/index.html'>#{I18n.t('nav.home')}</a>\n</li>\n" \
|
298
300
|
"<li>#{I18n.t('pictures.menu')}</li>\n" \
|
299
301
|
"<li>\n<a href='index.html'>My Gallery</a>\n</li>\n" \
|
300
|
-
"<li>#{I18n.t('pictures.nav.
|
302
|
+
"<li>#{I18n.t('pictures.nav.location')} (bar)</li>\n" \
|
301
303
|
"</ul>\n\n" \
|
302
304
|
"<ul class='groups'>\n</ul>\n" \
|
303
305
|
"</section>\n",
|
@@ -311,15 +313,16 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
311
313
|
}
|
312
314
|
)
|
313
315
|
|
314
|
-
# Invalid
|
315
|
-
|
316
|
+
# Invalid grouping criteria
|
317
|
+
query = { 'group_by' => 'foo' }
|
318
|
+
code, mime, content = @responder.generate_page('/browse.html', query)
|
316
319
|
expect(code).to eql(404)
|
317
320
|
expect(mime).to be_empty
|
318
321
|
expect(content).to be_empty
|
319
322
|
|
320
|
-
# Invalid
|
321
|
-
query = { 'sort_order' => 'foo' }
|
322
|
-
code, mime, content = @responder.generate_page('/
|
323
|
+
# Invalid sorting criteria
|
324
|
+
query = { 'group_by' => 'location', 'sort_order' => 'foo' }
|
325
|
+
code, mime, content = @responder.generate_page('/browse.html', query)
|
323
326
|
expect(code).to eql(404)
|
324
327
|
expect(mime).to be_empty
|
325
328
|
expect(content).to be_empty
|
@@ -341,97 +344,59 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
341
344
|
end
|
342
345
|
end
|
343
346
|
|
344
|
-
context 'when asked for \'/api/
|
345
|
-
it 'should return
|
346
|
-
# Existing group
|
347
|
-
query = {}
|
348
|
-
code, mime, content = @responder.generate_page('/api/
|
349
|
-
expect(code).to eql(200)
|
350
|
-
expect(mime).to eql('application/json')
|
351
|
-
expect(content).to eql(
|
352
|
-
[
|
353
|
-
{ 'id' => 'group1_title1', 'title' => 'Group 1, Title 1', 'brief' => 'brief_text_1' },
|
354
|
-
{ 'id' => 'group1_title2', 'title' => 'Group 1, Title 2' }
|
355
|
-
].to_json
|
356
|
-
)
|
357
|
-
|
358
|
-
# Existing group, valid selector, no sort order
|
359
|
-
query = { 'group1' => 'group1_title1' }
|
360
|
-
code, mime, content = @responder.generate_page('/api/groups/group2', query)
|
347
|
+
context 'when asked for \'/api/group_thumbnail\'' do
|
348
|
+
it 'should return the selected group thumnail' do
|
349
|
+
# Existing group with thumbnail
|
350
|
+
query = { 'location' => 'New York, USA' }
|
351
|
+
code, mime, content = @responder.generate_page('/api/group_thumbnail', query)
|
361
352
|
expect(code).to eql(200)
|
362
|
-
expect(mime).to eql('
|
363
|
-
expect(content).to eql(
|
364
|
-
[
|
365
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' },
|
366
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' }
|
367
|
-
].to_json
|
368
|
-
)
|
353
|
+
expect(mime).to eql('image/png')
|
354
|
+
expect(content).to eql(File.read(File.join(__dir__, 'alpha.png')))
|
369
355
|
|
370
|
-
# Existing group
|
371
|
-
query = { '
|
372
|
-
code, mime, content = @responder.generate_page('/api/
|
373
|
-
expect(code).to eql(200)
|
374
|
-
expect(mime).to eql('application/json')
|
375
|
-
expect(content).to eql(
|
376
|
-
[
|
377
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' },
|
378
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' }
|
379
|
-
].to_json
|
380
|
-
)
|
381
|
-
query = { 'group1' => 'group1_title1', 'sort_by' => 'id', 'sort_order' => 'desc' }
|
382
|
-
code, mime, content = @responder.generate_page('/api/groups/group2', query)
|
356
|
+
# Existing group with no specified thumbnail
|
357
|
+
query = { 'location' => 'Paris, France' }
|
358
|
+
code, mime, content = @responder.generate_page('/api/group_thumbnail', query)
|
383
359
|
expect(code).to eql(200)
|
384
|
-
expect(mime).to eql('
|
360
|
+
expect(mime).to eql('image/svg+xml')
|
385
361
|
expect(content).to eql(
|
386
|
-
|
387
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' },
|
388
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' }
|
389
|
-
].to_json
|
362
|
+
File.read(File.join(__dir__, '../../../lib/intranet/resources/www/group_thumbnail.svg'))
|
390
363
|
)
|
391
364
|
|
392
|
-
#
|
393
|
-
query = { '
|
394
|
-
code, mime, content = @responder.generate_page('/api/
|
395
|
-
expect(code).to eql(200)
|
396
|
-
expect(mime).to eql('application/json')
|
397
|
-
expect(content).to eql([].to_json)
|
398
|
-
|
399
|
-
# Invalid group type
|
400
|
-
code, mime, content = @responder.generate_page('/api/groups/foo', {})
|
365
|
+
# Existing group with non-existant thumbnail
|
366
|
+
query = { 'author' => 'Jane Doe' }
|
367
|
+
code, mime, content = @responder.generate_page('/api/group_thumbnail', query)
|
401
368
|
expect(code).to eql(404)
|
402
369
|
expect(mime).to be_empty
|
403
370
|
expect(content).to be_empty
|
404
371
|
|
405
|
-
# Invalid
|
406
|
-
query = { '
|
407
|
-
code, mime, content = @responder.generate_page('/api/
|
372
|
+
# Invalid query
|
373
|
+
query = { 'location' => 'Tokyo, Japan', 'camera' => 'Canon EOS 5D MARK IV' }
|
374
|
+
code, mime, content = @responder.generate_page('/api/group_thumbnail', query)
|
408
375
|
expect(code).to eql(404)
|
409
376
|
expect(mime).to be_empty
|
410
377
|
expect(content).to be_empty
|
411
378
|
end
|
412
379
|
end
|
413
380
|
|
414
|
-
context 'when asked for \'/api/
|
415
|
-
it 'should return the selected group
|
416
|
-
# Existing group with
|
417
|
-
query = { '
|
418
|
-
code, mime, content = @responder.generate_page('/api/
|
381
|
+
context 'when asked for \'/api/group_brief\'' do
|
382
|
+
it 'should return the selected group brief text' do
|
383
|
+
# Existing group with brief text
|
384
|
+
query = { 'location' => 'Paris, France' }
|
385
|
+
code, mime, content = @responder.generate_page('/api/group_brief', query)
|
419
386
|
expect(code).to eql(200)
|
420
|
-
expect(mime).to eql('
|
421
|
-
expect(content).to eql(
|
387
|
+
expect(mime).to eql('application/json')
|
388
|
+
expect(content).to eql('The City of Light'.to_json)
|
422
389
|
|
423
|
-
# Existing group with no
|
424
|
-
query = { '
|
425
|
-
code, mime, content = @responder.generate_page('/api/
|
390
|
+
# Existing group with no brief text
|
391
|
+
query = { 'location' => 'Tokyo, Japan' }
|
392
|
+
code, mime, content = @responder.generate_page('/api/group_brief', query)
|
426
393
|
expect(code).to eql(200)
|
427
|
-
expect(mime).to eql('
|
428
|
-
expect(content).to eql(
|
429
|
-
File.read(File.join(__dir__, '../../../lib/intranet/resources/www/group_thumbnail.svg'))
|
430
|
-
)
|
394
|
+
expect(mime).to eql('application/json')
|
395
|
+
expect(content).to eql(''.to_json)
|
431
396
|
|
432
|
-
#
|
433
|
-
query = { '
|
434
|
-
code, mime, content = @responder.generate_page('/api/
|
397
|
+
# Invalid query
|
398
|
+
query = { 'location' => 'Tokyo, Japan', 'camera' => 'Canon EOS 5D MARK IV' }
|
399
|
+
code, mime, content = @responder.generate_page('/api/group_brief', query)
|
435
400
|
expect(code).to eql(404)
|
436
401
|
expect(mime).to be_empty
|
437
402
|
expect(content).to be_empty
|
@@ -446,46 +411,46 @@ RSpec.describe Intranet::Pictures::Responder do
|
|
446
411
|
expect(mime).to eql('application/json')
|
447
412
|
expect(content).to eql(
|
448
413
|
[
|
449
|
-
{ 'datetime' => '2019:07:22 09:41:31', '
|
450
|
-
{ 'datetime' => '2020:06:19 07:51:05', '
|
451
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
452
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
453
|
-
{ 'datetime' => '2019:07:22 09:45:17', '
|
414
|
+
{ 'datetime' => '2019:07:22 09:41:31', 'author' => 'John Doe', 'location' => 'Paris, France', 'camera' => 'Apple iPhone 11' },
|
415
|
+
{ 'datetime' => '2020:06:19 07:51:05', 'flash' => false, 'author' => 'Jane Doe', 'location' => 'Tokyo, Japan' },
|
416
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
417
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
418
|
+
{ 'datetime' => '2019:07:22 09:45:17', 'author' => 'John Doe', 'location' => 'Tokyo, Japan' }
|
454
419
|
].to_json
|
455
420
|
)
|
456
421
|
|
457
422
|
# Valid selector, no sort order
|
458
|
-
query = { '
|
423
|
+
query = { 'author' => 'Jane Doe', 'flash' => true }
|
459
424
|
code, mime, content = @responder.generate_page('/api/pictures', query)
|
460
425
|
expect(code).to eql(200)
|
461
426
|
expect(mime).to eql('application/json')
|
462
427
|
expect(content).to eql(
|
463
428
|
[
|
464
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
465
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
429
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
430
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' }
|
466
431
|
].to_json
|
467
432
|
)
|
468
433
|
|
469
434
|
# Valid selector, valid sort order
|
470
|
-
query = { '
|
435
|
+
query = { 'author' => 'Jane Doe', 'flash' => true, 'sort_by' => 'datetime' }
|
471
436
|
code, mime, content = @responder.generate_page('/api/pictures', query)
|
472
437
|
expect(code).to eql(200)
|
473
438
|
expect(mime).to eql('application/json')
|
474
439
|
expect(content).to eql(
|
475
440
|
[
|
476
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
477
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
441
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
442
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' }
|
478
443
|
].to_json
|
479
444
|
)
|
480
|
-
query = { '
|
445
|
+
query = { 'author' => 'Jane Doe', 'flash' => true, 'sort_by' => 'location',
|
481
446
|
'sort_order' => 'desc' }
|
482
447
|
code, mime, content = @responder.generate_page('/api/pictures', query)
|
483
448
|
expect(code).to eql(200)
|
484
449
|
expect(mime).to eql('application/json')
|
485
450
|
expect(content).to eql(
|
486
451
|
[
|
487
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
488
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
452
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
453
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' }
|
489
454
|
].to_json
|
490
455
|
)
|
491
456
|
|
@@ -1,46 +1,36 @@
|
|
1
1
|
{
|
2
2
|
"title": "My Gallery",
|
3
3
|
"groups": {
|
4
|
-
"
|
4
|
+
"author": [
|
5
5
|
{
|
6
|
-
"id": "
|
7
|
-
"title": "Group 1, Title 1",
|
6
|
+
"id": "John Doe",
|
8
7
|
"uri": "white.jpg",
|
9
|
-
"brief": "
|
8
|
+
"brief": "Best photographer ever"
|
10
9
|
},
|
11
10
|
{
|
12
|
-
"id": "
|
13
|
-
"title": "Group 1, Title 2",
|
11
|
+
"id": "Jane Doe",
|
14
12
|
"uri": "thumb12.jpg"
|
15
13
|
}
|
16
14
|
],
|
17
|
-
"
|
15
|
+
"location": [
|
18
16
|
{
|
19
|
-
"id": "
|
20
|
-
"
|
21
|
-
"uri": "alpha.png",
|
22
|
-
"value": "abcd"
|
17
|
+
"id": "New York, USA",
|
18
|
+
"uri": "alpha.png"
|
23
19
|
},
|
24
20
|
{
|
25
|
-
"id": "
|
26
|
-
"
|
27
|
-
"value": "bcde",
|
28
|
-
"brief": "brief_text_2"
|
21
|
+
"id": "Paris, France",
|
22
|
+
"brief": "The City of Light"
|
29
23
|
},
|
30
24
|
{
|
31
|
-
"id": "
|
32
|
-
"title": "Group 2, Title 3",
|
33
|
-
"value": "aabb"
|
25
|
+
"id": "Tokyo, Japan"
|
34
26
|
}
|
35
27
|
],
|
36
|
-
"
|
28
|
+
"camera": [
|
37
29
|
{
|
38
|
-
"id": "
|
39
|
-
"title": "Group 3, Title 1"
|
30
|
+
"id": "Apple iPhone 11"
|
40
31
|
},
|
41
32
|
{
|
42
|
-
"id": "
|
43
|
-
"title": "Group 3, Title 2"
|
33
|
+
"id": "Canon EOS 5D MARK IV"
|
44
34
|
}
|
45
35
|
]
|
46
36
|
},
|
@@ -48,36 +38,36 @@
|
|
48
38
|
{
|
49
39
|
"uri": "white.jpg",
|
50
40
|
"datetime": "2019:07:22 09:41:31",
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
41
|
+
"author": "John Doe",
|
42
|
+
"location": "Paris, France",
|
43
|
+
"camera": "Apple iPhone 11"
|
54
44
|
},
|
55
45
|
{
|
56
46
|
"uri": "./alpha.png",
|
57
47
|
"datetime": "2020:06:19 07:51:05",
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
48
|
+
"flash": false,
|
49
|
+
"author": "Jane Doe",
|
50
|
+
"location": "Tokyo, Japan"
|
61
51
|
},
|
62
52
|
{
|
63
53
|
"uri": "pic3.jpg",
|
64
54
|
"datetime": "2020:06:20 18:14:09",
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
55
|
+
"flash": true,
|
56
|
+
"author": "Jane Doe",
|
57
|
+
"location": "New York, USA"
|
68
58
|
},
|
69
59
|
{
|
70
60
|
"uri": "sample-db.json",
|
71
61
|
"datetime": "2020:06:20 06:09:54",
|
72
|
-
"
|
73
|
-
"
|
74
|
-
"
|
75
|
-
"
|
62
|
+
"flash": true,
|
63
|
+
"author": "Jane Doe",
|
64
|
+
"location": "Paris, France",
|
65
|
+
"camera": "Canon EOS 5D MARK IV"
|
76
66
|
},
|
77
67
|
{
|
78
68
|
"datetime": "2019:07:22 09:45:17",
|
79
|
-
"
|
80
|
-
"
|
69
|
+
"author": "John Doe",
|
70
|
+
"location": "Tokyo, Japan"
|
81
71
|
}
|
82
72
|
]
|
83
73
|
}
|
data/spec/spec_helper.rb
CHANGED
@@ -41,13 +41,11 @@ RSpec.configure do |config|
|
|
41
41
|
$LOAD_PATH << File.absolute_path(File.join('..', 'lib'), __dir__)
|
42
42
|
|
43
43
|
# Load and start SimpleCov to gather code coverage information
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
add_filter 'spec' # exclude 'spec' folder from coverage
|
51
|
-
end
|
44
|
+
require 'simplecov'
|
45
|
+
SimpleCov.start do
|
46
|
+
enable_coverage :branch # measure branches coverage
|
47
|
+
primary_coverage :branch
|
48
|
+
minimum_coverage line: 100, branch: 100 # minimal coverage rate to succeed
|
49
|
+
add_filter 'spec' # exclude 'spec' folder from coverage
|
52
50
|
end
|
53
51
|
end
|