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.
@@ -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 = [{ group_type: 'group2', sort_by: 'value', asc: false, limit: 2 }]
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.group2')}</h3>\n" \
68
+ "<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
69
69
  "<ul class='groups'>\n" \
70
- "<li title='Group 2, Title 2'>\n<a onclick='openImagesGallery(&quot;group2=group2_title2&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title2&quot;)'></div>\n<figcaption>\nGroup 2, Title 2\n<br>\n<em>brief_text_2</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
71
- "<li title='Group 2, Title 1'>\n<a onclick='openImagesGallery(&quot;group2=group2_title1&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title1&quot;)'></div>\n<figcaption>\nGroup 2, Title 1\n</figcaption>\n</figure>\n</a>\n</li>\n" \
70
+ "<li title='New York, USA'>\n<a onclick='openImagesGallery(&quot;location=New York, USA&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=New York, USA&quot;)'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
71
+ "<li title='Paris, France'>\n<a onclick='openImagesGallery(&quot;location=Paris, France&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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='browse_group2.html?sort_by=value&amp;sort_order=desc'>#{I18n.t('pictures.see_more')}</a>\n</p>\n" \
73
+ "<p class='see_more'>\n<a href='browse.html?group_by=location&amp;sort_by=datetime&amp;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 = [{ group_type: 'group2', sort_by: 'value', asc: true, limit: 2 }]
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.group2')}</h3>\n" \
99
+ "<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
100
100
  "<ul class='groups'>\n" \
101
- "<li title='Group 2, Title 3'>\n<a onclick='openImagesGallery(&quot;group2=group2_title3&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title3&quot;)'></div>\n<figcaption>\nGroup 2, Title 3\n</figcaption>\n</figure>\n</a>\n</li>\n" \
102
- "<li title='Group 2, Title 1'>\n<a onclick='openImagesGallery(&quot;group2=group2_title1&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title1&quot;)'></div>\n<figcaption>\nGroup 2, Title 1\n</figcaption>\n</figure>\n</a>\n</li>\n" \
101
+ "<li title='Paris, France'>\n<a onclick='openImagesGallery(&quot;location=Paris, France&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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(&quot;location=Tokyo, Japan&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Tokyo, Japan&quot;)'></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='browse_group2.html?sort_by=value'>#{I18n.t('pictures.see_more')}</a>\n</p>\n" \
104
+ "<p class='see_more'>\n<a href='browse.html?group_by=location&amp;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 = [{ group_type: 'group2' }]
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.group2')}</h3>\n" \
130
+ "<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
131
131
  "<ul class='groups'>\n" \
132
- "<li title='Group 2, Title 3'>\n<a onclick='openImagesGallery(&quot;group2=group2_title3&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title3&quot;)'></div>\n<figcaption>\nGroup 2, Title 3\n</figcaption>\n</figure>\n</a>\n</li>\n" \
133
- "<li title='Group 2, Title 2'>\n<a onclick='openImagesGallery(&quot;group2=group2_title2&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title2&quot;)'></div>\n<figcaption>\nGroup 2, Title 2\n<br>\n<em>brief_text_2</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
134
- "<li title='Group 2, Title 1'>\n<a onclick='openImagesGallery(&quot;group2=group2_title1&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title1&quot;)'></div>\n<figcaption>\nGroup 2, Title 1\n</figcaption>\n</figure>\n</a>\n</li>\n" \
132
+ "<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery(&quot;location=Tokyo, Japan&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Tokyo, Japan&quot;)'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
133
+ "<li title='Paris, France'>\n<a onclick='openImagesGallery(&quot;location=Paris, France&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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(&quot;location=New York, USA&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=New York, USA&quot;)'></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 = [{ group_type: 'invalid', sort_by: 'id' }]
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 = [{ group_type: 'group2', asc: true, browse: 'group1', browse_sort_by: 'uri', browse_asc: true }]
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.group2')}</h3>\n" \
172
+ "<h3>#{I18n.t('pictures.browse_by.location')}</h3>\n" \
172
173
  "<ul class='groups wide'>\n" \
173
- "<li title='Group 2, Title 1'>\n<a href='browse_group1.html?sort_by=uri&amp;group2=group2_title1'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title1&quot;)'></div>\n<figcaption>\nGroup 2, Title 1\n</figcaption>\n</figure>\n</a>\n</li>\n" \
174
- "<li title='Group 2, Title 2'>\n<a href='browse_group1.html?sort_by=uri&amp;group2=group2_title2'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title2&quot;)'></div>\n<figcaption>\nGroup 2, Title 2\n<br>\n<em>brief_text_2</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
175
- "<li title='Group 2, Title 3'>\n<a href='browse_group1.html?sort_by=uri&amp;group2=group2_title3'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title3&quot;)'></div>\n<figcaption>\nGroup 2, Title 3\n</figcaption>\n</figure>\n</a>\n</li>\n" \
174
+ "<li title='New York, USA'>\n<a href='browse.html?group_by=author&amp;location=New York, USA'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=New York, USA&quot;)'></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&amp;location=Paris, France'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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&amp;location=Tokyo, Japan'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Tokyo, Japan&quot;)'></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 = [{ group_type: 'group2' }]
190
+ recents = [{ 'group_by' => 'location', 'sort_by' => 'location', 'sort_order' => 'asc' }]
190
191
  @responder.instance_variable_set(:@recents, recents)
191
- home_groups = [{ group_type: 'group1', asc: false, browse: 'group2', browse_sort_by: 'value', browse_asc: false }]
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.group2')}</h3>\n" \
206
+ "<h3>#{I18n.t('pictures.recents.location')}</h3>\n" \
205
207
  "<ul class='groups'>\n" \
206
- "<li title='Group 2, Title 3'>\n<a onclick='openImagesGallery(&quot;group2=group2_title3&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title3&quot;)'></div>\n<figcaption>\nGroup 2, Title 3\n</figcaption>\n</figure>\n</a>\n</li>\n" \
207
- "<li title='Group 2, Title 2'>\n<a onclick='openImagesGallery(&quot;group2=group2_title2&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title2&quot;)'></div>\n<figcaption>\nGroup 2, Title 2\n<br>\n<em>brief_text_2</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
208
- "<li title='Group 2, Title 1'>\n<a onclick='openImagesGallery(&quot;group2=group2_title1&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title1&quot;)'></div>\n<figcaption>\nGroup 2, Title 1\n</figcaption>\n</figure>\n</a>\n</li>\n" \
208
+ "<li title='New York, USA'>\n<a onclick='openImagesGallery(&quot;location=New York, USA&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=New York, USA&quot;)'></div>\n<figcaption>\nNew York, USA\n</figcaption>\n</figure>\n</a>\n</li>\n" \
209
+ "<li title='Paris, France'>\n<a onclick='openImagesGallery(&quot;location=Paris, France&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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(&quot;location=Tokyo, Japan&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Tokyo, Japan&quot;)'></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.group1')}</h3>\n" \
212
+ "<h3>#{I18n.t('pictures.browse_by.author')}</h3>\n" \
211
213
  "<ul class='groups wide'>\n" \
212
- "<li title='Group 1, Title 2'>\n<a href='browse_group2.html?sort_by=value&amp;sort_order=desc&amp;group1=group1_title2'>\n<figure>\n<div style='background-image: url(&quot;api/group/group1?group1=group1_title2&quot;)'></div>\n<figcaption>\nGroup 1, Title 2\n</figcaption>\n</figure>\n</a>\n</li>\n" \
213
- "<li title='Group 1, Title 1'>\n<a href='browse_group2.html?sort_by=value&amp;sort_order=desc&amp;group1=group1_title1'>\n<figure>\n<div style='background-image: url(&quot;api/group/group1?group1=group1_title1&quot;)'></div>\n<figcaption>\nGroup 1, Title 1\n<br>\n<em>brief_text_1</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
214
+ "<li title='Jane Doe'>\n<a href='browse.html?group_by=location&amp;sort_by=location&amp;sort_order=desc&amp;author=Jane Doe'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?author=Jane Doe&quot;)'></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&amp;sort_by=location&amp;sort_order=desc&amp;author=John Doe'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?author=John Doe&quot;)'></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 \'/browse_*.html\'' do
229
- it 'should return a partial HTML content with selected groups' do
230
- # Existing group, no selector nor sort order
231
- query = {}
232
- code, mime, content = @responder.generate_page('/browse_group1.html', query)
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.group1')}</li>\n" \
244
+ "<li>#{I18n.t('pictures.nav.author')}</li>\n" \
243
245
  "</ul>\n\n" \
244
246
  "<ul class='groups'>\n" \
245
- "<li title='Group 1, Title 1'>\n<a onclick='openImagesGallery(&quot;group1=group1_title1&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group1?group1=group1_title1&quot;)'></div>\n<figcaption>\nGroup 1, Title 1\n<br>\n<em>brief_text_1</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
246
- "<li title='Group 1, Title 2'>\n<a onclick='openImagesGallery(&quot;group1=group1_title2&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group1?group1=group1_title2&quot;)'></div>\n<figcaption>\nGroup 1, Title 2\n</figcaption>\n</figure>\n</a>\n</li>\n" \
247
+ "<li title='John Doe'>\n<a onclick='openImagesGallery(&quot;author=John Doe&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?author=John Doe&quot;)'></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(&quot;author=Jane Doe&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?author=Jane Doe&quot;)'></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
- # Existing group, valid selector, valid sort order
260
- query = { 'group1' => 'group1_title1', 'sort_by' => 'id', 'sort_order' => 'desc' }
261
- code, mime, content = @responder.generate_page('/browse_group2.html', query)
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.group2')} (Group 1, Title 1)</li>\n" \
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='Group 2, Title 3'>\n<a onclick='openImagesGallery(&quot;group1=group1_title1&amp;group2=group2_title3&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title3&quot;)'></div>\n<figcaption>\nGroup 2, Title 3\n</figcaption>\n</figure>\n</a>\n</li>\n" \
275
- "<li title='Group 2, Title 2'>\n<a onclick='openImagesGallery(&quot;group1=group1_title1&amp;group2=group2_title2&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group/group2?group2=group2_title2&quot;)'></div>\n<figcaption>\nGroup 2, Title 2\n<br>\n<em>brief_text_2</em>\n</figcaption>\n</figure>\n</a>\n</li>\n" \
276
+ "<li title='Tokyo, Japan'>\n<a onclick='openImagesGallery(&quot;author=John Doe&amp;location=Tokyo, Japan&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Tokyo, Japan&quot;)'></div>\n<figcaption>\nTokyo, Japan\n</figcaption>\n</figure>\n</a>\n</li>\n" \
277
+ "<li title='Paris, France'>\n<a onclick='openImagesGallery(&quot;author=John Doe&amp;location=Paris, France&amp;sort_by=datetime&quot;);'>\n<figure>\n<div style='background-image: url(&quot;api/group_thumbnail?location=Paris, France&quot;)'></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('/browse_group2.html', query)
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.group2')} (bar)</li>\n" \
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 group type
315
- code, mime, content = @responder.generate_page('/browse_foo.html', {})
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 sort order
321
- query = { 'sort_order' => 'foo' }
322
- code, mime, content = @responder.generate_page('/browse_group2.html', query)
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/groups\'' do
345
- it 'should return a JSON representation of the selected groups' do
346
- # Existing group, no selector nor sort order
347
- query = {}
348
- code, mime, content = @responder.generate_page('/api/groups/group1', query)
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('application/json')
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, valid selector, valid sort order
371
- query = { 'group1' => 'group1_title1', 'sort_by' => 'value', 'sort_order' => 'asc' }
372
- code, mime, content = @responder.generate_page('/api/groups/group2', query)
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('application/json')
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
- # Invalid selector
393
- query = { 'foo' => 'bar' }
394
- code, mime, content = @responder.generate_page('/api/groups/group2', query)
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 sort order
406
- query = { 'sort_order' => 'foo' }
407
- code, mime, content = @responder.generate_page('/api/groups/group2', query)
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/group\'' do
415
- it 'should return the selected group thumnail' do
416
- # Existing group with thumbnail
417
- query = { 'group2' => 'group2_title1' }
418
- code, mime, content = @responder.generate_page('/api/group/group2', query)
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('image/png')
421
- expect(content).to eql(File.read(File.join(__dir__, 'alpha.png')))
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 specified thumbnail
424
- query = { 'group2' => 'group2_title2' }
425
- code, mime, content = @responder.generate_page('/api/group/group2', query)
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('image/svg+xml')
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
- # Existing group with non-existant thumbnail
433
- query = { 'group1' => 'group1_title2' }
434
- code, mime, content = @responder.generate_page('/api/group/group1', query)
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', 'group1' => 'group1_title1', 'group2' => 'group2_title2', 'group3' => 'group3_title1' },
450
- { 'datetime' => '2020:06:19 07:51:05', 'value' => false, 'group1' => 'group1_title2', 'group2' => 'group2_title2' },
451
- { 'datetime' => '2020:06:20 18:14:09', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title1' },
452
- { 'datetime' => '2020:06:20 06:09:54', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title3', 'group3' => 'group3_title2' },
453
- { 'datetime' => '2019:07:22 09:45:17', 'group1' => 'group1_title1', 'group2' => 'group2_title3' }
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 = { 'group1' => 'group1_title2', 'value' => true }
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', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title1' },
465
- { 'datetime' => '2020:06:20 06:09:54', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title3', 'group3' => 'group3_title2' }
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 = { 'group1' => 'group1_title2', 'value' => true, 'sort_by' => 'datetime' }
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', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title3', 'group3' => 'group3_title2' },
477
- { 'datetime' => '2020:06:20 18:14:09', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title1' }
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 = { 'group1' => 'group1_title2', 'value' => true, 'sort_by' => 'group2',
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', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title3', 'group3' => 'group3_title2' },
488
- { 'datetime' => '2020:06:20 18:14:09', 'value' => true, 'group1' => 'group1_title2', 'group2' => 'group2_title1' }
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
- "group1": [
4
+ "author": [
5
5
  {
6
- "id": "group1_title1",
7
- "title": "Group 1, Title 1",
6
+ "id": "John Doe",
8
7
  "uri": "white.jpg",
9
- "brief": "brief_text_1"
8
+ "brief": "Best photographer ever"
10
9
  },
11
10
  {
12
- "id": "group1_title2",
13
- "title": "Group 1, Title 2",
11
+ "id": "Jane Doe",
14
12
  "uri": "thumb12.jpg"
15
13
  }
16
14
  ],
17
- "group2": [
15
+ "location": [
18
16
  {
19
- "id": "group2_title1",
20
- "title": "Group 2, Title 1",
21
- "uri": "alpha.png",
22
- "value": "abcd"
17
+ "id": "New York, USA",
18
+ "uri": "alpha.png"
23
19
  },
24
20
  {
25
- "id": "group2_title2",
26
- "title": "Group 2, Title 2",
27
- "value": "bcde",
28
- "brief": "brief_text_2"
21
+ "id": "Paris, France",
22
+ "brief": "The City of Light"
29
23
  },
30
24
  {
31
- "id": "group2_title3",
32
- "title": "Group 2, Title 3",
33
- "value": "aabb"
25
+ "id": "Tokyo, Japan"
34
26
  }
35
27
  ],
36
- "group3": [
28
+ "camera": [
37
29
  {
38
- "id": "group3_title1",
39
- "title": "Group 3, Title 1"
30
+ "id": "Apple iPhone 11"
40
31
  },
41
32
  {
42
- "id": "group3_title2",
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
- "group1": "group1_title1",
52
- "group2": "group2_title2",
53
- "group3": "group3_title1"
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
- "value": false,
59
- "group1": "group1_title2",
60
- "group2": "group2_title2"
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
- "value": true,
66
- "group1": "group1_title2",
67
- "group2": "group2_title1"
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
- "value": true,
73
- "group1": "group1_title2",
74
- "group2": "group2_title3",
75
- "group3": "group3_title2"
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
- "group1": "group1_title1",
80
- "group2": "group2_title3"
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
- unless config.files_to_run.one?
45
- require 'simplecov'
46
- SimpleCov.start do
47
- enable_coverage :branch # measure branches coverage
48
- primary_coverage :branch
49
- minimum_coverage line: 100, branch: 100 # minimal coverage rate to succeed
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