ruby-thumbor 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +19 -6
- data/lib/ruby-thumbor.rb +9 -142
- data/lib/thumbor/cascade.rb +70 -0
- data/lib/thumbor/crypto_url.rb +146 -0
- data/lib/thumbor/version.rb +3 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/thumbor/cascade_spec.rb +392 -0
- data/spec/thumbor/crypto_url_spec.rb +371 -0
- data/spec/util/thumbor.rb +7 -0
- metadata +25 -49
- data/.gemtest +0 -0
- data/History.txt +0 -19
- data/Manifest.txt +0 -13
- data/PostInstall.txt +0 -3
- data/Rakefile +0 -21
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/ruby-thumbor_spec.rb +0 -436
- data/spec/spec.opts +0 -1
- data/tasks/rspec.rake +0 -1
@@ -0,0 +1,392 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'ruby-thumbor'
|
4
|
+
require 'util/thumbor'
|
5
|
+
|
6
|
+
describe Thumbor::Cascade do
|
7
|
+
let(:image_url) { 'my.domain.com/some/image/url.jpg' }
|
8
|
+
let(:image_md5) { 'f33af67e41168e80fcc5b00f8bd8061a' }
|
9
|
+
let(:key) { 'my-security-key' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
Thumbor.key = key
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { Thumbor::Cascade.new image_url }
|
16
|
+
|
17
|
+
describe '#new' do
|
18
|
+
it "should create a new instance passing key and keep it" do
|
19
|
+
subject.computed_key.should == 'my-security-keym'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should raise an error' do
|
24
|
+
expect{ subject.god_of_war_crop }.to raise_error(NoMethodError)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#url_for' do
|
28
|
+
|
29
|
+
it "should return just the image hash if no arguments passed" do
|
30
|
+
url = subject.url_for
|
31
|
+
url.should == image_md5
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise if no image passed" do
|
35
|
+
expect { Thumbor::Cascade.new.url_for }.to raise_error(RuntimeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return proper url for width-only" do
|
39
|
+
url = subject.width(300).url_for
|
40
|
+
url.should == '300x0/' << image_md5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return proper url for height-only" do
|
44
|
+
url = subject.height(300).url_for
|
45
|
+
url.should == '0x300/' << image_md5
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return proper url for width and height" do
|
49
|
+
url = subject.width(200).height(300).url_for
|
50
|
+
url.should == '200x300/' << image_md5
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return proper smart url" do
|
54
|
+
url = subject.width(200).height(300).smart(true).url_for
|
55
|
+
url.should == '200x300/smart/' << image_md5
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return proper fit-in url" do
|
59
|
+
url = subject.width(200).height(300).fit_in(true).url_for
|
60
|
+
url.should == 'fit-in/200x300/' << image_md5
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return proper flip url if no width and height" do
|
64
|
+
url = subject.flip(true).url_for
|
65
|
+
url.should == '-0x0/' << image_md5
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return proper flop url if no width and height" do
|
69
|
+
url = subject.flop(true).url_for
|
70
|
+
url.should == '0x-0/' << image_md5
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return proper flip-flop url if no width and height" do
|
74
|
+
url = subject.flip(true).flop(true).url_for
|
75
|
+
url.should == '-0x-0/' << image_md5
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return proper flip url if width" do
|
79
|
+
url = subject.width(300).flip(true).url_for
|
80
|
+
url.should == '-300x0/' << image_md5
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return proper flop url if height" do
|
84
|
+
url = subject.height(300).flop(true).url_for
|
85
|
+
url.should == '0x-300/' << image_md5
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return horizontal align" do
|
89
|
+
url = subject.halign(:left).url_for
|
90
|
+
url.should == 'left/' << image_md5
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not return horizontal align if it is center" do
|
94
|
+
url = subject.halign(:center).url_for
|
95
|
+
url.should == image_md5
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return vertical align" do
|
99
|
+
url = subject.valign(:top).url_for
|
100
|
+
url.should == 'top/' << image_md5
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not return vertical align if it is middle" do
|
104
|
+
url = subject.valign(:middle).url_for
|
105
|
+
url.should == image_md5
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return halign and valign properly" do
|
109
|
+
url = subject.halign(:left).valign(:top).url_for
|
110
|
+
url.should == 'left/top/' << image_md5
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return meta properly" do
|
114
|
+
url = subject.meta(true).url_for
|
115
|
+
url.should == 'meta/' << image_md5
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return proper crop url when param is array" do
|
119
|
+
url = subject.crop([10, 20, 30, 40]).url_for
|
120
|
+
url.should == '10x20:30x40/' << image_md5
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return proper crop url" do
|
124
|
+
url = subject.crop(10, 20, 30, 40).url_for
|
125
|
+
url.should == '10x20:30x40/' << image_md5
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should ignore crop if all zeros" do
|
129
|
+
url = subject.crop(0, 0, 0, 0).url_for
|
130
|
+
url.should == image_md5
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have smart after halign and valign" do
|
134
|
+
url = subject.halign(:left).valign(:top).smart(true).url_for
|
135
|
+
url.should == 'left/top/smart/' << image_md5
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have quality filter" do
|
139
|
+
url = subject.quality_filter(20).url_for
|
140
|
+
url.should == 'filters:quality(20)/' << image_md5
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should have brightness filter" do
|
144
|
+
url = subject.brightness_filter(30).url_for
|
145
|
+
url.should == 'filters:brightness(30)/' << image_md5
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should have 2 filters" do
|
149
|
+
url = subject.brightness_filter(30).quality_filter(20).url_for
|
150
|
+
url.should == 'filters:brightness(30):quality(20)/' << image_md5
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should escape url args" do
|
154
|
+
url = subject.watermark_filter('http://my-server.com/image.png', 30).quality_filter(20).url_for
|
155
|
+
url.should == 'filters:watermark(http%3A%2F%2Fmy-server.com%2Fimage.png,30):quality(20)/' << image_md5
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should have trim without params" do
|
159
|
+
url = subject.trim.url_for
|
160
|
+
url.should == 'trim/' << image_md5
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should have trim with direction param" do
|
164
|
+
url = subject.trim('bottom-right').url_for
|
165
|
+
url.should == 'trim:bottom-right/' << image_md5
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should have trim with direction and tolerance param" do
|
169
|
+
url = subject.trim('bottom-right', 15).url_for
|
170
|
+
url.should == 'trim:bottom-right:15/' << image_md5
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#generate' do
|
175
|
+
|
176
|
+
it "should create a new instance passing key and keep it" do
|
177
|
+
url = subject.width(300).height(200).generate
|
178
|
+
url.should == '/TQfyd3H36Z3srcNcLOYiM05YNO8=/300x200/my.domain.com/some/image/url.jpg'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should create a new instance passing key and keep it" do
|
182
|
+
url = subject.width(300).height(200).meta(true).generate
|
183
|
+
url.should == '/YBQEWd3g_WRMnVEG73zfzcr8Zj0=/meta/300x200/my.domain.com/some/image/url.jpg'
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should create a new instance passing key and keep it" do
|
187
|
+
url = subject.width(300).height(200).meta(true).smart(true).generate
|
188
|
+
url.should == '/jP89J0qOWHgPlm_lOA28GtOh5GU=/meta/300x200/smart/my.domain.com/some/image/url.jpg'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should create a new instance passing key and keep it" do
|
192
|
+
url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).generate
|
193
|
+
url.should == '/zrrOh_TtTs4kiLLEQq1w4bcTYdc=/meta/fit-in/300x200/smart/my.domain.com/some/image/url.jpg'
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should create a new instance passing key and keep it" do
|
197
|
+
url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).generate
|
198
|
+
url.should == '/4t1XK1KH43cOb1QJ9tU00-W2_k8=/meta/fit-in/-300x200/smart/my.domain.com/some/image/url.jpg'
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should create a new instance passing key and keep it" do
|
202
|
+
url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).flop(true).generate
|
203
|
+
url.should == '/HJnvjZU69PkPOhyZGu-Z3Uc_W_A=/meta/fit-in/-300x-200/smart/my.domain.com/some/image/url.jpg'
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should create a new instance passing key and keep it" do
|
207
|
+
url = subject.quality_filter(20).brightness_filter(10).generate
|
208
|
+
url.should == '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#generate :old => true" do
|
213
|
+
subject { Thumbor::Cascade.new(image_url).old(true) }
|
214
|
+
|
215
|
+
it "should create a new instance passing key and keep it" do
|
216
|
+
url = subject.width(300).height(200).generate
|
217
|
+
url.should == '/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should allow thumbor to decrypt it properly" do
|
221
|
+
url = subject.width(300).height(200).generate
|
222
|
+
|
223
|
+
encrypted = url.split('/')[1]
|
224
|
+
|
225
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
226
|
+
|
227
|
+
decrypted["horizontal_flip"].should == false
|
228
|
+
decrypted["vertical_flip"].should == false
|
229
|
+
decrypted["smart"].should == false
|
230
|
+
decrypted["meta"].should == false
|
231
|
+
decrypted["fit_in"].should == false
|
232
|
+
decrypted["crop"]["left"].should == 0
|
233
|
+
decrypted["crop"]["top"].should == 0
|
234
|
+
decrypted["crop"]["right"].should == 0
|
235
|
+
decrypted["crop"]["bottom"].should == 0
|
236
|
+
decrypted["valign"].should == 'middle'
|
237
|
+
decrypted["halign"].should == 'center'
|
238
|
+
decrypted["image_hash"].should == image_md5
|
239
|
+
decrypted["width"].should == 300
|
240
|
+
decrypted["height"].should == 200
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should allow thumbor to decrypt it properly with meta" do
|
245
|
+
url = subject.width(300).height(200).meta(true).generate
|
246
|
+
|
247
|
+
encrypted = url.split('/')[1]
|
248
|
+
|
249
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
250
|
+
|
251
|
+
decrypted["meta"].should == true
|
252
|
+
decrypted["image_hash"].should == image_md5
|
253
|
+
decrypted["width"].should == 300
|
254
|
+
decrypted["height"].should == 200
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should allow thumbor to decrypt it properly with smart" do
|
259
|
+
url = subject.width(300).height(200).meta(true).smart(true).generate
|
260
|
+
|
261
|
+
encrypted = url.split('/')[1]
|
262
|
+
|
263
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
264
|
+
|
265
|
+
decrypted["meta"].should == true
|
266
|
+
decrypted["smart"].should == true
|
267
|
+
decrypted["image_hash"].should == image_md5
|
268
|
+
decrypted["width"].should == 300
|
269
|
+
decrypted["height"].should == 200
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should allow thumbor to decrypt it properly with fit-in" do
|
274
|
+
url = subject.width(300).height(200).fit_in(true).generate
|
275
|
+
|
276
|
+
encrypted = url.split('/')[1]
|
277
|
+
|
278
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
279
|
+
|
280
|
+
decrypted["fit_in"].should == true
|
281
|
+
decrypted["image_hash"].should == image_md5
|
282
|
+
decrypted["width"].should == 300
|
283
|
+
decrypted["height"].should == 200
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should allow thumbor to decrypt it properly with flip" do
|
288
|
+
url = subject.width(300).height(200).meta(true).smart(true).flip(true).generate
|
289
|
+
|
290
|
+
encrypted = url.split('/')[1]
|
291
|
+
|
292
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
293
|
+
|
294
|
+
decrypted["meta"].should == true
|
295
|
+
decrypted["smart"].should == true
|
296
|
+
decrypted["image_hash"].should == image_md5
|
297
|
+
decrypted["width"].should == 300
|
298
|
+
decrypted["height"].should == 200
|
299
|
+
decrypted["flip_horizontally"] == true
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should allow thumbor to decrypt it properly with flop" do
|
304
|
+
url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).generate
|
305
|
+
|
306
|
+
encrypted = url.split('/')[1]
|
307
|
+
|
308
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
309
|
+
|
310
|
+
decrypted["meta"].should == true
|
311
|
+
decrypted["smart"].should == true
|
312
|
+
decrypted["image_hash"].should == image_md5
|
313
|
+
decrypted["width"].should == 300
|
314
|
+
decrypted["height"].should == 200
|
315
|
+
decrypted["flip_horizontally"] == true
|
316
|
+
decrypted["flip_vertically"] == true
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should allow thumbor to decrypt it properly with halign" do
|
321
|
+
url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).
|
322
|
+
halign(:left).generate
|
323
|
+
|
324
|
+
encrypted = url.split('/')[1]
|
325
|
+
|
326
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
327
|
+
|
328
|
+
decrypted["meta"].should == true
|
329
|
+
decrypted["smart"].should == true
|
330
|
+
decrypted["image_hash"].should == image_md5
|
331
|
+
decrypted["width"].should == 300
|
332
|
+
decrypted["height"].should == 200
|
333
|
+
decrypted["flip_horizontally"] == true
|
334
|
+
decrypted["flip_vertically"] == true
|
335
|
+
decrypted["halign"] == "left"
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should allow thumbor to decrypt it properly with valign" do
|
340
|
+
url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).
|
341
|
+
halign(:left).valign(:top).generate
|
342
|
+
|
343
|
+
encrypted = url.split('/')[1]
|
344
|
+
|
345
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
346
|
+
|
347
|
+
decrypted["meta"].should == true
|
348
|
+
decrypted["smart"].should == true
|
349
|
+
decrypted["image_hash"].should == image_md5
|
350
|
+
decrypted["width"].should == 300
|
351
|
+
decrypted["height"].should == 200
|
352
|
+
decrypted["flip_horizontally"] == true
|
353
|
+
decrypted["flip_vertically"] == true
|
354
|
+
decrypted["halign"] == "left"
|
355
|
+
decrypted["valign"] == "top"
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should allow thumbor to decrypt it properly with cropping" do
|
360
|
+
url = subject.width(300).height(200).crop([10, 20, 30, 40]).generate
|
361
|
+
|
362
|
+
encrypted = url.split('/')[1]
|
363
|
+
|
364
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
365
|
+
|
366
|
+
decrypted["horizontal_flip"].should == false
|
367
|
+
decrypted["vertical_flip"].should == false
|
368
|
+
decrypted["smart"].should == false
|
369
|
+
decrypted["meta"].should == false
|
370
|
+
decrypted["crop"]["left"].should == 10
|
371
|
+
decrypted["crop"]["top"].should == 20
|
372
|
+
decrypted["crop"]["right"].should == 30
|
373
|
+
decrypted["crop"]["bottom"].should == 40
|
374
|
+
decrypted["valign"].should == 'middle'
|
375
|
+
decrypted["halign"].should == 'center'
|
376
|
+
decrypted["image_hash"].should == image_md5
|
377
|
+
decrypted["width"].should == 300
|
378
|
+
decrypted["height"].should == 200
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should allow thumbor to decrypt it properly with filters" do
|
383
|
+
url = subject.quality_filter(20).brightness_filter(10).generate
|
384
|
+
|
385
|
+
encrypted = url.split('/')[1]
|
386
|
+
|
387
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
388
|
+
|
389
|
+
decrypted["filters"].should == "quality(20):brightness(10)"
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'ruby-thumbor'
|
4
|
+
require 'util/thumbor'
|
5
|
+
|
6
|
+
image_url = 'my.domain.com/some/image/url.jpg'
|
7
|
+
image_md5 = 'f33af67e41168e80fcc5b00f8bd8061a'
|
8
|
+
key = 'my-security-key'
|
9
|
+
|
10
|
+
describe Thumbor::CryptoURL do
|
11
|
+
subject { Thumbor::CryptoURL.new key }
|
12
|
+
|
13
|
+
describe '#new' do
|
14
|
+
it "should create a new instance passing key and keep it" do
|
15
|
+
subject.computed_key.should == 'my-security-keym'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#url_for' do
|
20
|
+
|
21
|
+
it "should return just the image hash if no arguments passed" do
|
22
|
+
url = subject.url_for :image => image_url
|
23
|
+
url.should == image_md5
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise if no image passed" do
|
27
|
+
expect { subject.url_for Hash.new }.to raise_error(RuntimeError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return proper url for width-only" do
|
31
|
+
url = subject.url_for :image => image_url, :width => 300
|
32
|
+
url.should == '300x0/' << image_md5
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return proper url for height-only" do
|
36
|
+
url = subject.url_for :image => image_url, :height => 300
|
37
|
+
url.should == '0x300/' << image_md5
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return proper url for width and height" do
|
41
|
+
url = subject.url_for :image => image_url, :width => 200, :height => 300
|
42
|
+
url.should == '200x300/' << image_md5
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return proper smart url" do
|
46
|
+
url = subject.url_for :image => image_url, :width => 200, :height => 300, :smart => true
|
47
|
+
url.should == '200x300/smart/' << image_md5
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return proper fit-in url" do
|
51
|
+
url = subject.url_for :image => image_url, :width => 200, :height => 300, :fit_in => true
|
52
|
+
url.should == 'fit-in/200x300/' << image_md5
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return proper flip url if no width and height" do
|
56
|
+
url = subject.url_for :image => image_url, :flip => true
|
57
|
+
url.should == '-0x0/' << image_md5
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return proper flop url if no width and height" do
|
61
|
+
url = subject.url_for :image => image_url, :flop => true
|
62
|
+
url.should == '0x-0/' << image_md5
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return proper flip-flop url if no width and height" do
|
66
|
+
url = subject.url_for :image => image_url, :flip => true, :flop => true
|
67
|
+
url.should == '-0x-0/' << image_md5
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return proper flip url if width" do
|
71
|
+
url = subject.url_for :image => image_url, :width => 300, :flip => true
|
72
|
+
url.should == '-300x0/' << image_md5
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return proper flop url if height" do
|
76
|
+
url = subject.url_for :image => image_url, :height => 300, :flop => true
|
77
|
+
url.should == '0x-300/' << image_md5
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return horizontal align" do
|
81
|
+
url = subject.url_for :image => image_url, :halign => :left
|
82
|
+
url.should == 'left/' << image_md5
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not return horizontal align if it is center" do
|
86
|
+
url = subject.url_for :image => image_url, :halign => :center
|
87
|
+
url.should == image_md5
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return vertical align" do
|
91
|
+
url = subject.url_for :image => image_url, :valign => :top
|
92
|
+
url.should == 'top/' << image_md5
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not return vertical align if it is middle" do
|
96
|
+
url = subject.url_for :image => image_url, :valign => :middle
|
97
|
+
url.should == image_md5
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return halign and valign properly" do
|
101
|
+
url = subject.url_for :image => image_url, :halign => :left, :valign => :top
|
102
|
+
url.should == 'left/top/' << image_md5
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return meta properly" do
|
106
|
+
url = subject.url_for :image => image_url, :meta => true
|
107
|
+
url.should == 'meta/' << image_md5
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return proper crop url" do
|
111
|
+
url = subject.url_for :image => image_url, :crop => [10, 20, 30, 40]
|
112
|
+
url.should == '10x20:30x40/' << image_md5
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should ignore crop if all zeros" do
|
116
|
+
url = subject.url_for :image => image_url, :crop => [0, 0, 0, 0]
|
117
|
+
url.should == image_md5
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have smart after halign and valign" do
|
121
|
+
url = subject.url_for :image => image_url, :halign => :left, :valign => :top, :smart => true
|
122
|
+
url.should == 'left/top/smart/' << image_md5
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should ignore filters if empty" do
|
126
|
+
url = subject.url_for :image => image_url, :filters => []
|
127
|
+
url.should == image_md5
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should have trim without params" do
|
131
|
+
url = subject.url_for :image => image_url, :trim => true
|
132
|
+
url.should == 'trim/' << image_md5
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should have trim with direction param" do
|
136
|
+
url = subject.url_for :image => image_url, :trim => ['bottom-right']
|
137
|
+
url.should == 'trim:bottom-right/' << image_md5
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should have trim with direction and tolerance param" do
|
141
|
+
url = subject.url_for :image => image_url, :trim => ['bottom-right', 15]
|
142
|
+
url.should == 'trim:bottom-right:15/' << image_md5
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#generate' do
|
147
|
+
|
148
|
+
it "should create a new instance passing key and keep it" do
|
149
|
+
url = subject.generate :width => 300, :height => 200, :image => image_url
|
150
|
+
|
151
|
+
url.should == '/TQfyd3H36Z3srcNcLOYiM05YNO8=/300x200/my.domain.com/some/image/url.jpg'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should create a new instance passing key and keep it" do
|
155
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url
|
156
|
+
|
157
|
+
url.should == '/YBQEWd3g_WRMnVEG73zfzcr8Zj0=/meta/300x200/my.domain.com/some/image/url.jpg'
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should create a new instance passing key and keep it" do
|
161
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true
|
162
|
+
|
163
|
+
url.should == '/jP89J0qOWHgPlm_lOA28GtOh5GU=/meta/300x200/smart/my.domain.com/some/image/url.jpg'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should create a new instance passing key and keep it" do
|
167
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true
|
168
|
+
|
169
|
+
url.should == '/zrrOh_TtTs4kiLLEQq1w4bcTYdc=/meta/fit-in/300x200/smart/my.domain.com/some/image/url.jpg'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should create a new instance passing key and keep it" do
|
173
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true, :flip => true
|
174
|
+
|
175
|
+
url.should == '/4t1XK1KH43cOb1QJ9tU00-W2_k8=/meta/fit-in/-300x200/smart/my.domain.com/some/image/url.jpg'
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should create a new instance passing key and keep it" do
|
179
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :fit_in => true, :flip => true, :flop => true
|
180
|
+
|
181
|
+
url.should == '/HJnvjZU69PkPOhyZGu-Z3Uc_W_A=/meta/fit-in/-300x-200/smart/my.domain.com/some/image/url.jpg'
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should create a new instance passing key and keep it" do
|
185
|
+
url = subject.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url
|
186
|
+
|
187
|
+
url.should == '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#generate :old => true" do
|
192
|
+
|
193
|
+
it "should create a new instance passing key and keep it" do
|
194
|
+
url = subject.generate :width => 300, :height => 200, :image => image_url, :old => true
|
195
|
+
|
196
|
+
url.should == '/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should allow thumbor to decrypt it properly" do
|
200
|
+
url = subject.generate :width => 300, :height => 200, :image => image_url, :old => true
|
201
|
+
|
202
|
+
encrypted = url.split('/')[1]
|
203
|
+
|
204
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
205
|
+
|
206
|
+
decrypted["horizontal_flip"].should == false
|
207
|
+
decrypted["vertical_flip"].should == false
|
208
|
+
decrypted["smart"].should == false
|
209
|
+
decrypted["meta"].should == false
|
210
|
+
decrypted["fit_in"].should == false
|
211
|
+
decrypted["crop"]["left"].should == 0
|
212
|
+
decrypted["crop"]["top"].should == 0
|
213
|
+
decrypted["crop"]["right"].should == 0
|
214
|
+
decrypted["crop"]["bottom"].should == 0
|
215
|
+
decrypted["valign"].should == 'middle'
|
216
|
+
decrypted["halign"].should == 'center'
|
217
|
+
decrypted["image_hash"].should == image_md5
|
218
|
+
decrypted["width"].should == 300
|
219
|
+
decrypted["height"].should == 200
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should allow thumbor to decrypt it properly with meta" do
|
224
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :old => true
|
225
|
+
|
226
|
+
encrypted = url.split('/')[1]
|
227
|
+
|
228
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
229
|
+
|
230
|
+
decrypted["meta"].should == true
|
231
|
+
decrypted["image_hash"].should == image_md5
|
232
|
+
decrypted["width"].should == 300
|
233
|
+
decrypted["height"].should == 200
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should allow thumbor to decrypt it properly with smart" do
|
238
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :old => true
|
239
|
+
|
240
|
+
encrypted = url.split('/')[1]
|
241
|
+
|
242
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
243
|
+
|
244
|
+
decrypted["meta"].should == true
|
245
|
+
decrypted["smart"].should == true
|
246
|
+
decrypted["image_hash"].should == image_md5
|
247
|
+
decrypted["width"].should == 300
|
248
|
+
decrypted["height"].should == 200
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should allow thumbor to decrypt it properly with fit-in" do
|
253
|
+
url = subject.generate :width => 300, :height => 200, :fit_in => true, :image => image_url, :old => true
|
254
|
+
|
255
|
+
encrypted = url.split('/')[1]
|
256
|
+
|
257
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
258
|
+
|
259
|
+
decrypted["fit_in"].should == true
|
260
|
+
decrypted["image_hash"].should == image_md5
|
261
|
+
decrypted["width"].should == 300
|
262
|
+
decrypted["height"].should == 200
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should allow thumbor to decrypt it properly with flip" do
|
267
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :old => true
|
268
|
+
|
269
|
+
encrypted = url.split('/')[1]
|
270
|
+
|
271
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
272
|
+
|
273
|
+
decrypted["meta"].should == true
|
274
|
+
decrypted["smart"].should == true
|
275
|
+
decrypted["image_hash"].should == image_md5
|
276
|
+
decrypted["width"].should == 300
|
277
|
+
decrypted["height"].should == 200
|
278
|
+
decrypted["flip_horizontally"] == true
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should allow thumbor to decrypt it properly with flop" do
|
283
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true, :old => true
|
284
|
+
|
285
|
+
encrypted = url.split('/')[1]
|
286
|
+
|
287
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
288
|
+
|
289
|
+
decrypted["meta"].should == true
|
290
|
+
decrypted["smart"].should == true
|
291
|
+
decrypted["image_hash"].should == image_md5
|
292
|
+
decrypted["width"].should == 300
|
293
|
+
decrypted["height"].should == 200
|
294
|
+
decrypted["flip_horizontally"] == true
|
295
|
+
decrypted["flip_vertically"] == true
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should allow thumbor to decrypt it properly with halign" do
|
300
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
301
|
+
:halign => :left, :old => true
|
302
|
+
|
303
|
+
encrypted = url.split('/')[1]
|
304
|
+
|
305
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
306
|
+
|
307
|
+
decrypted["meta"].should == true
|
308
|
+
decrypted["smart"].should == true
|
309
|
+
decrypted["image_hash"].should == image_md5
|
310
|
+
decrypted["width"].should == 300
|
311
|
+
decrypted["height"].should == 200
|
312
|
+
decrypted["flip_horizontally"] == true
|
313
|
+
decrypted["flip_vertically"] == true
|
314
|
+
decrypted["halign"] == "left"
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should allow thumbor to decrypt it properly with valign" do
|
319
|
+
url = subject.generate :width => 300, :height => 200, :meta => true, :image => image_url, :smart => true, :flip => true, :flop => true,
|
320
|
+
:halign => :left, :valign => :top, :old => true
|
321
|
+
|
322
|
+
encrypted = url.split('/')[1]
|
323
|
+
|
324
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
325
|
+
|
326
|
+
decrypted["meta"].should == true
|
327
|
+
decrypted["smart"].should == true
|
328
|
+
decrypted["image_hash"].should == image_md5
|
329
|
+
decrypted["width"].should == 300
|
330
|
+
decrypted["height"].should == 200
|
331
|
+
decrypted["flip_horizontally"] == true
|
332
|
+
decrypted["flip_vertically"] == true
|
333
|
+
decrypted["halign"] == "left"
|
334
|
+
decrypted["valign"] == "top"
|
335
|
+
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should allow thumbor to decrypt it properly with cropping" do
|
339
|
+
url = subject.generate :width => 300, :height => 200, :image => image_url, :crop => [10, 20, 30, 40], :old => true
|
340
|
+
|
341
|
+
encrypted = url.split('/')[1]
|
342
|
+
|
343
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
344
|
+
|
345
|
+
decrypted["horizontal_flip"].should == false
|
346
|
+
decrypted["vertical_flip"].should == false
|
347
|
+
decrypted["smart"].should == false
|
348
|
+
decrypted["meta"].should == false
|
349
|
+
decrypted["crop"]["left"].should == 10
|
350
|
+
decrypted["crop"]["top"].should == 20
|
351
|
+
decrypted["crop"]["right"].should == 30
|
352
|
+
decrypted["crop"]["bottom"].should == 40
|
353
|
+
decrypted["valign"].should == 'middle'
|
354
|
+
decrypted["halign"].should == 'center'
|
355
|
+
decrypted["image_hash"].should == image_md5
|
356
|
+
decrypted["width"].should == 300
|
357
|
+
decrypted["height"].should == 200
|
358
|
+
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should allow thumbor to decrypt it properly with filters" do
|
362
|
+
url = subject.generate :filters => ["quality(20)", "brightness(10)"], :image => image_url, :old => true
|
363
|
+
|
364
|
+
encrypted = url.split('/')[1]
|
365
|
+
|
366
|
+
decrypted = decrypt_in_thumbor(encrypted)
|
367
|
+
|
368
|
+
decrypted["filters"].should == "quality(20):brightness(10)"
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|