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