ruby-thumbor 1.3.0 → 4.0.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.
@@ -1,512 +1,320 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'json'
3
5
  require 'ruby-thumbor'
4
- require 'util/thumbor'
5
6
 
6
7
  describe Thumbor::Cascade do
7
8
  let(:image_url) { 'my.domain.com/some/image/url.jpg' }
8
- let(:image_md5) { 'f33af67e41168e80fcc5b00f8bd8061a' }
9
9
  let(:key) { 'my-security-key' }
10
10
 
11
- subject { Thumbor::Cascade.new image_url }
12
-
13
- after(:each) do
14
- Thumbor.key = nil
15
- end
16
-
17
- describe '#new' do
18
- before do
19
- Thumbor.key = key
20
- end
21
-
22
- it "should create a new instance passing key and keep it" do
23
- expect(subject.computed_key).to eq 'my-security-keym'
24
- end
25
- end
11
+ subject { Thumbor::Cascade.new key, image_url }
26
12
 
27
13
  it 'should raise an error' do
28
- expect{ subject.god_of_war_crop }.to raise_error(NoMethodError)
14
+ expect { subject.god_of_war_crop }.to raise_error(NoMethodError)
29
15
  end
30
16
 
31
- describe '#url_for' do
32
-
33
- it "should return just the image hash if no arguments passed" do
34
- url = subject.url_for
35
- expect(url).to eq image_md5
36
- end
37
-
38
- it "should raise if no image passed" do
39
- expect { Thumbor::Cascade.new.url_for }.to raise_error(RuntimeError)
40
- end
41
-
42
- it "should return proper url for width-only" do
43
- url = subject.width(300).url_for
44
- expect(url).to eq '300x0/' << image_md5
45
- end
46
-
47
- it "should return proper url for height-only" do
48
- url = subject.height(300).url_for
49
- expect(url).to eq '0x300/' << image_md5
50
- end
51
-
52
- it "should return proper url for width and height" do
53
- url = subject.width(200).height(300).url_for
54
- expect(url).to eq '200x300/' << image_md5
55
- end
56
-
57
- it "should return proper smart url" do
58
- url = subject.width(200).height(300).smart(true).url_for
59
- expect(url).to eq '200x300/smart/' << image_md5
60
- end
61
-
62
- it "should return proper fit-in url" do
63
- url = subject.width(200).height(300).fit_in(true).url_for
64
- expect(url).to eq 'fit-in/200x300/' << image_md5
65
- end
66
-
67
- it "should return proper adaptive-fit-in url" do
68
- url = subject.width(200).height(300).adaptive_fit_in(true).url_for
69
- expect(url).to eq 'adaptive-fit-in/200x300/' << image_md5
70
- end
71
-
72
- it "should return proper full-fit-in url" do
73
- url = subject.width(200).height(300).full_fit_in(true).url_for
74
- expect(url).to eq 'full-fit-in/200x300/' << image_md5
75
- end
76
-
77
- it "should return proper adaptive-full-fit-in url" do
78
- url = subject.width(200).height(300).adaptive_full_fit_in(true).url_for
79
- expect(url).to eq 'adaptive-full-fit-in/200x300/' << image_md5
80
- end
81
-
82
- [:fit_in, :full_fit_in].each do |fit|
83
- it "should raise error when using #{fit} without width or height" do
84
- subject.send(fit, true)
85
- expect{subject.url_for}.to raise_error(ArgumentError)
86
- end
87
- end
17
+ it 'should respond to filter methods' do
18
+ expect(subject.respond_to?('quality_filter')).to be_truthy
19
+ end
88
20
 
89
- it "should return proper flip url if no width and height" do
90
- url = subject.flip(true).url_for
91
- expect(url).to eq '-0x0/' << image_md5
21
+ describe '#generate' do
22
+ it 'should create an unsafe url' do
23
+ url = Thumbor::Cascade.new(nil, image_url).width(300).height(200).generate
24
+ expect(url).to eq '/unsafe/300x200/my.domain.com/some/image/url.jpg'
92
25
  end
93
26
 
94
- it "should return proper flop url if no width and height" do
95
- url = subject.flop(true).url_for
96
- expect(url).to eq '0x-0/' << image_md5
27
+ it 'should create an url with debug' do
28
+ url = subject.debug(true).height(200).generate
29
+ expect(url).to eq '/5_eX4HHQYk81HQVkc1gBIAvPbLo=/debug/0x200/my.domain.com/some/image/url.jpg'
97
30
  end
98
31
 
99
- it "should return proper flip-flop url if no width and height" do
100
- url = subject.flip(true).flop(true).url_for
101
- expect(url).to eq '-0x-0/' << image_md5
32
+ it 'should create a new instance passing key and keep it' do
33
+ url = subject.width(300).height(200).generate
34
+ expect(url).to eq '/TQfyd3H36Z3srcNcLOYiM05YNO8=/300x200/my.domain.com/some/image/url.jpg'
102
35
  end
103
36
 
104
- it "should return proper flip url if width" do
105
- url = subject.width(300).flip(true).url_for
106
- expect(url).to eq '-300x0/' << image_md5
37
+ it 'should be able to change the Thumbor key' do
38
+ url1 = subject.width(300).height(200).generate
39
+ url2 = Thumbor::Cascade.new('another-thumbor-key', image_url).width(300).height(200).generate
40
+ expect(url1).not_to eq url2
107
41
  end
108
42
 
109
- it "should return proper flop url if height" do
110
- url = subject.height(300).flop(true).url_for
111
- expect(url).to eq '0x-300/' << image_md5
43
+ it 'should create a new instance passing key and keep it' do
44
+ url = subject.width(300).height(200).meta(true).generate
45
+ expect(url).to eq '/YBQEWd3g_WRMnVEG73zfzcr8Zj0=/meta/300x200/my.domain.com/some/image/url.jpg'
112
46
  end
113
47
 
114
- it "should return horizontal align" do
115
- url = subject.halign(:left).url_for
116
- expect(url).to eq 'left/' << image_md5
48
+ it 'should create a new instance passing key and keep it' do
49
+ url = subject.width(300).height(200).meta(true).smart(true).generate
50
+ expect(url).to eq '/jP89J0qOWHgPlm_lOA28GtOh5GU=/meta/300x200/smart/my.domain.com/some/image/url.jpg'
117
51
  end
118
52
 
119
- it "should not return horizontal align if it is center" do
120
- url = subject.halign(:center).url_for
121
- expect(url).to eq image_md5
53
+ it 'should create a new instance passing key and keep it' do
54
+ url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).generate
55
+ expect(url).to eq '/zrrOh_TtTs4kiLLEQq1w4bcTYdc=/meta/fit-in/300x200/smart/my.domain.com/some/image/url.jpg'
122
56
  end
123
57
 
124
- it "should return vertical align" do
125
- url = subject.valign(:top).url_for
126
- expect(url).to eq 'top/' << image_md5
58
+ it 'should create a new instance passing key and keep it' do
59
+ url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).generate
60
+ expect(url).to eq '/4t1XK1KH43cOb1QJ9tU00-W2_k8=/meta/fit-in/-300x200/smart/my.domain.com/some/image/url.jpg'
127
61
  end
128
62
 
129
- it "should not return vertical align if it is middle" do
130
- url = subject.valign(:middle).url_for
131
- expect(url).to eq image_md5
63
+ it 'should create a new instance passing key and keep it' do
64
+ url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).flop(true).generate
65
+ expect(url).to eq '/HJnvjZU69PkPOhyZGu-Z3Uc_W_A=/meta/fit-in/-300x-200/smart/my.domain.com/some/image/url.jpg'
132
66
  end
133
67
 
134
- it "should return halign and valign properly" do
135
- url = subject.halign(:left).valign(:top).url_for
136
- expect(url).to eq 'left/top/' << image_md5
68
+ it 'should create a new instance passing key and keep it' do
69
+ url = subject.quality_filter(20).brightness_filter(10).generate
70
+ expect(url).to eq '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg'
137
71
  end
138
72
 
139
- it "should return meta properly" do
140
- url = subject.meta(true).url_for
141
- expect(url).to eq 'meta/' << image_md5
73
+ it 'should return just the image hash if no arguments passed' do
74
+ url = subject.generate
75
+ expect(url).to eq '/964rCTkAEDtvjy_a572k7kRa0SU=/my.domain.com/some/image/url.jpg'
142
76
  end
143
77
 
144
- it "should return proper crop url when param is array" do
145
- url = subject.crop([10, 20, 30, 40]).url_for
146
- expect(url).to eq '10x20:30x40/' << image_md5
78
+ it 'should raise if no image passed' do
79
+ expect { Thumbor::Cascade.new.generate }.to raise_error(RuntimeError)
147
80
  end
148
81
 
149
- it "should return proper crop url" do
150
- url = subject.crop(10, 20, 30, 40).url_for
151
- expect(url).to eq '10x20:30x40/' << image_md5
82
+ it 'should return proper url for width-only' do
83
+ url = subject.width(300).generate
84
+ expect(url).to eq '/eFwrBWryxtRw9hDSbQPhi5iLpo8=/300x0/my.domain.com/some/image/url.jpg'
152
85
  end
153
86
 
154
- it "should ignore crop if all zeros" do
155
- url = subject.crop(0, 0, 0, 0).url_for
156
- expect(url).to eq image_md5
87
+ it 'should return proper url for height-only' do
88
+ url = subject.height(300).generate
89
+ expect(url).to eq '/-VGIgp7g8cMKcfF2gFK9ZpmB_5w=/0x300/my.domain.com/some/image/url.jpg'
157
90
  end
158
91
 
159
- it "should have smart after halign and valign" do
160
- url = subject.halign(:left).valign(:top).smart(true).url_for
161
- expect(url).to eq 'left/top/smart/' << image_md5
92
+ it 'should return proper url for width and height' do
93
+ url = subject.width(200).height(300).generate
94
+ expect(url).to eq '/TrM0qqfcivb6VxS3Hxlxn43W21k=/200x300/my.domain.com/some/image/url.jpg'
162
95
  end
163
96
 
164
- it "should have quality filter" do
165
- url = subject.quality_filter(20).url_for
166
- expect(url).to eq 'filters:quality(20)/' << image_md5
97
+ it 'should return proper smart url' do
98
+ url = subject.width(200).height(300).smart(true).generate
99
+ expect(url).to eq '/hdzhxXzK45DzNTru5urV6x6xxSs=/200x300/smart/my.domain.com/some/image/url.jpg'
167
100
  end
168
101
 
169
- it "should have brightness filter" do
170
- url = subject.brightness_filter(30).url_for
171
- expect(url).to eq 'filters:brightness(30)/' << image_md5
102
+ it 'should return proper fit-in url' do
103
+ url = subject.width(200).height(300).fit_in(true).generate
104
+ expect(url).to eq '/LOv6ArMOJA2VRpfMQjjs4xSyZpM=/fit-in/200x300/my.domain.com/some/image/url.jpg'
172
105
  end
173
106
 
174
- it "should have 2 filters" do
175
- url = subject.brightness_filter(30).quality_filter(20).url_for
176
- expect(url).to eq 'filters:brightness(30):quality(20)/' << image_md5
107
+ it 'should return proper adaptive-fit-in url' do
108
+ url = subject.width(200).height(300).adaptive_fit_in(true).generate
109
+ expect(url).to eq '/V2xmSmQZm4i5-0Flx8iuRtawOkg=/adaptive-fit-in/200x300/my.domain.com/some/image/url.jpg'
177
110
  end
178
111
 
179
- it "should escape url args" do
180
- url = subject.watermark_filter('http://my-server.com/image.png', 30).quality_filter(20).url_for
181
- expect(url).to eq 'filters:watermark(http%3A%2F%2Fmy-server.com%2Fimage.png,30):quality(20)/' << image_md5
112
+ it 'should return proper full-fit-in url' do
113
+ url = subject.width(200).height(300).full_fit_in(true).generate
114
+ expect(url).to eq '/geXhR7ZFxztQTsKzmkDxYCX-HHg=/full-fit-in/200x300/my.domain.com/some/image/url.jpg'
182
115
  end
183
116
 
184
- it "should have trim without params" do
185
- url = subject.trim.url_for
186
- expect(url).to eq 'trim/' << image_md5
117
+ it 'should return proper adaptive-full-fit-in url' do
118
+ url = subject.width(200).height(300).adaptive_full_fit_in(true).generate
119
+ expect(url).to eq '/jlUfjdC-6rG6jmuHgFp6eKgPy2g=/adaptive-full-fit-in/200x300/my.domain.com/some/image/url.jpg'
187
120
  end
188
121
 
189
- it "should have trim with direction param" do
190
- url = subject.trim('bottom-right').url_for
191
- expect(url).to eq 'trim:bottom-right/' << image_md5
122
+ %i[fit_in full_fit_in].each do |fit|
123
+ it "should raise error when using #{fit} without width or height" do
124
+ subject.send(fit, true)
125
+ expect { subject.generate }.to raise_error(ArgumentError)
126
+ end
192
127
  end
193
128
 
194
- it "should have trim with direction and tolerance param" do
195
- url = subject.trim('bottom-right', 15).url_for
196
- expect(url).to eq 'trim:bottom-right:15/' << image_md5
129
+ it 'should return proper flip url if no width and height' do
130
+ url = subject.flip(true).generate
131
+ expect(url).to eq '/rlI4clPR-p-PR2QAxj5ZWiTfvH4=/-0x0/my.domain.com/some/image/url.jpg'
197
132
  end
198
133
 
199
- it "should have the right crop when cropping horizontally and given a left center" do
200
- url = subject.original_width(100).original_height(100).width(40).height(50).center(0, 50).url_for
201
- expect(url).to eq '0x0:80x100/40x50/' << image_md5
134
+ it 'should return proper flop url if no width and height' do
135
+ url = subject.flop(true).generate
136
+ expect(url).to eq '/-4dmGj-TwIEqTAL9_9yEqUM8cks=/0x-0/my.domain.com/some/image/url.jpg'
202
137
  end
203
138
 
204
- it "should have the right crop when cropping horizontally and given a right center" do
205
- url = subject.original_width(100).original_height(100).width(40).height(50).center(100, 50).url_for
206
- expect(url).to eq '20x0:100x100/40x50/' << image_md5
139
+ it 'should return proper flip-flop url if no width and height' do
140
+ url = subject.flip(true).flop(true).generate
141
+ expect(url).to eq '/FnMxpQMmxiMpdG219Dsj8pD_4Xc=/-0x-0/my.domain.com/some/image/url.jpg'
207
142
  end
208
143
 
209
- it "should have the right crop when cropping horizontally and given the actual center" do
210
- url = subject.original_width(100).original_height(100).width(40).height(50).center(50, 50).url_for
211
- expect(url).to eq '10x0:90x100/40x50/' << image_md5
144
+ it 'should return proper flip url if width' do
145
+ url = subject.width(300).flip(true).generate
146
+ expect(url).to eq '/ccr2PoSYcTEGL4_Wzt4u3wWVRKU=/-300x0/my.domain.com/some/image/url.jpg'
212
147
  end
213
148
 
214
- it "should have the right crop when cropping vertically and given a top center" do
215
- url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 0).url_for
216
- expect(url).to eq '0x0:100x80/50x40/' << image_md5
149
+ it 'should return proper flop url if height' do
150
+ url = subject.height(300).flop(true).generate
151
+ expect(url).to eq '/R5K91tkyNgXO65F6E0txgA6C9lY=/0x-300/my.domain.com/some/image/url.jpg'
217
152
  end
218
153
 
219
- it "should have the right crop when cropping vertically and given a bottom center" do
220
- url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 100).url_for
221
- expect(url).to eq '0x20:100x100/50x40/' << image_md5
154
+ it 'should return horizontal align' do
155
+ url = subject.halign(:left).generate
156
+ expect(url).to eq '/GTJE3wUt3sURik0O9Nae8sfI928=/left/my.domain.com/some/image/url.jpg'
222
157
  end
223
158
 
224
- it "should have the right crop when cropping vertically and given the actual center" do
225
- url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 50).url_for
226
- expect(url).to eq '0x10:100x90/50x40/' << image_md5
159
+ it 'should not return horizontal align if it is center' do
160
+ url = subject.halign(:center).generate
161
+ expect(url).to eq '/964rCTkAEDtvjy_a572k7kRa0SU=/my.domain.com/some/image/url.jpg'
227
162
  end
228
163
 
229
- it "should have the no crop when not necessary" do
230
- url = subject.original_width(100).original_height(100).width(50).height(50).center(50, 0).url_for
231
- expect(url).to eq '50x50/' << image_md5
164
+ it 'should return vertical align' do
165
+ url = subject.valign(:top).generate
166
+ expect(url).to eq '/1QQo5ihObuhgwl95--Z3g78vjiE=/top/my.domain.com/some/image/url.jpg'
232
167
  end
233
168
 
234
- it "should blow up with a bad center" do
235
- expect { subject.original_width(100).original_height(100).width(50).height(50).center(50).url_for }.to raise_error(RuntimeError)
169
+ it 'should not return vertical align if it is middle' do
170
+ url = subject.valign(:middle).generate
171
+ expect(url).to eq '/964rCTkAEDtvjy_a572k7kRa0SU=/my.domain.com/some/image/url.jpg'
236
172
  end
237
173
 
238
- it "should have no crop with a missing original_height" do
239
- url = subject.original_width(100).width(50).height(40).center(50, 0).url_for
240
- expect(url).to eq '50x40/' << image_md5
174
+ it 'should return halign and valign properly' do
175
+ url = subject.halign(:left).valign(:top).generate
176
+ expect(url).to eq '/yA2rmtWv_uzHd9klz5OuMIZ5auI=/left/top/my.domain.com/some/image/url.jpg'
241
177
  end
242
178
 
243
- it "should have no crop with a missing original_width" do
244
- url = subject.original_height(100).width(50).height(40).center(50, 0).url_for
245
- expect(url).to eq '50x40/' << image_md5
179
+ it 'should return meta properly' do
180
+ url = subject.meta(true).generate
181
+ expect(url).to eq '/WvIJFDJDePgIl5hZcLgtrzIPxfY=/meta/my.domain.com/some/image/url.jpg'
246
182
  end
247
183
 
248
- it "should have no crop with out a width and height" do
249
- url = subject.original_width(100).original_height(100).center(50, 50).url_for
250
- expect(url).to eq image_md5
184
+ it 'should return proper crop url when param is array' do
185
+ url = subject.crop([10, 20, 30, 40]).generate
186
+ expect(url).to eq '/QcnhqNfHwiP6BHLbD6UvneX7K28=/10x20:30x40/my.domain.com/some/image/url.jpg'
251
187
  end
252
188
 
253
- it "should use the original width with a missing width" do
254
- url = subject.original_width(100).original_height(100).height(80).center(50, 50).url_for
255
- expect(url).to eq '0x10:100x90/0x80/' << image_md5
189
+ it 'should return proper crop url' do
190
+ url = subject.crop(10, 20, 30, 40).generate
191
+ expect(url).to eq '/QcnhqNfHwiP6BHLbD6UvneX7K28=/10x20:30x40/my.domain.com/some/image/url.jpg'
256
192
  end
257
193
 
258
- it "should use the original height with a missing height" do
259
- url = subject.original_width(100).original_height(100).width(80).center(50, 50).url_for
260
- expect(url).to eq '10x0:90x100/80x0/' << image_md5
194
+ it 'should ignore crop if all zeros' do
195
+ url = subject.crop(0, 0, 0, 0).generate
196
+ expect(url).to eq '/964rCTkAEDtvjy_a572k7kRa0SU=/my.domain.com/some/image/url.jpg'
261
197
  end
262
198
 
263
- it "should have the right crop with a negative width" do
264
- url = subject.original_width(100).original_height(100).width(-50).height(40).center(50, 50).url_for
265
- expect(url).to eq '0x10:100x90/-50x40/' << image_md5
199
+ it 'should have smart after halign and valign' do
200
+ url = subject.halign(:left).valign(:top).smart(true).generate
201
+ expect(url).to eq '/KS6mVuzlGE3hJ75n3JUonfGgSFM=/left/top/smart/my.domain.com/some/image/url.jpg'
266
202
  end
267
203
 
268
- it "should have the right crop with a negative height" do
269
- url = subject.original_width(100).original_height(100).width(50).height(-40).center(50, 50).url_for
270
- expect(url).to eq '0x10:100x90/50x-40/' << image_md5
204
+ it 'should have quality filter' do
205
+ url = subject.quality_filter(20).generate
206
+ expect(url).to eq '/NyA-is4NojxiRqo0NcmJDhB6GTs=/filters:quality(20)/my.domain.com/some/image/url.jpg'
271
207
  end
272
208
 
273
- it "should have the right crop with a negative height and width" do
274
- url = subject.original_width(100).original_height(100).width(-50).height(-40).center(50, 50).url_for
275
- expect(url).to eq '0x10:100x90/-50x-40/' << image_md5
209
+ it 'should have brightness filter' do
210
+ url = subject.brightness_filter(30).generate
211
+ expect(url).to eq '/oXDmnGD7vQV-rXcj8kCl1tcS3jc=/filters:brightness(30)/my.domain.com/some/image/url.jpg'
276
212
  end
277
- end
278
213
 
279
- describe '#generate' do
280
- before do
281
- Thumbor.key = key
214
+ it 'should have 2 filters' do
215
+ url = subject.brightness_filter(30).quality_filter(20).generate
216
+ expect(url).to eq '/SW9o4xQG1QAzE69WzEzarL_G3MI=/filters:brightness(30):quality(20)/my.domain.com/some/image/url.jpg'
282
217
  end
283
218
 
284
- it "should create a new instance passing key and keep it" do
285
- url = subject.width(300).height(200).generate
286
- expect(url).to eq '/TQfyd3H36Z3srcNcLOYiM05YNO8=/300x200/my.domain.com/some/image/url.jpg'
219
+ it 'should escape url args' do
220
+ url = subject.watermark_filter('http://my-server.com/image.png', 30).quality_filter(20).generate
221
+ expect(url).to eq '/4b9kwg0-zsojf7Ed01TPKPYOel4=/filters:watermark(http%3A%2F%2Fmy-server.com%2Fimage.png,30):quality(20)/my.domain.com/some/image/url.jpg'
287
222
  end
288
223
 
289
- it "should be able to change the Thumbor key" do
290
- thumbor = subject.width(300).height(200)
291
- url1 = thumbor.generate
292
- Thumbor.key = 'another-thumbor-key'
293
- url2 = thumbor.generate
294
- expect(url1).not_to eq url2
224
+ it 'should have trim without params' do
225
+ url = subject.trim.generate
226
+ expect(url).to eq '/w23BC0dUiYBFrUnuoYJe8XROuyw=/trim/my.domain.com/some/image/url.jpg'
295
227
  end
296
228
 
297
- it "should create a new instance passing key and keep it" do
298
- url = subject.width(300).height(200).meta(true).generate
299
- expect(url).to eq '/YBQEWd3g_WRMnVEG73zfzcr8Zj0=/meta/300x200/my.domain.com/some/image/url.jpg'
229
+ it 'should have trim with direction param' do
230
+ url = subject.trim('bottom-right').generate
231
+ expect(url).to eq '/kXPwSmqEvPFQezgzBCv9BtPWmBY=/trim:bottom-right/my.domain.com/some/image/url.jpg'
300
232
  end
301
233
 
302
- it "should create a new instance passing key and keep it" do
303
- url = subject.width(300).height(200).meta(true).smart(true).generate
304
- expect(url).to eq '/jP89J0qOWHgPlm_lOA28GtOh5GU=/meta/300x200/smart/my.domain.com/some/image/url.jpg'
234
+ it 'should have trim with direction and tolerance param' do
235
+ url = subject.trim('bottom-right', 15).generate
236
+ expect(url).to eq '/TUCEIhtWfI1Uv9zjavCSl_i0A_8=/trim:bottom-right:15/my.domain.com/some/image/url.jpg'
305
237
  end
306
238
 
307
- it "should create a new instance passing key and keep it" do
308
- url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).generate
309
- expect(url).to eq '/zrrOh_TtTs4kiLLEQq1w4bcTYdc=/meta/fit-in/300x200/smart/my.domain.com/some/image/url.jpg'
239
+ it 'should have the right crop when cropping horizontally and given a left center' do
240
+ url = subject.original_width(100).original_height(100).width(40).height(50).center(0, 50).generate
241
+ expect(url).to eq '/SZIT3w4Qgebv5DuVJ8G1IH1mkCU=/0x0:80x100/40x50/my.domain.com/some/image/url.jpg'
310
242
  end
311
243
 
312
- it "should create a new instance passing key and keep it" do
313
- url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).generate
314
- expect(url).to eq '/4t1XK1KH43cOb1QJ9tU00-W2_k8=/meta/fit-in/-300x200/smart/my.domain.com/some/image/url.jpg'
244
+ it 'should have the right crop when cropping horizontally and given a right center' do
245
+ url = subject.original_width(100).original_height(100).width(40).height(50).center(100, 50).generate
246
+ expect(url).to eq '/NEtCYehaISE7qR3zFj15CxnZoCs=/20x0:100x100/40x50/my.domain.com/some/image/url.jpg'
315
247
  end
316
248
 
317
- it "should create a new instance passing key and keep it" do
318
- url = subject.width(300).height(200).meta(true).smart(true).fit_in(true).flip(true).flop(true).generate
319
- expect(url).to eq '/HJnvjZU69PkPOhyZGu-Z3Uc_W_A=/meta/fit-in/-300x-200/smart/my.domain.com/some/image/url.jpg'
249
+ it 'should have the right crop when cropping horizontally and given the actual center' do
250
+ url = subject.original_width(100).original_height(100).width(40).height(50).center(50, 50).generate
251
+ expect(url).to eq '/JLH65vJTu6d-cXBmqe5hYoSD4ho=/10x0:90x100/40x50/my.domain.com/some/image/url.jpg'
320
252
  end
321
253
 
322
- it "should create a new instance passing key and keep it" do
323
- url = subject.quality_filter(20).brightness_filter(10).generate
324
- expect(url).to eq '/q0DiFg-5-eFZIqyN3lRoCvg2K0s=/filters:quality(20):brightness(10)/my.domain.com/some/image/url.jpg'
254
+ it 'should have the right crop when cropping vertically and given a top center' do
255
+ url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 0).generate
256
+ expect(url).to eq '/FIMZcLatW6bjgSRH9xTkEwUZAZ8=/0x0:100x80/50x40/my.domain.com/some/image/url.jpg'
325
257
  end
326
- end
327
258
 
328
- describe "#generate :old => true" do
329
- before do
330
- Thumbor.key = key
259
+ it 'should have the right crop when cropping vertically and given a bottom center' do
260
+ url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 100).generate
261
+ expect(url).to eq '/9Ud0sVo6i9DLOjlKbQP_4JXgFmA=/0x20:100x100/50x40/my.domain.com/some/image/url.jpg'
331
262
  end
332
263
 
333
- subject { Thumbor::Cascade.new(image_url).old(true) }
334
-
335
- it "should create a new instance passing key and keep it" do
336
- url = subject.width(300).height(200).generate
337
- expect(url).to eq '/qkLDiIbvtiks0Up9n5PACtmpOfX6dPXw4vP4kJU-jTfyF6y1GJBJyp7CHYh1H3R2/' << image_url
264
+ it 'should have the right crop when cropping vertically and given the actual center' do
265
+ url = subject.original_width(100).original_height(100).width(50).height(40).center(50, 50).generate
266
+ expect(url).to eq '/WejLJn8djJLn7DkMUq3S0zZCvZE=/0x10:100x90/50x40/my.domain.com/some/image/url.jpg'
338
267
  end
339
268
 
340
- it "should allow thumbor to decrypt it properly" do
341
- url = subject.width(300).height(200).generate
342
-
343
- encrypted = url.split('/')[1]
344
-
345
- decrypted = decrypt_in_thumbor(encrypted)
346
-
347
- expect(decrypted["horizontal_flip"]).to eq false
348
- expect(decrypted["vertical_flip"]).to eq false
349
- expect(decrypted["smart"]).to eq false
350
- expect(decrypted["meta"]).to eq false
351
- expect(decrypted["fit_in"]).to eq false
352
- expect(decrypted["crop"]["left"]).to eq 0
353
- expect(decrypted["crop"]["top"]).to eq 0
354
- expect(decrypted["crop"]["right"]).to eq 0
355
- expect(decrypted["crop"]["bottom"]).to eq 0
356
- expect(decrypted["valign"]).to eq 'middle'
357
- expect(decrypted["halign"]).to eq 'center'
358
- expect(decrypted["image_hash"]).to eq image_md5
359
- expect(decrypted["width"]).to eq 300
360
- expect(decrypted["height"]).to eq 200
361
-
269
+ it 'should have the no crop when not necessary' do
270
+ url = subject.original_width(100).original_height(100).width(50).height(50).center(50, 0).generate
271
+ expect(url).to eq '/trIjfr513nkGkCpKXK6qgox2jPA=/50x50/my.domain.com/some/image/url.jpg'
362
272
  end
363
273
 
364
- it "should allow thumbor to decrypt it properly with meta" do
365
- url = subject.width(300).height(200).meta(true).generate
366
-
367
- encrypted = url.split('/')[1]
368
-
369
- decrypted = decrypt_in_thumbor(encrypted)
370
-
371
- expect(decrypted["meta"]).to eq true
372
- expect(decrypted["image_hash"]).to eq image_md5
373
- expect(decrypted["width"]).to eq 300
374
- expect(decrypted["height"]).to eq 200
375
-
274
+ it 'should blow up with a bad center' do
275
+ expect do
276
+ subject.original_width(100).original_height(100).width(50).height(50).center(50).generate
277
+ end.to raise_error(RuntimeError)
376
278
  end
377
279
 
378
- it "should allow thumbor to decrypt it properly with smart" do
379
- url = subject.width(300).height(200).meta(true).smart(true).generate
380
-
381
- encrypted = url.split('/')[1]
382
-
383
- decrypted = decrypt_in_thumbor(encrypted)
384
-
385
- expect(decrypted["meta"]).to eq true
386
- expect(decrypted["smart"]).to eq true
387
- expect(decrypted["image_hash"]).to eq image_md5
388
- expect(decrypted["width"]).to eq 300
389
- expect(decrypted["height"]).to eq 200
390
-
280
+ it 'should have no crop with a missing original_height' do
281
+ url = subject.original_width(100).width(50).height(40).center(50, 0).generate
282
+ expect(url).to eq '/veYlY0msKmemAaXpeav2kCNftmU=/50x40/my.domain.com/some/image/url.jpg'
391
283
  end
392
284
 
393
- it "should allow thumbor to decrypt it properly with fit-in" do
394
- url = subject.width(300).height(200).fit_in(true).generate
395
-
396
- encrypted = url.split('/')[1]
397
-
398
- decrypted = decrypt_in_thumbor(encrypted)
399
-
400
- expect(decrypted["fit_in"]).to eq true
401
- expect(decrypted["image_hash"]).to eq image_md5
402
- expect(decrypted["width"]).to eq 300
403
- expect(decrypted["height"]).to eq 200
404
-
285
+ it 'should have no crop with a missing original_width' do
286
+ url = subject.original_height(100).width(50).height(40).center(50, 0).generate
287
+ expect(url).to eq '/veYlY0msKmemAaXpeav2kCNftmU=/50x40/my.domain.com/some/image/url.jpg'
405
288
  end
406
289
 
407
- it "should allow thumbor to decrypt it properly with flip" do
408
- url = subject.width(300).height(200).meta(true).smart(true).flip(true).generate
409
-
410
- encrypted = url.split('/')[1]
411
-
412
- decrypted = decrypt_in_thumbor(encrypted)
413
-
414
- expect(decrypted["meta"]).to eq true
415
- expect(decrypted["smart"]).to eq true
416
- expect(decrypted["image_hash"]).to eq image_md5
417
- expect(decrypted["width"]).to eq 300
418
- expect(decrypted["height"]).to eq 200
419
- expect(decrypted["horizontal_flip"]).to eq true
420
-
290
+ it 'should have no crop with out a width and height' do
291
+ url = subject.original_width(100).original_height(100).center(50, 50).generate
292
+ expect(url).to eq '/964rCTkAEDtvjy_a572k7kRa0SU=/my.domain.com/some/image/url.jpg'
421
293
  end
422
294
 
423
- it "should allow thumbor to decrypt it properly with flop" do
424
- url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).generate
425
-
426
- encrypted = url.split('/')[1]
427
-
428
- decrypted = decrypt_in_thumbor(encrypted)
429
-
430
- expect(decrypted["meta"]).to eq true
431
- expect(decrypted["smart"]).to eq true
432
- expect(decrypted["image_hash"]).to eq image_md5
433
- expect(decrypted["width"]).to eq 300
434
- expect(decrypted["height"]).to eq 200
435
- expect(decrypted["horizontal_flip"]).to eq true
436
- expect(decrypted["vertical_flip"]).to eq true
437
-
295
+ it 'should use the original width with a missing width' do
296
+ url = subject.original_width(100).original_height(100).height(80).center(50, 50).generate
297
+ expect(url).to eq '/02BNIIJ9NYNV9Q03JHPtlP0DIDg=/0x10:100x90/0x80/my.domain.com/some/image/url.jpg'
438
298
  end
439
299
 
440
- it "should allow thumbor to decrypt it properly with halign" do
441
- url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).
442
- halign(:left).generate
443
-
444
- encrypted = url.split('/')[1]
445
-
446
- decrypted = decrypt_in_thumbor(encrypted)
447
-
448
- expect(decrypted["meta"]).to eq true
449
- expect(decrypted["smart"]).to eq true
450
- expect(decrypted["image_hash"]).to eq image_md5
451
- expect(decrypted["width"]).to eq 300
452
- expect(decrypted["height"]).to eq 200
453
- expect(decrypted["horizontal_flip"]).to eq true
454
- expect(decrypted["vertical_flip"]).to eq true
455
- expect(decrypted["halign"]).to eq "left"
456
-
300
+ it 'should use the original height with a missing height' do
301
+ url = subject.original_width(100).original_height(100).width(80).center(50, 50).generate
302
+ expect(url).to eq '/0XL5BmMi3vlJQfw6aGOVW-M1vVI=/10x0:90x100/80x0/my.domain.com/some/image/url.jpg'
457
303
  end
458
304
 
459
- it "should allow thumbor to decrypt it properly with valign" do
460
- url = subject.width(300).height(200).meta(true).smart(true).flip(true).flop(true).
461
- halign(:left).valign(:top).generate
462
-
463
- encrypted = url.split('/')[1]
464
-
465
- decrypted = decrypt_in_thumbor(encrypted)
466
-
467
- expect(decrypted["meta"]).to eq true
468
- expect(decrypted["smart"]).to eq true
469
- expect(decrypted["image_hash"]).to eq image_md5
470
- expect(decrypted["width"]).to eq 300
471
- expect(decrypted["height"]).to eq 200
472
- expect(decrypted["horizontal_flip"]).to eq true
473
- expect(decrypted["vertical_flip"]).to eq true
474
- expect(decrypted["halign"]).to eq "left"
475
- expect(decrypted["valign"]).to eq "top"
476
-
305
+ it 'should have the right crop with a negative width' do
306
+ url = subject.original_width(100).original_height(100).width(-50).height(40).center(50, 50).generate
307
+ expect(url).to eq '/IuRNPlFlpTVol45bDkOm2PGvneo=/0x10:100x90/-50x40/my.domain.com/some/image/url.jpg'
477
308
  end
478
309
 
479
- it "should allow thumbor to decrypt it properly with cropping" do
480
- url = subject.width(300).height(200).crop([10, 20, 30, 40]).generate
481
-
482
- encrypted = url.split('/')[1]
483
-
484
- decrypted = decrypt_in_thumbor(encrypted)
485
-
486
- expect(decrypted["horizontal_flip"]).to eq false
487
- expect(decrypted["vertical_flip"]).to eq false
488
- expect(decrypted["smart"]).to eq false
489
- expect(decrypted["meta"]).to eq false
490
- expect(decrypted["crop"]["left"]).to eq 10
491
- expect(decrypted["crop"]["top"]).to eq 20
492
- expect(decrypted["crop"]["right"]).to eq 30
493
- expect(decrypted["crop"]["bottom"]).to eq 40
494
- expect(decrypted["valign"]).to eq 'middle'
495
- expect(decrypted["halign"]).to eq 'center'
496
- expect(decrypted["image_hash"]).to eq image_md5
497
- expect(decrypted["width"]).to eq 300
498
- expect(decrypted["height"]).to eq 200
499
-
310
+ it 'should have the right crop with a negative height' do
311
+ url = subject.original_width(100).original_height(100).width(50).height(-40).center(50, 50).generate
312
+ expect(url).to eq '/-8IhWGEeXaY1uv945i9EHLVjwuk=/0x10:100x90/50x-40/my.domain.com/some/image/url.jpg'
500
313
  end
501
314
 
502
- it "should allow thumbor to decrypt it properly with filters" do
503
- url = subject.quality_filter(20).brightness_filter(10).generate
504
-
505
- encrypted = url.split('/')[1]
506
-
507
- decrypted = decrypt_in_thumbor(encrypted)
508
-
509
- expect(decrypted["filters"]).to eq "quality(20):brightness(10)"
315
+ it 'should have the right crop with a negative height and width' do
316
+ url = subject.original_width(100).original_height(100).width(-50).height(-40).center(50, 50).generate
317
+ expect(url).to eq '/lfjGLTTEaW_Rcvc1q0ZhfYup2jg=/0x10:100x90/-50x-40/my.domain.com/some/image/url.jpg'
510
318
  end
511
319
  end
512
320
  end