cloudinary 1.0.81 → 1.0.82
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/CHANGELOG +7 -0
- data/lib/cloudinary.rb +2 -2
- data/lib/cloudinary/carrier_wave/storage.rb +3 -1
- data/lib/cloudinary/helper.rb +2 -2
- data/lib/cloudinary/missing.rb +10 -0
- data/lib/cloudinary/utils.rb +3 -5
- data/lib/cloudinary/version.rb +1 -1
- data/spec/cloudinary_helper_spec.rb +19 -7
- data/spec/spec_helper.rb +7 -0
- data/spec/uploader_spec.rb +1 -1
- data/spec/utils_spec.rb +384 -378
- metadata +72 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a6cbd0bda5b871cca87e23ee5b64e551c68c17f
|
4
|
+
data.tar.gz: ebd64c74b999914e26ece99aa312b1e40a91dcec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1166188baf03ded5949a7f55c13d778e2a78aeeb731999a21978ce4bef2dc420a10b58e7e4eae2ad45b776f37535d6c20f493f147004c5e504f24d5116578c05
|
7
|
+
data.tar.gz: dafa9aede45cb6b996fb718adb7d438e3212b070722ec6930d3db53a2dabf528c8582fc9521946bb6ad74f5dde5b1dd32d28de519f938a4a5c0a01530b4ed042
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= Version 1.0.82 - 2015-02-05
|
2
|
+
* Solve problem with CarrierWave integration to newer versions on the mongoid and carrierwave-mongoid gems.
|
3
|
+
* Enable root path for shared CDN:
|
4
|
+
* Modified restriction in utils so that it doesn't fail for root path with shared CDN.
|
5
|
+
* Added Object::present? predicate. Check if Object::present doesn't exist before defining it.
|
6
|
+
* Checking for `defined?(Rails)` is not enough if we want to invoke `Rails.version` etc. It was changed to `defined? Rails::version`.
|
7
|
+
|
1
8
|
= Version 1.0.81 - 2015-01-08
|
2
9
|
* CarrierWave - support default_format if format is unknown, support arbitrary format for resource_type raw.
|
3
10
|
|
data/lib/cloudinary.rb
CHANGED
@@ -77,7 +77,7 @@ module Cloudinary
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def self.app_root
|
80
|
-
if
|
80
|
+
if defined? Rails::root
|
81
81
|
# Rails 2.2 return String for Rails.root
|
82
82
|
Rails.root.is_a?(Pathname) ? Rails.root : Pathname.new(Rails.root)
|
83
83
|
else
|
@@ -89,7 +89,7 @@ module Cloudinary
|
|
89
89
|
|
90
90
|
def self.config_env
|
91
91
|
return ENV["CLOUDINARY_ENV"] if ENV["CLOUDINARY_ENV"]
|
92
|
-
return Rails.env if defined?
|
92
|
+
return Rails.env if defined? Rails::env
|
93
93
|
nil
|
94
94
|
end
|
95
95
|
|
@@ -83,7 +83,9 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
|
|
83
83
|
elsif defined?(Mongoid::Document) && uploader.model.is_a?(Mongoid::Document)
|
84
84
|
# Mongoid support
|
85
85
|
if Mongoid::VERSION.split(".").first.to_i >= 4
|
86
|
-
|
86
|
+
column = column.to_sym
|
87
|
+
uploader.model.write_attribute(column, name)
|
88
|
+
uploader.model.set(column => name)
|
87
89
|
else
|
88
90
|
uploader.model.set(column, name)
|
89
91
|
end
|
data/lib/cloudinary/helper.rb
CHANGED
@@ -235,7 +235,7 @@ module CloudinaryHelper
|
|
235
235
|
if !method_defined?(:image_tag)
|
236
236
|
include ActionView::Helpers::AssetTagHelper
|
237
237
|
end
|
238
|
-
if defined?(Rails) && !Rails.version.start_with?(
|
238
|
+
if defined?(Rails::version) && !Rails.version.start_with?('2') && Cloudinary.config.enhance_image_tag
|
239
239
|
alias_method_chain :image_tag, :cloudinary
|
240
240
|
alias_method_chain :image_path, :cloudinary
|
241
241
|
else
|
@@ -299,7 +299,7 @@ if defined? ActionView::Helpers::AssetUrlHelper
|
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
302
|
-
if defined?(Rails) && Rails.version.start_with?(
|
302
|
+
if defined?(Rails::version) && Rails.version.start_with?('2')
|
303
303
|
ActionView::Base.send :include, ActionView::Helpers::AssetTagHelper
|
304
304
|
ActionView::Base.send :include, CloudinaryHelper
|
305
305
|
end
|
data/lib/cloudinary/missing.rb
CHANGED
@@ -3,6 +3,16 @@ if !nil.respond_to?(:blank?)
|
|
3
3
|
def blank?
|
4
4
|
respond_to?(:empty?) ? empty? : !self
|
5
5
|
end
|
6
|
+
|
7
|
+
if not defined? Object::present?
|
8
|
+
# An object is present if it's not blank.
|
9
|
+
#
|
10
|
+
# @return [true, false]
|
11
|
+
def present?
|
12
|
+
!blank?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
end
|
7
17
|
|
8
18
|
class NilClass #:nodoc:
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -130,11 +130,9 @@ class Cloudinary::Utils
|
|
130
130
|
sign_version = config_option_consume(options, :sign_version) # Deprecated behavior
|
131
131
|
url_suffix = options.delete(:url_suffix)
|
132
132
|
use_root_path = config_option_consume(options, :use_root_path)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
133
|
+
|
134
|
+
raise(CloudinaryException, "URL Suffix only supported in private CDN") if url_suffix.present? and not private_cdn
|
135
|
+
|
138
136
|
original_source = source
|
139
137
|
return original_source if source.blank?
|
140
138
|
if defined?(CarrierWave::Uploader::Base) && source.is_a?(CarrierWave::Uploader::Base)
|
data/lib/cloudinary/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rspec'
|
1
2
|
require 'spec_helper'
|
2
3
|
require 'cloudinary'
|
3
4
|
require 'action_view'
|
@@ -7,7 +8,7 @@ helper_class = Class.new do
|
|
7
8
|
include CloudinaryHelper
|
8
9
|
end
|
9
10
|
|
10
|
-
describe CloudinaryHelper do
|
11
|
+
RSpec.describe CloudinaryHelper do
|
11
12
|
let(:helper) { helper_class.new }
|
12
13
|
|
13
14
|
|
@@ -16,9 +17,14 @@ describe CloudinaryHelper do
|
|
16
17
|
subject(:input) { helper.cl_image_upload_tag(:image_id, options) }
|
17
18
|
|
18
19
|
before do
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
if defined? allow
|
21
|
+
allow(Cloudinary::Utils).to receive_messages :cloudinary_api_url => '', :sign_request => Hash.new
|
22
|
+
allow(helper).to receive(:build_callback_url).and_return('')
|
23
|
+
else
|
24
|
+
Cloudinary::Utils.should_receive(:cloudinary_api_url).and_return('')
|
25
|
+
Cloudinary::Utils.should_receive(:sign_request).and_return(Hash.new)
|
26
|
+
helper.should_receive(:build_callback_url).and_return('')
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
it "allow multiple upload" do
|
@@ -29,19 +35,25 @@ describe CloudinaryHelper do
|
|
29
35
|
end
|
30
36
|
|
31
37
|
context "#cl_image_tag" do
|
32
|
-
subject(:input) { helper.cl_image_tag(
|
38
|
+
subject(:input) { helper.cl_image_tag('sample.jpg', options) }
|
33
39
|
|
34
40
|
context "responsive_width" do
|
35
41
|
let(:options) { {responsive_width: true, cloud_name: "test"} }
|
36
42
|
it "should use data-src for responsive_width" do
|
37
|
-
|
43
|
+
img_tag = html_tag_matcher 'img'
|
44
|
+
expect(input).to match img_tag
|
45
|
+
expect(input).to include('class="cld-responsive"')
|
46
|
+
expect(input).to include( 'data-src="http://res.cloudinary.com/test/image/upload/c_limit,w_auto/sample.jpg"')
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
50
|
context "dpr_auto" do
|
42
51
|
let(:options) { {dpr: :auto, cloud_name: "test"} }
|
43
52
|
it "should use data-src for dpr auto" do
|
44
|
-
|
53
|
+
img_tag = html_tag_matcher 'img'
|
54
|
+
expect(input).to match(img_tag)
|
55
|
+
expect(input).to include('data-src="http://res.cloudinary.com/test/image/upload/dpr_auto/sample.jpg"')
|
56
|
+
expect(input).to include('class="cld-hidpi"')
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,3 +4,10 @@ RSpec.configure do |config|
|
|
4
4
|
config.run_all_when_everything_filtered = true
|
5
5
|
config.filter_run_excluding :delete_all => true
|
6
6
|
end
|
7
|
+
|
8
|
+
# Create a regexp with the given tag name.
|
9
|
+
# @param [String or Symbol] tag tag name (e.g. `img`)
|
10
|
+
# @return [Regexp] the regular expression to match the tag
|
11
|
+
def html_tag_matcher( tag)
|
12
|
+
/<#{tag}([\s]+[-[:word:]]+[\s]*\=\s*\"[^\"]*\")*\s*>.*<\s*\/#{tag}\s*>/
|
13
|
+
end
|
data/spec/uploader_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe Cloudinary::Uploader do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should successfully upload file by url" do
|
21
|
-
result = Cloudinary::Uploader.upload("http://cloudinary.com/images/
|
21
|
+
result = Cloudinary::Uploader.upload("http://cloudinary.com/images/old_logo.png")
|
22
22
|
expect(result["width"]).to eq(241)
|
23
23
|
expect(result["height"]).to eq(51)
|
24
24
|
expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
|
data/spec/utils_spec.rb
CHANGED
@@ -1,378 +1,384 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'cloudinary'
|
3
|
-
|
4
|
-
describe Cloudinary::Utils do
|
5
|
-
before(:each) do
|
6
|
-
Cloudinary.config do
|
7
|
-
|config|
|
8
|
-
config.cloud_name = "test123"
|
9
|
-
config.secure_distribution = nil
|
10
|
-
config.private_cdn = false
|
11
|
-
config.secure = false
|
12
|
-
config.cname = nil
|
13
|
-
config.cdn_subdomain = false
|
14
|
-
config.api_key = "1234"
|
15
|
-
config.api_secret = "b"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_cloudinary_url(public_id, options, expected_url, expected_options)
|
20
|
-
url = Cloudinary::Utils.cloudinary_url(public_id, options)
|
21
|
-
expect(url).to eq(expected_url)
|
22
|
-
expect(options).to eq(expected_options)
|
23
|
-
url
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should use cloud_name from config" do
|
27
|
-
test_cloudinary_url("test", {}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should allow overriding cloud_name in options" do
|
31
|
-
test_cloudinary_url("test", {:cloud_name=>"test321"}, "http://res.cloudinary.com/test321/image/upload/test", {})
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should use default secure distribution if secure=true" do
|
35
|
-
test_cloudinary_url("test", {:secure=>true}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should allow overriding secure distribution if secure=true" do
|
39
|
-
test_cloudinary_url("test", {:secure=>true, :secure_distribution=>"something.else.com"}, "https://something.else.com/test123/image/upload/test", {})
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should take secure distribution from config if secure=true" do
|
43
|
-
Cloudinary.config.secure_distribution = "config.secure.distribution.com"
|
44
|
-
test_cloudinary_url("test", {:secure=>true}, "https://config.secure.distribution.com/test123/image/upload/test", {})
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should default to akamai if secure is given with private_cdn and no secure_distribution" do
|
48
|
-
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true}, "https://test123-res.cloudinary.com/image/upload/test", {})
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should not add cloud_name if secure private_cdn and secure non akamai secure_distribution" do
|
52
|
-
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true, :secure_distribution=>"something.cloudfront.net"}, "https://something.cloudfront.net/image/upload/test", {})
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should allow overriding private_cdn if private_cdn=true" do
|
56
|
-
test_cloudinary_url("test", {:private_cdn => true}, "http://test123-res.cloudinary.com/image/upload/test", {})
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should allow overriding private_cdn if private_cdn=false" do
|
60
|
-
Cloudinary.config.private_cdn = true
|
61
|
-
test_cloudinary_url("test", {:private_cdn => false}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should allow overriding cname if cname=example.com" do
|
65
|
-
test_cloudinary_url("test", {:cname => "example.com"}, "http://example.com/test123/image/upload/test", {})
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should allow overriding cname if cname=false" do
|
69
|
-
Cloudinary.config.cname = "example.com"
|
70
|
-
test_cloudinary_url("test", {:cname => nil}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should use format from options" do
|
74
|
-
test_cloudinary_url("test", {:format=>:jpg}, "http://res.cloudinary.com/test123/image/upload/test.jpg", {})
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should disallow url_suffix in shared distribution" do
|
78
|
-
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello"})}.to raise_error(CloudinaryException)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should disallow url_suffix in non upload types" do
|
82
|
-
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should disallow url_suffix with / or ." do
|
86
|
-
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello/world", :private_cdn=>true})}.to raise_error(CloudinaryException)
|
87
|
-
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello.world", :private_cdn=>true})}.to raise_error(CloudinaryException)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should support url_suffix for private_cdn" do
|
91
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true}, "http://test123-res.cloudinary.com/images/test/hello", {})
|
92
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :angle=>0, :private_cdn=>true}, "http://test123-res.cloudinary.com/images/a_0/test/hello", {})
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should put format after url_suffix" do
|
96
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg"}, "http://test123-res.cloudinary.com/images/test/hello.jpg", {})
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should not sign the url_suffix" do
|
100
|
-
expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
|
101
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :sign_url=>true}, "http://test123-res.cloudinary.com/images/#{expected_signture}/test/hello.jpg", {})
|
102
|
-
|
103
|
-
expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :angle=>0, :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
|
104
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :angle=>0, :sign_url=>true}, "http://test123-res.cloudinary.com/images/#{expected_signture}/a_0/test/hello.jpg", {})
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should support url_suffix for raw uploads" do
|
108
|
-
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :resource_type=>:raw}, "http://test123-res.cloudinary.com/files/test/hello", {})
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
test_cloudinary_url("test", {:width=>100, :height=>100
|
137
|
-
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not pass width and height to html in case
|
141
|
-
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
test_cloudinary_url("
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should
|
192
|
-
test_cloudinary_url("
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
test_cloudinary_url("test", {"
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
test_cloudinary_url("test", {"
|
294
|
-
test_cloudinary_url("test", {"
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
it "build_upload_params
|
304
|
-
options = {:
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
it "should
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
test_cloudinary_url("image.jpg", {:
|
358
|
-
test_cloudinary_url("image.jpg", {:
|
359
|
-
test_cloudinary_url("image.
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
end
|
373
|
-
|
374
|
-
it "should
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cloudinary'
|
3
|
+
|
4
|
+
describe Cloudinary::Utils do
|
5
|
+
before(:each) do
|
6
|
+
Cloudinary.config do
|
7
|
+
|config|
|
8
|
+
config.cloud_name = "test123"
|
9
|
+
config.secure_distribution = nil
|
10
|
+
config.private_cdn = false
|
11
|
+
config.secure = false
|
12
|
+
config.cname = nil
|
13
|
+
config.cdn_subdomain = false
|
14
|
+
config.api_key = "1234"
|
15
|
+
config.api_secret = "b"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_cloudinary_url(public_id, options, expected_url, expected_options)
|
20
|
+
url = Cloudinary::Utils.cloudinary_url(public_id, options)
|
21
|
+
expect(url).to eq(expected_url)
|
22
|
+
expect(options).to eq(expected_options)
|
23
|
+
url
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should use cloud_name from config" do
|
27
|
+
test_cloudinary_url("test", {}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should allow overriding cloud_name in options" do
|
31
|
+
test_cloudinary_url("test", {:cloud_name=>"test321"}, "http://res.cloudinary.com/test321/image/upload/test", {})
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should use default secure distribution if secure=true" do
|
35
|
+
test_cloudinary_url("test", {:secure=>true}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow overriding secure distribution if secure=true" do
|
39
|
+
test_cloudinary_url("test", {:secure=>true, :secure_distribution=>"something.else.com"}, "https://something.else.com/test123/image/upload/test", {})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should take secure distribution from config if secure=true" do
|
43
|
+
Cloudinary.config.secure_distribution = "config.secure.distribution.com"
|
44
|
+
test_cloudinary_url("test", {:secure=>true}, "https://config.secure.distribution.com/test123/image/upload/test", {})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should default to akamai if secure is given with private_cdn and no secure_distribution" do
|
48
|
+
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true}, "https://test123-res.cloudinary.com/image/upload/test", {})
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not add cloud_name if secure private_cdn and secure non akamai secure_distribution" do
|
52
|
+
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true, :secure_distribution=>"something.cloudfront.net"}, "https://something.cloudfront.net/image/upload/test", {})
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should allow overriding private_cdn if private_cdn=true" do
|
56
|
+
test_cloudinary_url("test", {:private_cdn => true}, "http://test123-res.cloudinary.com/image/upload/test", {})
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow overriding private_cdn if private_cdn=false" do
|
60
|
+
Cloudinary.config.private_cdn = true
|
61
|
+
test_cloudinary_url("test", {:private_cdn => false}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should allow overriding cname if cname=example.com" do
|
65
|
+
test_cloudinary_url("test", {:cname => "example.com"}, "http://example.com/test123/image/upload/test", {})
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should allow overriding cname if cname=false" do
|
69
|
+
Cloudinary.config.cname = "example.com"
|
70
|
+
test_cloudinary_url("test", {:cname => nil}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should use format from options" do
|
74
|
+
test_cloudinary_url("test", {:format=>:jpg}, "http://res.cloudinary.com/test123/image/upload/test.jpg", {})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should disallow url_suffix in shared distribution" do
|
78
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello"})}.to raise_error(CloudinaryException)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should disallow url_suffix in non upload types" do
|
82
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should disallow url_suffix with / or ." do
|
86
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello/world", :private_cdn=>true})}.to raise_error(CloudinaryException)
|
87
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello.world", :private_cdn=>true})}.to raise_error(CloudinaryException)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should support url_suffix for private_cdn" do
|
91
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true}, "http://test123-res.cloudinary.com/images/test/hello", {})
|
92
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :angle=>0, :private_cdn=>true}, "http://test123-res.cloudinary.com/images/a_0/test/hello", {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should put format after url_suffix" do
|
96
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg"}, "http://test123-res.cloudinary.com/images/test/hello.jpg", {})
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not sign the url_suffix" do
|
100
|
+
expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
|
101
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :sign_url=>true}, "http://test123-res.cloudinary.com/images/#{expected_signture}/test/hello.jpg", {})
|
102
|
+
|
103
|
+
expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :angle=>0, :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
|
104
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :angle=>0, :sign_url=>true}, "http://test123-res.cloudinary.com/images/#{expected_signture}/a_0/test/hello.jpg", {})
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should support url_suffix for raw uploads" do
|
108
|
+
test_cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :resource_type=>:raw}, "http://test123-res.cloudinary.com/files/test/hello", {})
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'root_path support' do
|
112
|
+
|
113
|
+
it "should allow use_root_path in shared distribution" do
|
114
|
+
# expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true})}.to raise_error(CloudinaryException)
|
115
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>false}, "http://res.cloudinary.com/test123/test", {})
|
116
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>false, :angle=>0}, "http://res.cloudinary.com/test123/a_0/test", {})
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should support use_root_path for private_cdn" do
|
120
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true}, "http://test123-res.cloudinary.com/test", {})
|
121
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :angle=>0}, "http://test123-res.cloudinary.com/a_0/test", {})
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should support use_root_path together with url_suffix for private_cdn" do
|
125
|
+
test_cloudinary_url("test", {:use_root_path=>true, :url_suffix=>"hello", :private_cdn=>true}, "http://test123-res.cloudinary.com/test/hello", {})
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should disallow use_root_path if not image/upload" do
|
129
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
|
130
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :resource_type=>:raw})}.to raise_error(CloudinaryException)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should use width and height from options only if crop is given" do
|
136
|
+
test_cloudinary_url("test", {:width=>100, :height=>100}, "http://res.cloudinary.com/test123/image/upload/test", {:width=>100, :height=>100})
|
137
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:crop}, "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/test", {:width=>100, :height=>100})
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not pass width and height to html in case of fit, lfill or limit crop" do
|
141
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:limit}, "http://res.cloudinary.com/test123/image/upload/c_limit,h_100,w_100/test", {})
|
142
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:lfill}, "http://res.cloudinary.com/test123/image/upload/c_lfill,h_100,w_100/test", {})
|
143
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:fit}, "http://res.cloudinary.com/test123/image/upload/c_fit,h_100,w_100/test", {})
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should not pass width and height to html in case angle was used" do
|
147
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:scale, :angle=>:auto}, "http://res.cloudinary.com/test123/image/upload/a_auto,c_scale,h_100,w_100/test", {})
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should use x, y, radius, prefix, gravity and quality from options" do
|
151
|
+
test_cloudinary_url("test", {:x=>1, :y=>2, :radius=>3, :gravity=>:center, :quality=>0.4, :prefix=>"a"}, "http://res.cloudinary.com/test123/image/upload/g_center,p_a,q_0.4,r_3,x_1,y_2/test", {})
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should support named tranformation" do
|
155
|
+
test_cloudinary_url("test", {:transformation=>"blip"}, "http://res.cloudinary.com/test123/image/upload/t_blip/test", {})
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should support array of named tranformations" do
|
159
|
+
test_cloudinary_url("test", {:transformation=>["blip", "blop"]}, "http://res.cloudinary.com/test123/image/upload/t_blip.blop/test", {})
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should support base tranformation" do
|
163
|
+
test_cloudinary_url("test", {:transformation=>{:x=>100, :y=>100, :crop=>:fill}, :crop=>:crop, :width=>100}, "http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/c_crop,w_100/test", {:width=>100})
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should support array of base tranformations" do
|
167
|
+
test_cloudinary_url("test", {:transformation=>[{:x=>100, :y=>100, :width=>200, :crop=>:fill}, {:radius=>10}], :crop=>:crop, :width=>100}, "http://res.cloudinary.com/test123/image/upload/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test", {:width=>100})
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should support array of tranformations" do
|
171
|
+
result = Cloudinary::Utils.generate_transformation_string([{:x=>100, :y=>100, :width=>200, :crop=>:fill}, {:radius=>10}])
|
172
|
+
expect(result).to eq("c_fill,w_200,x_100,y_100/r_10")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not include empty tranformations" do
|
176
|
+
test_cloudinary_url("test", {:transformation=>[{}, {:x=>100, :y=>100, :crop=>:fill}, {}]}, "http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/test", {})
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should support size" do
|
180
|
+
test_cloudinary_url("test", {:size=>"10x10", :crop=>:crop}, "http://res.cloudinary.com/test123/image/upload/c_crop,h_10,w_10/test", {:width=>"10", :height=>"10"})
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should use type from options" do
|
184
|
+
test_cloudinary_url("test", {:type=>:facebook}, "http://res.cloudinary.com/test123/image/facebook/test", {})
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should use resource_type from options" do
|
188
|
+
test_cloudinary_url("test", {:resource_type=>:raw}, "http://res.cloudinary.com/test123/raw/upload/test", {})
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should ignore http links only if type is not given or is asset" do
|
192
|
+
test_cloudinary_url("http://test", {:type=>nil}, "http://test", {})
|
193
|
+
test_cloudinary_url("http://test", {:type=>:asset}, "http://test", {})
|
194
|
+
test_cloudinary_url("http://test", {:type=>:fetch}, "http://res.cloudinary.com/test123/image/fetch/http://test" , {})
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should use allow absolute links to /images" do
|
198
|
+
test_cloudinary_url("/images/test", {}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should use ignore absolute links not to /images" do
|
202
|
+
test_cloudinary_url("/js/test", {}, "/js/test", {})
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should escape fetch urls" do
|
206
|
+
test_cloudinary_url("http://blah.com/hello?a=b", {:type=>:fetch}, "http://res.cloudinary.com/test123/image/fetch/http://blah.com/hello%3Fa%3Db", {})
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should should escape http urls" do
|
210
|
+
test_cloudinary_url("http://www.youtube.com/watch?v=d9NF2edxy-M", {:type=>:youtube}, "http://res.cloudinary.com/test123/image/youtube/http://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M", {})
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should support background" do
|
214
|
+
test_cloudinary_url("test", {:background=>"red"}, "http://res.cloudinary.com/test123/image/upload/b_red/test", {})
|
215
|
+
test_cloudinary_url("test", {:background=>"#112233"}, "http://res.cloudinary.com/test123/image/upload/b_rgb:112233/test", {})
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should support default_image" do
|
219
|
+
test_cloudinary_url("test", {:default_image=>"default"}, "http://res.cloudinary.com/test123/image/upload/d_default/test", {})
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should support angle" do
|
223
|
+
test_cloudinary_url("test", {:angle=>"55"}, "http://res.cloudinary.com/test123/image/upload/a_55/test", {})
|
224
|
+
test_cloudinary_url("test", {:angle=>["auto", "55"]}, "http://res.cloudinary.com/test123/image/upload/a_auto.55/test", {})
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should support format for fetch urls" do
|
228
|
+
test_cloudinary_url("http://cloudinary.com/images/logo.png", {:format=>"jpg", :type=>:fetch}, "http://res.cloudinary.com/test123/image/fetch/f_jpg/http://cloudinary.com/images/logo.png", {})
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should support effect" do
|
232
|
+
test_cloudinary_url("test", {:effect=>"sepia"}, "http://res.cloudinary.com/test123/image/upload/e_sepia/test", {})
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should support effect with hash param" do
|
236
|
+
test_cloudinary_url("test", {:effect=>{"sepia"=>10}}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should support effect with array param" do
|
240
|
+
test_cloudinary_url("test", {:effect=>["sepia", 10]}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
241
|
+
end
|
242
|
+
|
243
|
+
{:overlay=>:l, :underlay=>:u}.each do |param, letter|
|
244
|
+
it "should support #{param}" do
|
245
|
+
test_cloudinary_url("test", {param=>"text:hello"}, "http://res.cloudinary.com/test123/image/upload/#{letter}_text:hello/test", {})
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should not pass width/height to html for #{param}" do
|
249
|
+
test_cloudinary_url("test", {param=>"text:hello", :height=>100, :width=>100}, "http://res.cloudinary.com/test123/image/upload/h_100,#{letter}_text:hello,w_100/test", {})
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should use ssl_detected if secure is not given as parameter and not set to true in configuration" do
|
254
|
+
test_cloudinary_url("test", {:ssl_detected=>true}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should use secure if given over ssl_detected and configuration" do
|
258
|
+
Cloudinary.config.secure = true
|
259
|
+
test_cloudinary_url("test", {:ssl_detected=>true, :secure=>false}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should use secure: true from configuration over ssl_detected" do
|
263
|
+
Cloudinary.config.secure = true
|
264
|
+
test_cloudinary_url("test", {:ssl_detected=>false}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should support extenal cname" do
|
268
|
+
test_cloudinary_url("test", {:cname=>"hello.com"}, "http://hello.com/test123/image/upload/test", {})
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should support extenal cname with cdn_subdomain on" do
|
272
|
+
test_cloudinary_url("test", {:cname=>"hello.com", :cdn_subdomain=>true}, "http://a2.hello.com/test123/image/upload/test", {})
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should support cdn_subdomain with secure on if using shared_domain" do
|
276
|
+
test_cloudinary_url("test", {:secure=>true, :cdn_subdomain=>true}, "https://res-2.cloudinary.com/test123/image/upload/test", {})
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should support secure_cdn_subdomain false override with secure" do
|
280
|
+
test_cloudinary_url("test", {:secure=>true, :cdn_subdomain=>true, :secure_cdn_subdomain=>false}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should support secure_cdn_subdomain true override with secure" do
|
284
|
+
test_cloudinary_url("test", {:secure=>true, :cdn_subdomain=>true, :secure_cdn_subdomain=>true, :private_cdn=>true}, "https://test123-res-2.cloudinary.com/image/upload/test", {})
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should support string param" do
|
288
|
+
test_cloudinary_url("test", {"effect"=>{"sepia"=>10}}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should support border" do
|
292
|
+
test_cloudinary_url("test", {"border"=>{:width=>5}}, "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_black/test", {})
|
293
|
+
test_cloudinary_url("test", {"border"=>{:width=>5, :color=>"#ffaabbdd"}}, "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_rgb:ffaabbdd/test", {})
|
294
|
+
test_cloudinary_url("test", {"border"=>"1px_solid_blue"}, "http://res.cloudinary.com/test123/image/upload/bo_1px_solid_blue/test", {})
|
295
|
+
test_cloudinary_url("test", {"border"=>"2"}, "http://res.cloudinary.com/test123/image/upload/test", {:border=>"2"})
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should support flags" do
|
299
|
+
test_cloudinary_url("test", {"flags"=>"abc"}, "http://res.cloudinary.com/test123/image/upload/fl_abc/test", {})
|
300
|
+
test_cloudinary_url("test", {"flags"=>["abc", "def"]}, "http://res.cloudinary.com/test123/image/upload/fl_abc.def/test", {})
|
301
|
+
end
|
302
|
+
|
303
|
+
it "build_upload_params should not destroy options" do
|
304
|
+
options = {:width=>100, :crop=>:scale}
|
305
|
+
expect(Cloudinary::Uploader.build_upload_params(options)[:transformation]).to eq("c_scale,w_100")
|
306
|
+
expect(options.length).to eq(2)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "build_upload_params canonize booleans" do
|
310
|
+
options = {:backup=>true, :use_filename=>false, :colors=>"true", :exif=>"false", :colors=>:true,
|
311
|
+
:image_metadata=>:false, :invalidate=>1, :eager_async=>"1"}
|
312
|
+
params = Cloudinary::Uploader.build_upload_params(options)
|
313
|
+
expect(Cloudinary::Api.only(params, *options.keys)).to eq(
|
314
|
+
:backup=>1, :use_filename=>0, :colors=>1, :exif=>0, :colors=>1,
|
315
|
+
:image_metadata=>0, :invalidate=>1, :eager_async=>1
|
316
|
+
)
|
317
|
+
expect(Cloudinary::Uploader.build_upload_params(:backup=>nil)[:backup]).to be_nil
|
318
|
+
expect(Cloudinary::Uploader.build_upload_params({})[:backup]).to be_nil
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should add version if public_id contains /" do
|
322
|
+
test_cloudinary_url("folder/test", {}, "http://res.cloudinary.com/test123/image/upload/v1/folder/test", {})
|
323
|
+
test_cloudinary_url("folder/test", {:version=>123}, "http://res.cloudinary.com/test123/image/upload/v123/folder/test", {})
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should not add version if public_id contains version already" do
|
327
|
+
test_cloudinary_url("v1234/test", {}, "http://res.cloudinary.com/test123/image/upload/v1234/test", {})
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should allow to shorted image/upload urls" do
|
331
|
+
test_cloudinary_url("test", {:shorten=>true}, "http://res.cloudinary.com/test123/iu/test", {})
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should allow to use folders in PreloadedFile" do
|
335
|
+
signature = Cloudinary::Utils.api_sign_request({:public_id=>"folder/file", :version=>"1234"}, Cloudinary.config.api_secret)
|
336
|
+
preloaded = Cloudinary::PreloadedFile.new("image/upload/v1234/folder/file.jpg#" + signature)
|
337
|
+
expect(preloaded).to be_valid
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should escape public_ids" do
|
341
|
+
[
|
342
|
+
["a b", "a%20b"],
|
343
|
+
["a+b", "a%2Bb"],
|
344
|
+
["a%20b", "a%20b"],
|
345
|
+
["a-b", "a-b"],
|
346
|
+
["a??b", "a%3F%3Fb"],
|
347
|
+
["parentheses(interject)", "parentheses%28interject%29"]
|
348
|
+
].each do
|
349
|
+
|source, target|
|
350
|
+
expect(Cloudinary::Utils.cloudinary_url(source)).to eq("http://res.cloudinary.com/test123/image/upload/#{target}")
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should correctly sign URLs", :signed => true do
|
355
|
+
test_cloudinary_url("image.jpg", {:version => 1234, :transformation => {:crop => "crop", :width => 10, :height => 20}, :sign_url => true}, "http://res.cloudinary.com/test123/image/upload/s--Ai4Znfl3--/c_crop,h_20,w_10/v1234/image.jpg", {})
|
356
|
+
test_cloudinary_url("image.jpg", {:version => 1234, :sign_url => true}, "http://res.cloudinary.com/test123/image/upload/s----SjmNDA--/v1234/image.jpg", {})
|
357
|
+
test_cloudinary_url("image.jpg", {:transformation => {:crop => "crop", :width => 10, :height => 20}, :sign_url => true}, "http://res.cloudinary.com/test123/image/upload/s--Ai4Znfl3--/c_crop,h_20,w_10/image.jpg", {})
|
358
|
+
test_cloudinary_url("image.jpg", {:transformation => {:crop => "crop", :width => 10, :height => 20}, :type => :authenticated, :sign_url => true}, "http://res.cloudinary.com/test123/image/authenticated/s--Ai4Znfl3--/c_crop,h_20,w_10/image.jpg", {})
|
359
|
+
test_cloudinary_url("http://google.com/path/to/image.png", {:type => "fetch", :version => 1234, :sign_url => true}, "http://res.cloudinary.com/test123/image/fetch/s--hH_YcbiS--/v1234/http://google.com/path/to/image.png", {})
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should correctly sign URLs in deprecated sign_version mode", :signed => true do
|
363
|
+
test_cloudinary_url("image.jpg", {:version => 1234, :transformation => {:crop => "crop", :width => 10, :height => 20}, :sign_url => true, :sign_version => true}, "http://res.cloudinary.com/test123/image/upload/s--MaRXzoEC--/c_crop,h_20,w_10/v1234/image.jpg", {})
|
364
|
+
test_cloudinary_url("image.jpg", {:version => 1234, :sign_url => true, :sign_version => true}, "http://res.cloudinary.com/test123/image/upload/s--ZlgFLQcO--/v1234/image.jpg", {})
|
365
|
+
test_cloudinary_url("image.jpg", {:transformation => {:crop => "crop", :width => 10, :height => 20}, :sign_url => true, :sign_version => true}, "http://res.cloudinary.com/test123/image/upload/s--Ai4Znfl3--/c_crop,h_20,w_10/image.jpg", {})
|
366
|
+
test_cloudinary_url("http://google.com/path/to/image.png", {:type => "fetch", :version => 1234, :sign_url => true, :sign_version => true}, "http://res.cloudinary.com/test123/image/fetch/s--_GAUclyB--/v1234/http://google.com/path/to/image.png", {})
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should correctly sign_request" do
|
370
|
+
params = Cloudinary::Utils.sign_request({:public_id=>"folder/file", :version=>"1234"})
|
371
|
+
expect(params).to eq(:public_id=>"folder/file", :version=>"1234", :signature=>"7a3349cbb373e4812118d625047ede50b90e7b67", :api_key=>"1234")
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should support responsive width" do
|
375
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:crop, :responsive_width=>true}, "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/c_limit,w_auto/test", {responsive: true})
|
376
|
+
Cloudinary.config.responsive_width_transformation = {:width => :auto, :crop => :pad}
|
377
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:crop, :responsive_width=>true}, "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/c_pad,w_auto/test", {responsive: true})
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should correctly encode double arrays" do
|
381
|
+
expect(Cloudinary::Utils.encode_double_array([1,2,3,4])).to eq("1,2,3,4")
|
382
|
+
expect(Cloudinary::Utils.encode_double_array([[1,2,3,4],[5,6,7,8]])).to eq("1,2,3,4|5,6,7,8")
|
383
|
+
end
|
384
|
+
end
|
metadata
CHANGED
@@ -1,67 +1,84 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudinary
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.82
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Nadav Soferman
|
8
8
|
- Itai Lahan
|
9
9
|
- Tal Lev-Ami
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
17
16
|
name: rest-client
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: "0"
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws_cf_signer
|
29
23
|
prerelease: false
|
30
|
-
|
31
|
-
requirements:
|
32
|
-
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: aws_cf_signer
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
33
36
|
type: :runtime
|
34
|
-
version_requirements: *id003
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
37
|
prerelease: false
|
38
|
-
|
39
|
-
requirements:
|
40
|
-
-
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
41
50
|
type: :development
|
42
|
-
version_requirements: *id004
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: actionpack
|
45
51
|
prerelease: false
|
46
|
-
|
47
|
-
requirements:
|
48
|
-
-
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: actionpack
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
49
64
|
type: :development
|
50
|
-
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
51
71
|
description: Client library for easily using the Cloudinary service
|
52
|
-
email:
|
72
|
+
email:
|
53
73
|
- nadav.soferman@cloudinary.com
|
54
74
|
- itai.lahan@cloudinary.com
|
55
75
|
- tal.levami@cloudinary.com
|
56
76
|
executables: []
|
57
|
-
|
58
77
|
extensions: []
|
59
|
-
|
60
78
|
extra_rdoc_files: []
|
61
|
-
|
62
|
-
|
63
|
-
- .
|
64
|
-
- .rspec
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".rspec"
|
65
82
|
- CHANGELOG
|
66
83
|
- Gemfile
|
67
84
|
- README.md
|
@@ -111,29 +128,30 @@ files:
|
|
111
128
|
- vendor/assets/javascripts/cloudinary/load-image.min.js
|
112
129
|
- vendor/assets/javascripts/cloudinary/processing.js
|
113
130
|
homepage: http://cloudinary.com
|
114
|
-
licenses:
|
131
|
+
licenses:
|
115
132
|
- MIT
|
116
133
|
metadata: {}
|
117
|
-
|
118
134
|
post_install_message:
|
119
135
|
rdoc_options: []
|
120
|
-
|
121
|
-
require_paths:
|
136
|
+
require_paths:
|
122
137
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
requirements:
|
125
|
-
-
|
126
|
-
|
127
|
-
|
128
|
-
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
129
148
|
requirements: []
|
130
|
-
|
131
149
|
rubyforge_project: cloudinary
|
132
|
-
rubygems_version: 2.4.
|
150
|
+
rubygems_version: 2.4.5
|
133
151
|
signing_key:
|
134
152
|
specification_version: 4
|
135
153
|
summary: Client library for easily using the Cloudinary service
|
136
|
-
test_files:
|
154
|
+
test_files:
|
137
155
|
- spec/api_spec.rb
|
138
156
|
- spec/cloudinary_helper_spec.rb
|
139
157
|
- spec/docx.docx
|