cloudinary 1.11.1 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  4. data/.github/pull_request_template.md +24 -0
  5. data/.gitignore +6 -1
  6. data/.travis.yml +15 -5
  7. data/CHANGELOG.md +149 -0
  8. data/Rakefile +3 -45
  9. data/cloudinary.gemspec +20 -4
  10. data/lib/active_storage/blob_key.rb +20 -0
  11. data/lib/active_storage/service/cloudinary_service.rb +229 -0
  12. data/lib/cloudinary.rb +31 -22
  13. data/lib/cloudinary/api.rb +173 -5
  14. data/lib/cloudinary/auth_token.rb +6 -4
  15. data/lib/cloudinary/carrier_wave.rb +3 -1
  16. data/lib/cloudinary/carrier_wave/remote.rb +3 -2
  17. data/lib/cloudinary/carrier_wave/storage.rb +2 -1
  18. data/lib/cloudinary/cloudinary_controller.rb +2 -4
  19. data/lib/cloudinary/helper.rb +30 -3
  20. data/lib/cloudinary/railtie.rb +7 -3
  21. data/lib/cloudinary/uploader.rb +35 -6
  22. data/lib/cloudinary/utils.rb +112 -40
  23. data/lib/cloudinary/version.rb +1 -1
  24. data/lib/cloudinary/video_helper.rb +96 -22
  25. data/lib/tasks/cloudinary/fetch_assets.rake +48 -0
  26. data/lib/tasks/{cloudinary.rake → cloudinary/sync_static.rake} +0 -0
  27. data/tools/allocate_test_cloud.sh +9 -0
  28. data/tools/get_test_cloud.sh +9 -0
  29. data/tools/update_version +29 -11
  30. data/vendor/assets/javascripts/cloudinary/jquery.cloudinary.js +48 -14
  31. data/vendor/assets/javascripts/cloudinary/jquery.fileupload.js +24 -4
  32. data/vendor/assets/javascripts/cloudinary/jquery.ui.widget.js +741 -561
  33. data/vendor/assets/javascripts/cloudinary/load-image.all.min.js +1 -1
  34. metadata +62 -67
  35. data/spec/access_control_spec.rb +0 -102
  36. data/spec/api_spec.rb +0 -567
  37. data/spec/archive_spec.rb +0 -129
  38. data/spec/auth_token_spec.rb +0 -77
  39. data/spec/cache_spec.rb +0 -109
  40. data/spec/cloudinary_helper_spec.rb +0 -325
  41. data/spec/cloudinary_spec.rb +0 -32
  42. data/spec/data/sync_static/app/assets/javascripts/1.coffee +0 -1
  43. data/spec/data/sync_static/app/assets/javascripts/1.js +0 -1
  44. data/spec/data/sync_static/app/assets/stylesheets/1.css +0 -3
  45. data/spec/docx.docx +0 -0
  46. data/spec/favicon.ico +0 -0
  47. data/spec/image_spec.rb +0 -107
  48. data/spec/logo.png +0 -0
  49. data/spec/rake_spec.rb +0 -160
  50. data/spec/sample_asset_file.tsv +0 -4
  51. data/spec/search_spec.rb +0 -109
  52. data/spec/spec_helper.rb +0 -266
  53. data/spec/storage_spec.rb +0 -44
  54. data/spec/streaminig_profiles_api_spec.rb +0 -74
  55. data/spec/support/helpers/temp_file_helpers.rb +0 -22
  56. data/spec/support/shared_contexts/rake.rb +0 -19
  57. data/spec/uploader_spec.rb +0 -392
  58. data/spec/utils_methods_spec.rb +0 -54
  59. data/spec/utils_spec.rb +0 -970
  60. data/spec/video_tag_spec.rb +0 -253
  61. data/spec/video_url_spec.rb +0 -185
@@ -1,54 +0,0 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require 'cloudinary'
4
-
5
- include Cloudinary
6
-
7
- describe Utils do
8
-
9
- it 'should parse integer range values' do
10
- expect(Utils.instance_eval { norm_range_value("200") }).to eq("200")
11
- end
12
- it "should parse float range values" do
13
- expect(Utils.instance_eval { norm_range_value("200.0") }).to eq("200.0"), "parse a float"
14
- end
15
- it "should parse a percent range value" do
16
- expect(Utils.instance_eval { norm_range_value("20p") }).to eq("20p")
17
- end
18
- describe "json_array_param" do
19
- let (:data) {{:one => 1, :two => 2, "three" => 3}}
20
- let (:data_s) {"{\"one\":1,\"two\":2,\"three\":3}"}
21
- let (:data2) {{:foo => "bar"}}
22
- let (:data2_s) {"{\"foo\":\"bar\"}"}
23
- it "should convert a hash to json array" do
24
- result = Utils.json_array_param(data)
25
- expect(result).to match(/^\[.+\]$/)
26
- end
27
- it "should convert an array of hash to json array" do
28
- result = Utils.json_array_param([data, data2])
29
- expect(result).to eql("[#{data_s},#{data2_s}]")
30
- end
31
- it "should convert a json string to json array string" do
32
- result = Utils.json_array_param(data_s)
33
- expect(result).to eql("[#{data_s}]")
34
- end
35
- it "should accept a JSON array string and return it" do
36
- result = Utils.json_array_param("[#{data_s},#{data2_s}]")
37
- expect(result).to eql("[#{data_s},#{data2_s}]")
38
- end
39
- it "should throw an error if input string is not valid json string" do
40
- expect{Utils.json_array_param("I'm not a JSON object!")}.to raise_error(JSON::ParserError)
41
- end
42
- it "should support a block" do
43
- hash = {:block => "works"}
44
- hash_s = '{"block":"works"}'
45
- result = Utils.json_array_param(data) do |array|
46
- array[0]['foo'] = 'foobar'
47
- array.push(hash)
48
-
49
- end
50
- expect(result).to include(hash_s)
51
- expect(result).to include('foobar')
52
- end
53
- end
54
- end
@@ -1,970 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
-
4
- describe Cloudinary::Utils do
5
-
6
-
7
- before :each do
8
- Cloudinary.reset_config
9
- Cloudinary.config do |config|
10
- # config.cloud_name = "demo"
11
- config.secure_distribution = nil
12
- config.private_cdn = false
13
- config.secure = false
14
- config.cname = nil
15
- config.cdn_subdomain = false
16
- end
17
- end
18
-
19
- let(:cloud_name) { Cloudinary.config.cloud_name }
20
- let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
21
- let(:upload_path) { "#{root_path}/image/upload" }
22
-
23
- it "should allow overriding cloud_name in options" do
24
- expect(["test", { :cloud_name => "test321" }])
25
- .to produce_url("http://res.cloudinary.com/test321/image/upload/test")
26
- .and empty_options
27
- end
28
-
29
- it "should use default secure distribution if secure=true" do
30
- expect(["test", { :secure => true }])
31
- .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
32
- .and empty_options
33
- end
34
-
35
- it "should allow overriding secure distribution if secure=true" do
36
- expect(["test", { :secure => true, :secure_distribution => "something.else.com" }])
37
- .to produce_url("https://something.else.com/#{cloud_name}/image/upload/test")
38
- .and empty_options
39
- end
40
-
41
- it "should take secure distribution from config if secure=true" do
42
- Cloudinary.config.secure_distribution = "config.secure.distribution.com"
43
- expect(["test", { :secure => true }])
44
- .to produce_url("https://config.secure.distribution.com/#{cloud_name}/image/upload/test")
45
- .and empty_options
46
- end
47
-
48
- it "should default to akamai if secure is given with private_cdn and no secure_distribution" do
49
- expect(["test", { :secure => true, :private_cdn => true }])
50
- .to produce_url("https://#{cloud_name}-res.cloudinary.com/image/upload/test")
51
- .and empty_options
52
- end
53
-
54
- it "should not add cloud_name if secure private_cdn and secure non akamai secure_distribution" do
55
- expect(["test", { :secure => true, :private_cdn => true, :secure_distribution => "something.cloudfront.net" }])
56
- .to produce_url("https://something.cloudfront.net/image/upload/test")
57
- .and empty_options
58
- end
59
-
60
- it "should allow overriding private_cdn if private_cdn=true" do
61
- expect(["test", { :private_cdn => true }])
62
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/image/upload/test")
63
- .and empty_options
64
- end
65
-
66
- it "should allow overriding private_cdn if private_cdn=false" do
67
- Cloudinary.config.private_cdn = true
68
- expect(["test", { :private_cdn => false }])
69
- .to produce_url("#{upload_path}/test")
70
- .and empty_options
71
- end
72
-
73
- it "should allow overriding cname if cname=example.com" do
74
- expect(["test", { :cname => "example.com" }])
75
- .to produce_url("http://example.com/#{cloud_name}/image/upload/test")
76
- .and empty_options
77
- end
78
-
79
- it "should allow overriding cname if cname=false" do
80
- Cloudinary.config.cname = "example.com"
81
- expect(["test", { :cname => false }])
82
- .to produce_url("#{upload_path}/test")
83
- .and empty_options
84
- end
85
-
86
- it "should use format from options" do
87
- expect(["test", { :format => :jpg }])
88
- .to produce_url("#{upload_path}/test.jpg")
89
- .and empty_options
90
- end
91
-
92
- it "should support url_suffix in shared distribution" do
93
- expect(["test", { :url_suffix => "hello" }])
94
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/images/test/hello")
95
- .and empty_options
96
- expect(["test", { :url_suffix => "hello", :angle => 0 }])
97
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/images/a_0/test/hello")
98
- .and empty_options
99
- end
100
-
101
- it "should disallow url_suffix in non upload types" do
102
- expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello", :private_cdn => true, :type => :facebook }) }.to raise_error(CloudinaryException)
103
- end
104
-
105
- it "should disallow url_suffix with / or ." do
106
- expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello/world", :private_cdn => true }) }.to raise_error(CloudinaryException)
107
- expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello.world", :private_cdn => true }) }.to raise_error(CloudinaryException)
108
- end
109
-
110
- it "should support url_suffix for private_cdn" do
111
- expect(["test", { :url_suffix => "hello", :private_cdn => true }])
112
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/test/hello")
113
- .and empty_options
114
- expect(["test", { :url_suffix => "hello", :angle => 0, :private_cdn => true }])
115
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/a_0/test/hello")
116
- .and empty_options
117
- end
118
-
119
- it "should put format after url_suffix" do
120
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg" }])
121
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/test/hello.jpg")
122
- .and empty_options
123
- end
124
-
125
- it "should sign a url" do
126
- expected = Cloudinary::Utils.cloudinary_url "some_public_id.jpg",
127
- :cloud_name => "test",
128
- :api_key => "123456789012345",
129
- :api_secret => "AbcdEfghIjklmnopq1234567890",
130
- :type => "authenticated",
131
- :sign_url => true,
132
- :overlay => "text:Helvetica_50:test+text"
133
- expect(expected).to eq("http://res.cloudinary.com/test/image/authenticated/s--j5Z1ILxd--/l_text:Helvetica_50:test+text/some_public_id.jpg")
134
- end
135
-
136
- it "should not sign the url_suffix" do
137
- expected_signture = Cloudinary::Utils.cloudinary_url("test", :format => "jpg", :sign_url => true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
138
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg", :sign_url => true }])
139
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/#{expected_signture}/test/hello.jpg")
140
- .and empty_options
141
-
142
- expected_signture = Cloudinary::Utils.cloudinary_url("test", :format => "jpg", :angle => 0, :sign_url => true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
143
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg", :angle => 0, :sign_url => true }])
144
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/#{expected_signture}/a_0/test/hello.jpg")
145
- .and empty_options
146
- end
147
-
148
- it "should support url_suffix for raw uploads" do
149
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :raw }])
150
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/files/test/hello")
151
- .and empty_options
152
- end
153
-
154
- it "should support url_suffix for videos" do
155
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :video }])
156
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/videos/test/hello")
157
- .and empty_options
158
- end
159
-
160
- it "should support url_suffix for private images" do
161
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :image, :type => :private }])
162
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/private_images/test/hello")
163
- .and empty_options
164
- expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg", :resource_type => :image, :type => :private }])
165
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/private_images/test/hello.jpg")
166
- .and empty_options
167
- end
168
-
169
- it "should support url_suffix for authenticated images" do
170
- expect(["test", { :url_suffix => "hello", :format => "jpg", :resource_type => :image, :type => :authenticated }])
171
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/authenticated_images/test/hello.jpg")
172
- .and empty_options
173
- end
174
-
175
-
176
- describe 'root_path support' do
177
-
178
- it "should allow use_root_path in shared distribution" do
179
- # expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true})}.to raise_error(CloudinaryException)
180
- expect(["test", { :use_root_path => true, :private_cdn => false }])
181
- .to produce_url("#{root_path}/test")
182
- .and empty_options
183
- expect(["test", { :use_root_path => true, :private_cdn => false, :angle => 0 }])
184
- .to produce_url("#{root_path}/a_0/test")
185
- .and empty_options
186
- end
187
-
188
- it "should support use_root_path for private_cdn" do
189
- expect(["test", { :use_root_path => true, :private_cdn => true }])
190
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/test")
191
- .and empty_options
192
- expect(["test", { :use_root_path => true, :private_cdn => true, :angle => 0 }])
193
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/a_0/test")
194
- .and empty_options
195
- end
196
-
197
- it "should support use_root_path together with url_suffix for private_cdn" do
198
- expect(["test", { :use_root_path => true, :url_suffix => "hello", :private_cdn => true }])
199
- .to produce_url("http://#{cloud_name}-res.cloudinary.com/test/hello")
200
- .and empty_options
201
- end
202
-
203
- it "should disallow use_root_path if not image/upload" do
204
- expect { Cloudinary::Utils.cloudinary_url("test", { :use_root_path => true, :private_cdn => true, :type => :facebook }) }.to raise_error(CloudinaryException)
205
- expect { Cloudinary::Utils.cloudinary_url("test", { :use_root_path => true, :private_cdn => true, :resource_type => :raw }) }.to raise_error(CloudinaryException)
206
- end
207
-
208
- end
209
- describe ":width, :height" do
210
- it "should use width and height from options only if crop is given" do
211
- expect(["test", { :width => 100, :height => 100 }])
212
- .to produce_url("#{upload_path}/test")
213
- .and mutate_options_to({ :width => 100, :height => 100 })
214
- expect(["test", { :width => 100, :height => 100, :crop => :crop }])
215
- .to produce_url("#{upload_path}/c_crop,h_100,w_100/test")
216
- .and mutate_options_to({ :width => 100, :height => 100 })
217
- end
218
-
219
- it "should not pass width and height to html in case of fit, lfill or limit crop" do
220
- expect(["test", { :width => 100, :height => 100, :crop => :limit }])
221
- .to produce_url("#{upload_path}/c_limit,h_100,w_100/test")
222
- .and empty_options
223
- expect(["test", { :width => 100, :height => 100, :crop => :lfill }])
224
- .to produce_url("#{upload_path}/c_lfill,h_100,w_100/test")
225
- .and empty_options
226
- expect(["test", { :width => 100, :height => 100, :crop => :fit }])
227
- .to produce_url("#{upload_path}/c_fit,h_100,w_100/test")
228
- .and empty_options
229
- end
230
-
231
- it "should not pass width and height to html in case angle was used" do
232
- expect(["test", { :width => 100, :height => 100, :crop => :scale, :angle => :auto }])
233
- .to produce_url("#{upload_path}/a_auto,c_scale,h_100,w_100/test")
234
- .and empty_options
235
- end
236
- it "should support size" do
237
- expect(["test", { :size => "10x10", :crop => :crop }])
238
- .to produce_url("#{upload_path}/c_crop,h_10,w_10/test")
239
- .and mutate_options_to({ :width => "10", :height => "10" })
240
- end
241
- it "should support auto width" do
242
- expect(["test", { :width => "auto:20", :crop => :fill }])
243
- .to produce_url("#{upload_path}/c_fill,w_auto:20/test")
244
- expect(["test", { :width => "auto:20:350", :crop => :fill }])
245
- .to produce_url("#{upload_path}/c_fill,w_auto:20:350/test")
246
- expect(["test", { :width => "auto:breakpoints", :crop => :fill }])
247
- .to produce_url("#{upload_path}/c_fill,w_auto:breakpoints/test")
248
- expect(["test", { :width => "auto:breakpoints_100_1900_20_15", :crop => :fill }])
249
- .to produce_url("#{upload_path}/c_fill,w_auto:breakpoints_100_1900_20_15/test")
250
- expect(["test", { :width => "auto:breakpoints:json", :crop => :fill }])
251
- .to produce_url("#{upload_path}/c_fill,w_auto:breakpoints:json/test")
252
- end
253
- it 'should support ih,iw' do
254
- expect(["test", {:width => "iw", :height => "ih", :crop => :crop}])
255
- .to produce_url("#{upload_path}/c_crop,h_ih,w_iw/test")
256
- end
257
- end
258
-
259
- it "should use x, y, radius, prefix, gravity and quality from options" do
260
- expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => 0.4, :prefix => "a" }])
261
- .to produce_url("#{upload_path}/g_center,p_a,q_0.4,r_3,x_1,y_2/test")
262
- .and empty_options
263
-
264
- expect(["test", { :width => 0.5, :crop => :crop, :gravity => :auto }])
265
- .to produce_url("#{upload_path}/c_crop,g_auto,w_0.5/test")
266
- .and empty_options
267
- end
268
-
269
- describe "gravity" do
270
- it "should support auto" do
271
- expect(["test", {width: 100, height: 100, crop: 'crop', gravity: 'auto'}])
272
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto,h_100,w_100/test")
273
- .and mutate_options_to({width: 100, height: 100})
274
- expect(["test", {width: 100, height: 100, crop: 'crop', gravity: 'auto'}])
275
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto,h_100,w_100/test")
276
- .and mutate_options_to({width: 100, height: 100})
277
- end
278
- it "should support focal gravity" do
279
- ["adv_face", "adv_faces", "adv_eyes", "face", "faces", "body", "no_faces"].each do |focal|
280
- expect(["test", {width: 100, height: 100, crop: 'crop', gravity: "auto:#{focal}"}])
281
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto:#{focal},h_100,w_100/test")
282
- .and mutate_options_to({width: 100, height: 100})
283
- end
284
- end
285
- it "should support auto level with thumb cropping" do
286
- [0, 10, 100].each do |level|
287
- expect(["test", {width: 100, height: 100, crop: 'thumb', gravity: "auto:#{level}"}])
288
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_thumb,g_auto:#{level},h_100,w_100/test")
289
- .and mutate_options_to({width: 100, height: 100})
290
- expect(["test", {width: 100, height: 100, crop: 'thumb', gravity: "auto:adv_faces:#{level}"}])
291
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_thumb,g_auto:adv_faces:#{level},h_100,w_100/test")
292
- .and mutate_options_to({width: 100, height: 100})
293
- end
294
- end
295
- it "should support custom_no_override" do
296
- expect(["test", {width: 100, height: 100, crop: 'crop', gravity: "auto:custom_no_override"}])
297
- .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto:custom_no_override,h_100,w_100/test")
298
- .and mutate_options_to({width: 100, height: 100})
299
- end
300
- end
301
-
302
- describe ":quality" do
303
- it "support a percent value" do
304
- expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => 80, :prefix => "a" }])
305
- .to produce_url("#{upload_path}/g_center,p_a,q_80,r_3,x_1,y_2/test")
306
-
307
- expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => "80:444", :prefix => "a" }])
308
- .to produce_url("#{upload_path}/g_center,p_a,q_80:444,r_3,x_1,y_2/test")
309
- end
310
- it "should support auto value" do
311
-
312
- expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => "auto", :prefix => "a" }])
313
- .to produce_url("#{upload_path}/g_center,p_a,q_auto,r_3,x_1,y_2/test")
314
-
315
- expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => "auto:good", :prefix => "a" }])
316
- .to produce_url("#{upload_path}/g_center,p_a,q_auto:good,r_3,x_1,y_2/test")
317
-
318
- end
319
- end
320
-
321
- describe ":transformation" do
322
- it "should support named tranformation" do
323
- expect(["test", { :transformation => "blip" }])
324
- .to produce_url("#{upload_path}/t_blip/test")
325
- .and empty_options
326
- end
327
-
328
- it "should support array of named tranformations" do
329
- expect(["test", { :transformation => ["blip", "blop"] }])
330
- .to produce_url("#{upload_path}/t_blip.blop/test")
331
- .and empty_options
332
- end
333
-
334
- it "should support base tranformation" do
335
- expect(["test", { :transformation => { :x => 100, :y => 100, :crop => :fill }, :crop => :crop, :width => 100 }])
336
- .to produce_url("#{upload_path}/c_fill,x_100,y_100/c_crop,w_100/test")
337
- .and mutate_options_to({ :width => 100 })
338
- end
339
-
340
- it "should support array of base tranformations" do
341
- expect(["test", { :transformation => [{ :x => 100, :y => 100, :width => 200, :crop => :fill }, { :radius => 10 }], :crop => :crop, :width => 100 }])
342
- .to produce_url("#{upload_path}/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test")
343
- .and mutate_options_to({ :width => 100 })
344
- end
345
-
346
- it "should support array of tranformations" do
347
- result = Cloudinary::Utils.generate_transformation_string([{ :x => 100, :y => 100, :width => 200, :crop => :fill }, { :radius => 10 }])
348
- expect(result).to eq("c_fill,w_200,x_100,y_100/r_10")
349
- end
350
-
351
- it "should not include empty tranformations" do
352
- expect(["test", { :transformation => [{}, { :x => 100, :y => 100, :crop => :fill }, {}] }])
353
- .to produce_url("#{upload_path}/c_fill,x_100,y_100/test")
354
- .and empty_options
355
- end
356
- end
357
-
358
-
359
- it "should use type from options" do
360
- expect(["test", { :type => :facebook }])
361
- .to produce_url("#{root_path}/image/facebook/test")
362
- .and empty_options
363
- end
364
-
365
- it "should use resource_type from options" do
366
- expect(["test", { :resource_type => :raw }])
367
- .to produce_url("#{root_path}/raw/upload/test")
368
- .and empty_options
369
- end
370
-
371
- it "should ignore http links only if type is not given or is asset" do
372
- expect(["http://test", { :type => nil }])
373
- .to produce_url("http://test")
374
- .and empty_options
375
- expect(["http://test", { :type => :asset }])
376
- .to produce_url("http://test")
377
- .and empty_options
378
- expect(["http://test", { :type => :fetch }])
379
- .to produce_url("#{root_path}/image/fetch/http://test")
380
- .and empty_options
381
- end
382
-
383
- it "should use allow absolute links to /images" do
384
- expect(["/images/test", {}])
385
- .to produce_url("#{upload_path}/test")
386
- .and empty_options
387
- end
388
-
389
- it "should use ignore absolute links not to /images" do
390
- expect(["/js/test", {}])
391
- .to produce_url("/js/test")
392
- .and empty_options
393
- end
394
-
395
- it "should escape fetch urls" do
396
- expect(["http://blah.com/hello?a=b", { :type => :fetch }])
397
- .to produce_url("#{root_path}/image/fetch/http://blah.com/hello%3Fa%3Db")
398
- .and empty_options
399
- end
400
-
401
- it "should should escape http urls" do
402
- expect(["http://www.youtube.com/watch?v=d9NF2edxy-M", { :type => :youtube }])
403
- .to produce_url("#{root_path}/image/youtube/http://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M")
404
- .and empty_options
405
- end
406
-
407
- it "should support background" do
408
- expect(["test", { :background => "red" }])
409
- .to produce_url("#{upload_path}/b_red/test")
410
- .and empty_options
411
- expect(["test", { :background => "#112233" }])
412
- .to produce_url("#{upload_path}/b_rgb:112233/test")
413
- .and empty_options
414
- end
415
-
416
- it "should support default_image" do
417
- expect(["test", { :default_image => "default" }])
418
- .to produce_url("#{upload_path}/d_default/test")
419
- .and empty_options
420
- end
421
-
422
- it "should support angle" do
423
- expect(["test", { :angle => "55" }])
424
- .to produce_url("#{upload_path}/a_55/test")
425
- .and empty_options
426
- expect(["test", { :angle => ["auto", "55"] }])
427
- .to produce_url("#{upload_path}/a_auto.55/test")
428
- .and empty_options
429
- end
430
-
431
- it "should support format for fetch urls" do
432
- expect(["http://cloudinary.com/images/logo.png", { :format => "jpg", :type => :fetch }])
433
- .to produce_url("#{root_path}/image/fetch/f_jpg/http://cloudinary.com/images/logo.png")
434
- .and empty_options
435
- end
436
-
437
- it "should support effect" do
438
- expect(["test", { :effect => "sepia" }])
439
- .to produce_url("#{upload_path}/e_sepia/test")
440
- .and empty_options
441
- end
442
-
443
- it "should support effect with hash param" do
444
- expect(["test", { :effect => { "sepia" => -10 } }])
445
- .to produce_url("#{upload_path}/e_sepia:-10/test")
446
- .and empty_options
447
- end
448
-
449
- it "should support effect with array param" do
450
- expect(["test", { :effect => ["sepia", 10] }])
451
- .to produce_url("#{upload_path}/e_sepia:10/test")
452
- .and empty_options
453
- end
454
-
455
- it "should support blur effect with ocr gravity" do
456
- expect(["test", { :effect => ["blur_region", 5000], :gravity => "ocr_text" }])
457
- .to produce_url("#{upload_path}/e_blur_region:5000,g_ocr_text/test")
458
- .and empty_options
459
- end
460
-
461
- it "should support artistic effect" do
462
- expect(["test", { :effect => "art:incognito"}])
463
- .to produce_url("#{upload_path}/e_art:incognito/test")
464
- .and empty_options
465
- end
466
-
467
- it "should support keyframe_interval" do
468
- expect(["test", { :keyframe_interval => 10 }])
469
- .to produce_url("#{upload_path}/ki_10/test")
470
- .and empty_options
471
- end
472
-
473
- it "should support streaming_profile" do
474
- expect(["test", { :streaming_profile => "some-profile" }])
475
- .to produce_url("#{upload_path}/sp_some-profile/test")
476
- .and empty_options
477
- end
478
-
479
- shared_examples "a signed url" do |specific_options = {}, specific_transformation = ""|
480
- let(:expected_transformation) do
481
- (specific_transformation.blank? || specific_transformation.match(/\/$/)) ? specific_transformation : "#{specific_transformation}/"
482
- end
483
- let! (:authenticated_image) do
484
- Cloudinary::Uploader.upload "http://res.cloudinary.com/demo/image/upload/sample.jpg",
485
- :type => 'authenticated',
486
- :tags => TEST_TAG
487
- end
488
- let(:options) { { :version => authenticated_image['version'], :sign_url => true, :type => :authenticated }.merge(specific_options) }
489
- let(:authenticated_path) { "#{root_path}/image/authenticated" }
490
-
491
- it "should correctly sign URL with version" do
492
- expect(["#{authenticated_image['public_id']}.jpg", options])
493
- .to produce_url(%r"#{authenticated_path}/s--[\w-]+--/#{expected_transformation}v#{authenticated_image['version']}/#{authenticated_image['public_id']}.jpg")
494
- .and empty_options
495
- end
496
- it "should correctly sign URL with transformation and version" do
497
- options[:transformation] = { :crop => "crop", :width => 10, :height => 20 }
498
- expect(["#{authenticated_image['public_id']}.jpg", options])
499
- .to produce_url(%r"#{authenticated_path}/s--[\w-]+--/c_crop,h_20,w_10/#{expected_transformation}v#{authenticated_image['version']}/#{authenticated_image['public_id']}.jpg")
500
- .and empty_options
501
- end
502
- it "should correctly sign URL with transformation" do
503
- options[:transformation] = { :crop => "crop", :width => 10, :height => 20 }
504
- expect(["#{authenticated_image['public_id']}.jpg", options])
505
- .to produce_url(%r"#{authenticated_path}/s--[\w-]+--/c_crop,h_20,w_10/#{expected_transformation}v#{authenticated_image['version']}/#{authenticated_image['public_id']}.jpg")
506
- .and empty_options
507
- .and be_served_by_cloudinary
508
- end
509
- it "should correctly sign fetch URL" do
510
- options[:type] = :fetch
511
- expect(["http://res.cloudinary.com/demo/sample.png", options])
512
- .to produce_url(%r"^#{root_path}/image/fetch/s--[\w-]+--/#{expected_transformation}v#{authenticated_image['version']}/http://res.cloudinary.com/demo/sample.png$")
513
- .and empty_options
514
- end
515
- end
516
-
517
-
518
- { 'overlay' => :l, :underlay => :u }.each do |param, letter|
519
- describe param do
520
- let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
521
- let(:layers_options) { [
522
- # [name, options, result]
523
- ["string", "text:hello", "text:hello"],
524
- ["public_id", { "public_id" => "logo" }, "logo"],
525
- ["public_id with folder", { "public_id" => "folder/logo" }, "folder:logo"],
526
- ["private", { "public_id" => "logo", "type" => "private" }, "private:logo"],
527
- ["format", { "public_id" => "logo", "format" => "png" }, "logo.png"],
528
- ["video", { "resource_type" => "video", "public_id" => "cat" }, "video:cat"],
529
- ] }
530
- it "should support #{param}" do
531
- layers_options.each do |name, options, result|
532
- expect(["test", { param => options }]).to produce_url("#{upload_path}/#{letter}_#{result}/test").and empty_options
533
- end
534
- end
535
-
536
- it "should not pass width/height to html for #{param}" do
537
- expect(["test", { param => "text:hello", :height => 100, :width => 100 }])
538
- .to produce_url("#{upload_path}/h_100,#{letter}_text:hello,w_100/test")
539
- .and empty_options
540
- end
541
- end
542
- end
543
-
544
- describe "text" do
545
-
546
- text_layer = "Hello World, /Nice to meet you?"
547
- text_encoded = "Hello%20World%252C%20%252FNice%20to%20meet%20you%3F"
548
-
549
- before :all do
550
- Cloudinary::Uploader.text(text_layer, {
551
- :public_id => "test_text",
552
- :overwrite => true,
553
- :font_family => "Arial",
554
- :font_size => "18",
555
- :tags => TEST_TAG
556
- })
557
- srt = Tempfile.new(['test_subtitles', '.srt'])
558
- srt.write <<-END
559
- 1
560
- 00:00:10,500 --> 00:00:13,000
561
- Hello World, Nice to meet you?
562
-
563
- END
564
- srt.rewind
565
- Cloudinary::Uploader.upload srt, :public_id => 'subtitles.srt', :resource_type => 'raw', :overwrite => true, :tags => TEST_TAG
566
- srt.unlink
567
- end
568
-
569
- include_context "cleanup"
570
-
571
- { 'overlay' => 'l' }.each do |param, short| # 'underlay' => 'u' behaves the same as overlay
572
- describe param do
573
- let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
574
- # [name, options, result]
575
- layers_options= [
576
- ["string", "text:test_text:hello", "text:test_text:hello"],
577
- ["explicit layer parameter", "text:test_text:#{text_encoded}", "text:test_text:#{text_encoded}"],
578
- ["text parameter", { :public_id => "test_text", :text => text_layer }, "text:test_text:#{text_encoded}"],
579
- ["text with font family and size parameters", { :text => text_layer, :font_family => "Arial", :font_size => "18" }, "text:Arial_18:#{text_encoded}"],
580
- ["text with text style parameter", { :text => text_layer, :font_family => "Arial", :font_size => "18", :font_weight => "bold", :font_style => "italic", :letter_spacing => 4, :line_spacing => 2 }, "text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2:#{text_encoded}"],
581
- ["subtitles", { :resource_type => "subtitles", :public_id => "subtitles.srt" }, "subtitles:subtitles.srt"],
582
- ["subtitles with font family and size", { :resource_type => "subtitles", :public_id => "subtitles.srt", :font_family => "Arial", :font_size => "40" }, "subtitles:Arial_40:subtitles.srt"],
583
- ["image of type fetch", { :public_id => "http://res.cloudinary.com/demo/image/upload/ci", :type => "fetch" }, "fetch:aHR0cDovL3Jlcy5jbG91ZGluYXJ5LmNvbS9kZW1vL2ltYWdlL3VwbG9hZC9jaQ=="]
584
- ]
585
- layers_options.each do |name, options, result|
586
- it "should support #{name}" do
587
- expect(["sample.jpg", { param => options }]).to produce_url("#{upload_path}/#{short}_#{result}/sample.jpg").and empty_options
588
- # expect("#{upload_path}/#{short}_#{result}/sample.jpg").to be_served_by_cloudinary
589
- end
590
- unless options.is_a? String || param == 'underlay'
591
- op = Hash.new
592
- op[param] = options
593
- it_behaves_like "a signed url", op, "#{short}_#{result}"
594
- end
595
- end
596
-
597
- it "should not pass width/height to html for #{param}" do
598
- expect(["test", { param => "text:test_text", :height => 100, :width => 100 }])
599
- .to produce_url("#{upload_path}/h_100,#{short}_text:test_text,w_100/test")
600
- .and empty_options
601
-
602
- end
603
- end
604
- end
605
- end
606
-
607
-
608
- it "should use ssl_detected if secure is not given as parameter and not set to true in configuration" do
609
- expect(["test", { :ssl_detected => true }])
610
- .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
611
- .and empty_options
612
- end
613
-
614
- it "should use secure if given over ssl_detected and configuration" do
615
- Cloudinary.config.secure = true
616
- expect(["test", { :ssl_detected => true, :secure => false }])
617
- .to produce_url("#{upload_path}/test")
618
- .and empty_options
619
- end
620
-
621
- it "should use secure: true from configuration over ssl_detected" do
622
- Cloudinary.config.secure = true
623
- expect(["test", { :ssl_detected => false }])
624
- .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
625
- .and empty_options
626
- end
627
-
628
- it "should support extenal cname" do
629
- expect(["test", { :cname => "hello.com" }])
630
- .to produce_url("http://hello.com/#{cloud_name}/image/upload/test")
631
- .and empty_options
632
- end
633
-
634
- it "should support extenal cname with cdn_subdomain on" do
635
- expect(["test", { :cname => "hello.com", :private_cdn => true, :cdn_subdomain => true}])
636
- .to produce_url("http://a2.hello.com/image/upload/test")
637
- .and empty_options
638
- end
639
-
640
- it "should support cdn_subdomain with secure on if using shared_domain" do
641
- expect(["test", { :secure => true, :cdn_subdomain => true }])
642
- .to produce_url("https://res-2.cloudinary.com/#{cloud_name}/image/upload/test")
643
- .and empty_options
644
- end
645
-
646
- it "should support secure_cdn_subdomain false override with secure" do
647
- expect(["test", { :secure => true, :cdn_subdomain => true, :secure_cdn_subdomain => false }])
648
- .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
649
- .and empty_options
650
- end
651
-
652
- it "should support secure_cdn_subdomain true override with secure" do
653
- expect(["test", { :secure => true, :cdn_subdomain => true, :secure_cdn_subdomain => true, :private_cdn => true }])
654
- .to produce_url("https://#{cloud_name}-res-2.cloudinary.com/image/upload/test")
655
- .and empty_options
656
- end
657
-
658
- it "should support string param" do
659
- expect(["test", { "effect" => { "sepia" => 10 } }])
660
- .to produce_url("#{upload_path}/e_sepia:10/test")
661
- .and empty_options
662
- end
663
-
664
- it "should support border" do
665
- expect(["test", { "border" => { :width => 5 } }])
666
- .to produce_url("#{upload_path}/bo_5px_solid_black/test")
667
- .and empty_options
668
- expect(["test", { "border" => { :width => 5, :color => "#ffaabbdd" } }])
669
- .to produce_url("#{upload_path}/bo_5px_solid_rgb:ffaabbdd/test")
670
- .and empty_options
671
- expect(["test", { "border" => "1px_solid_blue" }])
672
- .to produce_url("#{upload_path}/bo_1px_solid_blue/test")
673
- .and empty_options
674
- expect(["test", { "border" => "2" }]).to produce_url("#{upload_path}/test").and mutate_options_to({ :border => "2" })
675
- end
676
-
677
- it "should support flags" do
678
- expect(["test", { "flags" => "abc" }])
679
- .to produce_url("#{upload_path}/fl_abc/test")
680
- .and empty_options
681
- expect(["test", { "flags" => ["abc", "def"] }])
682
- .to produce_url("#{upload_path}/fl_abc.def/test")
683
- .and empty_options
684
- end
685
-
686
- it "should support aspect ratio" do
687
- expect(["test", { "aspect_ratio" => "1.0" }])
688
- .to produce_url("#{upload_path}/ar_1.0/test")
689
- .and empty_options
690
- expect(["test", { "aspect_ratio" => "3:2" }])
691
- .to produce_url("#{upload_path}/ar_3:2/test")
692
- .and empty_options
693
- end
694
-
695
- it "build_upload_params should not destroy options" do
696
- options = { :width => 100, :crop => :scale }
697
- expect(Cloudinary::Uploader.build_upload_params(options)[:transformation]).to eq("c_scale,w_100")
698
- expect(options.length).to eq(2)
699
- end
700
-
701
- it "build_upload_params canonize booleans" do
702
- options = { :backup => true, :use_filename => false, :colors => :true,
703
- :image_metadata => :false, :invalidate => 1 }
704
- params = Cloudinary::Uploader.build_upload_params(options)
705
- expect(Cloudinary::Api.only(params, *options.keys))
706
- .to eq(:backup => 1,
707
- :use_filename => 0,
708
- :colors => 1,
709
- :image_metadata => 0,
710
- :invalidate => 1
711
- )
712
- options = { :colors => "true", :exif => "false", :eager_async => "1" }
713
- params = Cloudinary::Uploader.build_upload_params(options)
714
- expect(Cloudinary::Api.only(params, *options.keys))
715
- .to eq(:exif => 0, :colors => 1, :eager_async => 1)
716
- expect(Cloudinary::Uploader.build_upload_params(:backup => nil)[:backup]).to be_nil
717
- expect(Cloudinary::Uploader.build_upload_params({})[:backup]).to be_nil
718
- end
719
-
720
- it "should add version if public_id contains /" do
721
- expect(["folder/test", {}])
722
- .to produce_url("#{upload_path}/v1/folder/test")
723
- .and empty_options
724
- expect(["folder/test", { :version => 123 }])
725
- .to produce_url("#{upload_path}/v123/folder/test")
726
- .and empty_options
727
- end
728
-
729
- it "should not add version if public_id contains version already" do
730
- expect(["v1234/test", {}])
731
- .to produce_url("#{upload_path}/v1234/test")
732
- .and empty_options
733
- end
734
-
735
- it "should allow to shorted image/upload urls" do
736
- expect(["test", { :shorten => true }])
737
- .to produce_url("#{root_path}/iu/test")
738
- .and empty_options
739
- end
740
-
741
- it "should allow to use folders in PreloadedFile" do
742
- signature = Cloudinary::Utils.api_sign_request({ :public_id => "folder/file", :version => "1234" }, Cloudinary.config.api_secret)
743
- preloaded = Cloudinary::PreloadedFile.new("image/upload/v1234/folder/file.jpg#" + signature)
744
- expect(preloaded).to be_valid
745
- [
746
- [:filename, 'folder/file.jpg'],
747
- [:version, '1234'],
748
- [:public_id, 'folder/file'],
749
- [:signature, signature],
750
- [:resource_type, 'image'],
751
- [:type, 'upload'],
752
- [:format, 'jpg']
753
- ].each do |attr,value|
754
- expect(preloaded.send(attr)).to eq(value)
755
- end
756
- end
757
-
758
- it "should escape public_ids" do
759
- [
760
- ["a b", "a%20b"],
761
- ["a+b", "a%2Bb"],
762
- ["a%20b", "a%20b"],
763
- ["a-b", "a-b"],
764
- ["a??b", "a%3F%3Fb"],
765
- ["parentheses(interject)", "parentheses%28interject%29"]
766
- ].each do
767
- |source, target|
768
- expect(Cloudinary::Utils.cloudinary_url(source)).to eq("#{upload_path}/#{target}")
769
- end
770
- end
771
-
772
-
773
- describe ":sign_url" do
774
- it_behaves_like "a signed url"
775
- end
776
-
777
- describe ":sign_version (deprecated)" do
778
- it_behaves_like "a signed url", :sign_version => true
779
- end
780
-
781
- it "should correctly sign_request" do
782
- params = Cloudinary::Utils.sign_request(
783
- {
784
- :public_id => "folder/file",
785
- :version => "1234" },
786
- {
787
- :cloud_name => "demo",
788
- :api_key => "1234",
789
- :api_secret => "b"
790
- }
791
- )
792
- expect(params).to include(:signature => "7a3349cbb373e4812118d625047ede50b90e7b67")
793
- end
794
-
795
- it "should support responsive width" do
796
- expect(["test", { :width => 100, :height => 100, :crop => :crop, :responsive_width => true }])
797
- .to produce_url("#{upload_path}/c_crop,h_100,w_100/c_limit,w_auto/test")
798
- .and mutate_options_to({ :responsive => true })
799
- Cloudinary.config.responsive_width_transformation = { :width => :auto, :crop => :pad }
800
- expect(["test", { :width => 100, :height => 100, :crop => :crop, :responsive_width => true }])
801
- .to produce_url("#{upload_path}/c_crop,h_100,w_100/c_pad,w_auto/test")
802
- .and mutate_options_to({ :responsive => true })
803
- end
804
-
805
- it "should correctly encode double arrays" do
806
- expect(Cloudinary::Utils.encode_double_array([1, 2, 3, 4])).to eq("1,2,3,4")
807
- expect(Cloudinary::Utils.encode_double_array([[1, 2, 3, 4], [5, 6, 7, 8]])).to eq("1,2,3,4|5,6,7,8")
808
- end
809
-
810
- describe ":if" do
811
- describe 'with literal condition string' do
812
- it "should include the if parameter as the first component in the transformation string" do
813
- expect(["sample", { if: "w_lt_200", crop: "fill", height: 120, width: 80 }])
814
- .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/sample")
815
- expect(["sample", { crop: "fill", height: 120, if: "w_lt_200", width: 80 }])
816
- .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/sample")
817
-
818
- end
819
- it "should allow multiple conditions when chaining transformations " do
820
- expect(["sample", transformation: [{ if: "w_lt_200", crop: "fill", height: 120, width: 80 },
821
- { if: "w_gt_400", crop: "fit", width: 150, height: 150 },
822
- { effect: "sepia" }]])
823
- .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/if_w_gt_400,c_fit,h_150,w_150/e_sepia/sample")
824
- end
825
- it "should allow multiple tags condition" do
826
- expect(["sample", transformation: [{ if: "!tag1:tag2:tag3!_in_tags", crop: "fill", height: 120, width: 80 },
827
- { if: "else", crop: "fit", width: 150, height: 150 },
828
- { effect: "sepia" }]])
829
- .to produce_url("#{upload_path}/if_!tag1:tag2:tag3!_in_tags,c_fill,h_120,w_80/if_else,c_fit,h_150,w_150/e_sepia/sample")
830
- end
831
-
832
- describe "including spaces and operators" do
833
- it "should translate operators" do
834
- expect(["sample", { if: "w < 200", crop: "fill", height: 120, width: 80 }])
835
- .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/sample")
836
- end
837
- end
838
-
839
- describe 'if end' do
840
- it "should include the if_end as the last parameter in its component" do
841
- expect(["sample", transformation: [{ if: "w_lt_200" },
842
- { crop: "fill", height: 120, width: 80, effect: "sharpen" },
843
- { effect: "brightness:50" },
844
- { effect: "shadow", color: "red" },
845
- { if: "end" }]])
846
- .to produce_url("#{upload_path}/if_w_lt_200/c_fill,e_sharpen,h_120,w_80/e_brightness:50/co_red,e_shadow/if_end/sample")
847
- end
848
- it "should support if_else with transformation parameters" do
849
- expect(["sample", transformation: [{ if: "w_lt_200", crop: "fill", height: 120, width: 80 },
850
- { if: "else", crop: "fill", height: 90, width: 100 }]])
851
- .to produce_url("#{upload_path}/if_w_lt_200,c_fill,h_120,w_80/if_else,c_fill,h_90,w_100/sample")
852
- end
853
- it "if_else should be without any transformation parameters" do
854
- expect(["sample", transformation: [{ if: "w_lt_200" },
855
- { crop: "fill", height: 120, width: 80 },
856
- { if: "else" },
857
- { crop: "fill", height: 90, width: 100 }]])
858
- .to produce_url("#{upload_path}/if_w_lt_200/c_fill,h_120,w_80/if_else/c_fill,h_90,w_100/sample")
859
- end
860
- end
861
- it "should support and translate operators: '=', '!=', '<', '>', '<=', '>=', '&&', '||'" do
862
-
863
- all_operators =
864
- 'if_' +
865
- 'w_eq_0_and' +
866
- '_w_ne_0_or' +
867
- '_h_lt_0_and' +
868
- '_ar_gt_0_and' +
869
- '_pc_lte_0_and' +
870
- '_fc_gte_0' +
871
- ',e_grayscale'
872
-
873
- expect( ["sample",
874
- :if =>"width = 0 && w != 0 || height < 0 and aspect_ratio > 0 and page_count <= 0 and face_count >= 0",
875
- :effect =>"grayscale"])
876
- .to produce_url("#{upload_path}/#{all_operators}/sample")
877
- end
878
-
879
- end
880
- end
881
-
882
- describe "variables" do
883
- it "array should define a set of variables" do
884
- options = {
885
- :if => "face_count > 2",
886
- :variables => [ ["$z", 5], ["$foo", "$z * 2"] ],
887
- :crop => "scale", :width => "$foo * 200"
888
- }
889
- t = Cloudinary::Utils.generate_transformation_string options
890
- expect(t).to eq("if_fc_gt_2,$z_5,$foo_$z_mul_2,c_scale,w_$foo_mul_200")
891
- end
892
- it "'$key' should define a variable" do
893
- options = { :transformation => [
894
- {"$foo" => 10 },
895
- {:if => "face_count > 2"},
896
- {:crop => "scale", :width => "$foo * 200 / face_count"},
897
- {:if => "end"}
898
- ] }
899
- t = Cloudinary::Utils.generate_transformation_string options
900
- expect(t).to eq("$foo_10/if_fc_gt_2/c_scale,w_$foo_mul_200_div_fc/if_end")
901
- end
902
- it "should support text values" do
903
- expect( ["sample", :effect => "$efname:100", "$efname" => "!blur!"]).to produce_url "#{upload_path}/$efname_!blur!,e_$efname:100/sample"
904
-
905
- end
906
- it "should support string interpolation" do
907
- expect( ["sample", :crop => "scale", :overlay => {:text => "$(start)Hello $(name)$(ext), $(no ) $( no)$(end)", :font_family => "Arial", :font_size => "18"} ]).to produce_url "#{upload_path}/c_scale,l_text:Arial_18:$(start)Hello%20$(name)$(ext)%252C%20%24%28no%20%29%20%24%28%20no%29$(end)/sample"
908
-
909
- end
910
- end
911
-
912
- describe "context" do
913
- it 'should escape pipe and backslash characters' do
914
- context = {"caption" => "different = caption", "alt2" => "alt|alternative"}
915
- result = Cloudinary::Utils.encode_context(context)
916
- expect(result).to eq("caption=different \\= caption|alt2=alt\\|alternative")
917
- .or eq("alt2=alt\\|alternative|caption=different \\= caption")
918
-
919
- end
920
- it 'should support symbols' do
921
- context = {:symbol_key => "string_value", "string_key" => :symbol_value}
922
- result = Cloudinary::Utils.encode_context(context)
923
- expect(result).to eq("string_key=symbol_value|symbol_key=string_value")
924
- .or eq("symbol_key=string_value|string_key=symbol_value")
925
- end
926
- end
927
-
928
- describe "customFunction" do
929
- custom_function_wasm = {
930
- :function_type => 'wasm',
931
- :source => 'blur.wasm'
932
- }
933
- custom_function_wasm_str = 'wasm:blur.wasm'
934
-
935
- custom_function_remote = {
936
- :function_type => 'remote',
937
- :source => 'https://df34ra4a.execute-api.us-west-2.amazonaws.com/default/cloudinaryFunction'
938
- }
939
- custom_function_remote_str = 'remote:aHR0cHM6Ly9kZjM0cmE0YS5leGVjdXRlLWFwaS51cy13ZXN0LTIuYW1hem9uYXdzLmNvbS9kZWZhdWx0L2Nsb3VkaW5hcnlGdW5jdGlvbg=='
940
-
941
- it 'should accept a string value' do
942
- actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_wasm_str
943
- expect( actual).to eq("fn_#{custom_function_wasm_str}")
944
- end
945
- it 'should accept a hash of options' do
946
- actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_wasm
947
- expect( actual).to eq("fn_#{custom_function_wasm_str}")
948
- end
949
- it 'should base64 encoded URL for a remote function' do
950
- actual = Cloudinary::Utils.generate_transformation_string :custom_function => custom_function_remote
951
- expect( actual).to eq("fn_#{custom_function_remote_str}")
952
-
953
- end
954
-
955
- it 'should accept a string value' do
956
- actual = Cloudinary::Utils.generate_transformation_string :custom_pre_function => custom_function_wasm_str
957
- expect( actual).to eq("fn_pre:#{custom_function_wasm_str}")
958
- end
959
- it 'should accept a hash of options' do
960
- actual = Cloudinary::Utils.generate_transformation_string :custom_pre_function => custom_function_wasm
961
- expect( actual).to eq("fn_pre:#{custom_function_wasm_str}")
962
- end
963
- it 'should base64 encoded URL for a remote function' do
964
- actual = Cloudinary::Utils.generate_transformation_string :custom_pre_function => custom_function_remote
965
- expect( actual).to eq("fn_pre:#{custom_function_remote_str}")
966
-
967
- end
968
-
969
- end
970
- end