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
@@ -24,119 +24,6 @@ RSpec.describe Intranet::Pictures::JsonDbProvider do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe '#group_types' do
|
28
|
-
before do
|
29
|
-
@provider = described_class.new(File.join(__dir__, 'sample-db.json'))
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should return the available group types' do
|
33
|
-
expect(@provider.group_types).to eql(%w[group1 group2 group3])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#list_groups' do
|
38
|
-
before do
|
39
|
-
@provider = described_class.new(File.join(__dir__, 'sample-db.json'))
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'given a valid +type+' do
|
43
|
-
it 'should return the list of groups of the given +type+ without the +uri+ key' do
|
44
|
-
expect(@provider.list_groups('group1')).to eql(
|
45
|
-
[
|
46
|
-
{ 'id' => 'group1_title1', 'title' => 'Group 1, Title 1', 'brief' => 'brief_text_1' },
|
47
|
-
{ 'id' => 'group1_title2', 'title' => 'Group 1, Title 2' }
|
48
|
-
]
|
49
|
-
)
|
50
|
-
expect(@provider.list_groups('group2')).to eql(
|
51
|
-
[
|
52
|
-
{ 'id' => 'group2_title1', 'title' => 'Group 2, Title 1', 'value' => 'abcd' },
|
53
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' },
|
54
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' }
|
55
|
-
]
|
56
|
-
)
|
57
|
-
expect(@provider.list_groups('group3')).to eql(
|
58
|
-
[
|
59
|
-
{ 'id' => 'group3_title1', 'title' => 'Group 3, Title 1' },
|
60
|
-
{ 'id' => 'group3_title2', 'title' => 'Group 3, Title 2' }
|
61
|
-
]
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should return only the groups matching the given +selector+' do
|
66
|
-
selector = { 'group1' => 'group1_title1' }
|
67
|
-
expect(@provider.list_groups('group2', selector)).to eql(
|
68
|
-
[
|
69
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' },
|
70
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' }
|
71
|
-
]
|
72
|
-
)
|
73
|
-
|
74
|
-
selector = { 'uri' => 'white.jpg' }
|
75
|
-
expect(@provider.list_groups('group1', selector)).to eql(
|
76
|
-
[
|
77
|
-
{ 'id' => 'group1_title1', 'title' => 'Group 1, Title 1', 'brief' => 'brief_text_1' }
|
78
|
-
]
|
79
|
-
)
|
80
|
-
|
81
|
-
selector = { 'group1' => 'group1_title2', 'value' => true }
|
82
|
-
expect(@provider.list_groups('group2', selector)).to eql(
|
83
|
-
[
|
84
|
-
{ 'id' => 'group2_title1', 'title' => 'Group 2, Title 1', 'value' => 'abcd' },
|
85
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' }
|
86
|
-
]
|
87
|
-
)
|
88
|
-
|
89
|
-
selector = { 'group2' => 'group2_title2', 'value' => false }
|
90
|
-
expect(@provider.list_groups('group2', selector)).to eql(
|
91
|
-
[
|
92
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' }
|
93
|
-
]
|
94
|
-
)
|
95
|
-
|
96
|
-
selector = { 'value' => true }
|
97
|
-
expect(@provider.list_groups('group3', selector)).to eql(
|
98
|
-
[
|
99
|
-
{ 'id' => 'group3_title2', 'title' => 'Group 3, Title 2' }
|
100
|
-
]
|
101
|
-
)
|
102
|
-
|
103
|
-
selector = { 'group4' => 'foo_bar_boz' } # referencing undefined fields
|
104
|
-
expect(@provider.list_groups('group2', selector)).to eql([])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'given an invalid +type+' do
|
109
|
-
it 'should raise KeyError' do
|
110
|
-
expect { @provider.list_groups('invalid') }.to raise_error(KeyError)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'given a valid +sort_by+ key' do
|
115
|
-
it 'should sort the groups by the given key' do
|
116
|
-
expect(@provider.list_groups('group1', {}, 'title', false)).to eql(
|
117
|
-
[
|
118
|
-
{ 'id' => 'group1_title2', 'title' => 'Group 1, Title 2' },
|
119
|
-
{ 'id' => 'group1_title1', 'title' => 'Group 1, Title 1', 'brief' => 'brief_text_1' }
|
120
|
-
]
|
121
|
-
)
|
122
|
-
|
123
|
-
expect(@provider.list_groups('group2', {}, 'value')).to eql(
|
124
|
-
[
|
125
|
-
{ 'id' => 'group2_title3', 'title' => 'Group 2, Title 3', 'value' => 'aabb' },
|
126
|
-
{ 'id' => 'group2_title1', 'title' => 'Group 2, Title 1', 'value' => 'abcd' },
|
127
|
-
{ 'id' => 'group2_title2', 'title' => 'Group 2, Title 2', 'value' => 'bcde', 'brief' => 'brief_text_2' }
|
128
|
-
]
|
129
|
-
)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'given an invalid +sort_by+ key' do
|
134
|
-
it 'should raise KeyError' do
|
135
|
-
expect { @provider.list_groups('group1', {}, 'invalid') }.to raise_error(KeyError)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
27
|
describe '#list_pictures' do
|
141
28
|
before do
|
142
29
|
@provider = described_class.new(File.join(__dir__, 'sample-db.json'))
|
@@ -145,42 +32,42 @@ RSpec.describe Intranet::Pictures::JsonDbProvider do
|
|
145
32
|
it 'should return the list of pictures without the uri key' do
|
146
33
|
expect(@provider.list_pictures).to eql(
|
147
34
|
[
|
148
|
-
{ 'datetime' => '2019:07:22 09:41:31', '
|
149
|
-
{ 'datetime' => '2020:06:19 07:51:05', '
|
150
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
151
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
152
|
-
{ 'datetime' => '2019:07:22 09:45:17', '
|
35
|
+
{ 'datetime' => '2019:07:22 09:41:31', 'author' => 'John Doe', 'location' => 'Paris, France', 'camera' => 'Apple iPhone 11' },
|
36
|
+
{ 'datetime' => '2020:06:19 07:51:05', 'flash' => false, 'author' => 'Jane Doe', 'location' => 'Tokyo, Japan' },
|
37
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
38
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
39
|
+
{ 'datetime' => '2019:07:22 09:45:17', 'author' => 'John Doe', 'location' => 'Tokyo, Japan' }
|
153
40
|
]
|
154
41
|
)
|
155
42
|
end
|
156
43
|
|
157
44
|
it 'should return only the pictures matching the given selector' do
|
158
|
-
selector = { '
|
45
|
+
selector = { 'author' => 'Jane Doe' }
|
159
46
|
expect(@provider.list_pictures(selector)).to eql(
|
160
47
|
[
|
161
|
-
{ 'datetime' => '2020:06:19 07:51:05', '
|
162
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
163
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
48
|
+
{ 'datetime' => '2020:06:19 07:51:05', 'flash' => false, 'author' => 'Jane Doe', 'location' => 'Tokyo, Japan' },
|
49
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
50
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' }
|
164
51
|
]
|
165
52
|
)
|
166
53
|
end
|
167
54
|
|
168
55
|
context 'given a valid +sort_by+ key' do
|
169
56
|
it 'should sort the pictures by the given key' do
|
170
|
-
selector = { '
|
171
|
-
expect(@provider.list_pictures(selector, '
|
57
|
+
selector = { 'author' => 'Jane Doe' }
|
58
|
+
expect(@provider.list_pictures(selector, 'location')).to eql(
|
172
59
|
[
|
173
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
174
|
-
{ 'datetime' => '2020:06:
|
175
|
-
{ 'datetime' => '2020:06:
|
60
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
61
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
62
|
+
{ 'datetime' => '2020:06:19 07:51:05', 'flash' => false, 'author' => 'Jane Doe', 'location' => 'Tokyo, Japan' }
|
176
63
|
]
|
177
64
|
)
|
178
65
|
|
179
66
|
expect(@provider.list_pictures(selector, 'datetime', false)).to eql(
|
180
67
|
[
|
181
|
-
{ 'datetime' => '2020:06:20 18:14:09', '
|
182
|
-
{ 'datetime' => '2020:06:20 06:09:54', '
|
183
|
-
{ 'datetime' => '2020:06:19 07:51:05', '
|
68
|
+
{ 'datetime' => '2020:06:20 18:14:09', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'New York, USA' },
|
69
|
+
{ 'datetime' => '2020:06:20 06:09:54', 'flash' => true, 'author' => 'Jane Doe', 'location' => 'Paris, France', 'camera' => 'Canon EOS 5D MARK IV' },
|
70
|
+
{ 'datetime' => '2020:06:19 07:51:05', 'flash' => false, 'author' => 'Jane Doe', 'location' => 'Tokyo, Japan' }
|
184
71
|
]
|
185
72
|
)
|
186
73
|
end
|
@@ -234,7 +121,7 @@ RSpec.describe Intranet::Pictures::JsonDbProvider do
|
|
234
121
|
|
235
122
|
context 'when +selector+ matches zero or more than one picture' do
|
236
123
|
it 'should raise KeyError' do
|
237
|
-
selector = { '
|
124
|
+
selector = { 'author' => 'Jane Doe' }
|
238
125
|
expect { @provider.picture(selector) }.to raise_error(KeyError)
|
239
126
|
selector = { 'uri' => 'black.jpg' }
|
240
127
|
expect { @provider.picture(selector) }.to raise_error(KeyError)
|
@@ -247,39 +134,57 @@ RSpec.describe Intranet::Pictures::JsonDbProvider do
|
|
247
134
|
@provider = described_class.new(File.join(__dir__, 'sample-db.json'))
|
248
135
|
end
|
249
136
|
|
250
|
-
context 'when +
|
137
|
+
context 'when +key+ and +value+ designate one group with +uri+ pointing to a valid image file' do
|
251
138
|
it 'should return the thumbnail file mime type and content' do
|
252
|
-
|
253
|
-
expect(@provider.group_thumbnail('group1', selector)).to eql(
|
139
|
+
expect(@provider.group_thumbnail('author', 'John Doe')).to eql(
|
254
140
|
['image/jpeg', File.read(File.join(__dir__, 'white.jpg'))]
|
255
141
|
)
|
256
|
-
|
257
|
-
expect(@provider.group_thumbnail('group2', selector)).to eql(
|
142
|
+
expect(@provider.group_thumbnail('location', 'New York, USA')).to eql(
|
258
143
|
['image/png', File.read(File.join(__dir__, 'alpha.png'))]
|
259
144
|
)
|
260
145
|
end
|
261
146
|
end
|
262
147
|
|
263
|
-
context 'when +
|
148
|
+
context 'when +key+ and +value+ designate one group with a +uri+ pointing to a non-existing file' do
|
264
149
|
it 'should raise KeyError' do
|
265
|
-
|
266
|
-
expect { @provider.group_thumbnail('group1', selector) }.to raise_error(KeyError)
|
150
|
+
expect { @provider.group_thumbnail('author', 'Jane Doe') }.to raise_error(KeyError)
|
267
151
|
end
|
268
152
|
end
|
269
153
|
|
270
|
-
context 'when +
|
154
|
+
context 'when +key+ and +value+ designate one group with +uri+ not defined' do
|
271
155
|
it 'should return nil' do
|
272
|
-
|
273
|
-
|
156
|
+
expect(@provider.group_thumbnail('location', 'Paris, France')).to be_nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when +key+ and +value+ do not designate an existing group' do
|
161
|
+
it 'should raise KeyError' do
|
162
|
+
expect { @provider.group_thumbnail('author', 'invalid') }.to raise_error(KeyError)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#group_brief' do
|
168
|
+
before do
|
169
|
+
@provider = described_class.new(File.join(__dir__, 'sample-db.json'))
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when +key+ and +value+ designate one group with a brief text' do
|
173
|
+
it 'should return the brief text' do
|
174
|
+
expect(@provider.group_brief('author', 'John Doe')).to eql('Best photographer ever')
|
175
|
+
expect(@provider.group_brief('location', 'Paris, France')).to eql('The City of Light')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'when +key+ and +value+ designate one group without a brief text' do
|
180
|
+
it 'should return an empty string' do
|
181
|
+
expect(@provider.group_brief('author', 'Jane Doe')).to be_empty
|
274
182
|
end
|
275
183
|
end
|
276
184
|
|
277
|
-
context 'when +
|
185
|
+
context 'when +key+ and +value+ do not designate an existing group' do
|
278
186
|
it 'should raise KeyError' do
|
279
|
-
|
280
|
-
expect { @provider.group_thumbnail('group1', selector) }.to raise_error(KeyError)
|
281
|
-
selector = { 'value' => true }
|
282
|
-
expect { @provider.group_thumbnail('group2', selector) }.to raise_error(KeyError)
|
187
|
+
expect { @provider.group_brief('author', 'invalid') }.to raise_error(KeyError)
|
283
188
|
end
|
284
189
|
end
|
285
190
|
end
|