cloudinary 1.0.78 → 1.0.79
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/lib/cloudinary/api.rb +8 -0
- data/lib/cloudinary/carrier_wave/preloaded.rb +2 -2
- data/lib/cloudinary/carrier_wave/process.rb +42 -34
- data/lib/cloudinary/uploader.rb +1 -0
- data/lib/cloudinary/utils.rb +95 -27
- data/lib/cloudinary/version.rb +1 -1
- data/spec/api_spec.rb +111 -94
- data/spec/uploader_spec.rb +33 -33
- data/spec/utils_spec.rb +160 -268
- metadata +2 -2
data/spec/uploader_spec.rb
CHANGED
@@ -6,41 +6,41 @@ describe Cloudinary::Uploader do
|
|
6
6
|
|
7
7
|
it "should successfully upload file" do
|
8
8
|
result = Cloudinary::Uploader.upload("spec/logo.png")
|
9
|
-
result["width"].
|
10
|
-
result["height"].
|
9
|
+
expect(result["width"]).to eq(241)
|
10
|
+
expect(result["height"]).to eq(51)
|
11
11
|
expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
|
12
|
-
result["signature"].
|
12
|
+
expect(result["signature"]).to eq(expected_signature)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should successfully upload a file from pathname", :pathname => true do
|
16
16
|
result = Cloudinary::Uploader.upload(Pathname.new("spec/logo.png"))
|
17
|
-
result["width"].
|
17
|
+
expect(result["width"]).to eq(241)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should successfully upload file by url" do
|
21
21
|
result = Cloudinary::Uploader.upload("http://cloudinary.com/images/logo.png")
|
22
|
-
result["width"].
|
23
|
-
result["height"].
|
22
|
+
expect(result["width"]).to eq(241)
|
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)
|
25
|
-
result["signature"].
|
25
|
+
expect(result["signature"]).to eq(expected_signature)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should successfully rename a file" do
|
29
29
|
result = Cloudinary::Uploader.upload("spec/logo.png")
|
30
30
|
Cloudinary::Uploader.rename(result["public_id"], result["public_id"]+"2")
|
31
|
-
Cloudinary::Api.resource(result["public_id"]+"2").
|
31
|
+
expect(Cloudinary::Api.resource(result["public_id"]+"2")).not_to be_nil
|
32
32
|
|
33
33
|
result2 = Cloudinary::Uploader.upload("spec/favicon.ico")
|
34
|
-
|
34
|
+
expect{Cloudinary::Uploader.rename(result2["public_id"], result["public_id"]+"2")}.to raise_error
|
35
35
|
Cloudinary::Uploader.rename(result2["public_id"], result["public_id"]+"2", :overwrite=>true)
|
36
36
|
|
37
|
-
Cloudinary::Api.resource(result["public_id"]+"2")["format"].
|
37
|
+
expect(Cloudinary::Api.resource(result["public_id"]+"2")["format"]).to eq("ico")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should support explicit" do
|
41
41
|
result = Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}])
|
42
42
|
url = Cloudinary::Utils.cloudinary_url("cloudinary", :type=>"twitter_name", :crop=>"scale", :width=>"2.0", :format=>"png", :version=>result["version"])
|
43
|
-
result["eager"][0]["url"].
|
43
|
+
expect(result["eager"][0]["url"]).to eq(url)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should support eager" do
|
@@ -54,85 +54,85 @@ describe Cloudinary::Uploader do
|
|
54
54
|
|
55
55
|
it "should successfully generate text image" do
|
56
56
|
result = Cloudinary::Uploader.text("hello world")
|
57
|
-
result["width"].
|
58
|
-
result["height"].
|
57
|
+
expect(result["width"]).to be > 1
|
58
|
+
expect(result["height"]).to be > 1
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should correctly handle tags" do
|
62
62
|
result = Cloudinary::Uploader.upload("spec/logo.png")
|
63
63
|
Cloudinary::Uploader.add_tag("tag1", result["public_id"])
|
64
64
|
Cloudinary::Uploader.add_tag("tag2", result["public_id"])
|
65
|
-
Cloudinary::Api.resource(result["public_id"])["tags"].
|
65
|
+
expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag1", "tag2"])
|
66
66
|
Cloudinary::Uploader.remove_tag("tag1", result["public_id"])
|
67
|
-
Cloudinary::Api.resource(result["public_id"])["tags"].
|
67
|
+
expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag2"])
|
68
68
|
Cloudinary::Uploader.replace_tag("tag3", result["public_id"])
|
69
|
-
Cloudinary::Api.resource(result["public_id"])["tags"].
|
69
|
+
expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag3"])
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should correctly handle unique_filename" do
|
73
73
|
result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true)
|
74
|
-
result["public_id"].
|
74
|
+
expect(result["public_id"]).to match(/logo_[a-zA-Z0-9]{6}/)
|
75
75
|
result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true, :unique_filename => false)
|
76
|
-
result["public_id"].
|
76
|
+
expect(result["public_id"]).to eq("logo")
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should allow whitelisted formats if allowed_formats", :allowed=>true do
|
80
80
|
result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["png"])
|
81
|
-
result["format"].
|
81
|
+
expect(result["format"]).to eq("png")
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should prevent non whitelisted formats from being uploaded if allowed_formats is specified", :allowed=>true do
|
85
|
-
|
85
|
+
expect{Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"])}.to raise_error
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should allow non whitelisted formats if type is specified and convert to that type", :allowed=>true do
|
89
89
|
result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"], :format => "jpg")
|
90
|
-
result["format"].
|
90
|
+
expect(result["format"]).to eq("jpg")
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should allow sending face coordinates" do
|
94
94
|
coordinates = [[120, 30, 109, 150], [121, 31, 110, 151]]
|
95
95
|
result = Cloudinary::Uploader.upload("spec/logo.png", {:face_coordinates => coordinates, :faces => true})
|
96
|
-
result["faces"].
|
96
|
+
expect(result["faces"]).to eq(coordinates)
|
97
97
|
|
98
98
|
different_coordinates = [[122, 32, 111, 152]]
|
99
99
|
Cloudinary::Uploader.explicit(result["public_id"], {:face_coordinates => different_coordinates, :faces => true, :type => "upload"})
|
100
100
|
info = Cloudinary::Api.resource(result["public_id"], {:faces => true})
|
101
|
-
info["faces"].
|
101
|
+
expect(info["faces"]).to eq(different_coordinates)
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should allow sending context" do
|
105
105
|
context = {"caption" => "some caption", "alt" => "alternative"}
|
106
106
|
result = Cloudinary::Uploader.upload("spec/logo.png", {:context => context})
|
107
107
|
info = Cloudinary::Api.resource(result["public_id"], {:context => true})
|
108
|
-
info["context"].
|
108
|
+
expect(info["context"]).to eq({"custom" => context})
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should support requesting manual moderation" do
|
112
112
|
result = Cloudinary::Uploader.upload("spec/logo.png", {:moderation => :manual})
|
113
|
-
result["moderation"][0]["status"].
|
114
|
-
result["moderation"][0]["kind"].
|
113
|
+
expect(result["moderation"][0]["status"]).to eq("pending")
|
114
|
+
expect(result["moderation"][0]["kind"]).to eq("manual")
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should support requesting raw conversion" do
|
118
|
-
|
118
|
+
expect{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should support requesting categorization" do
|
122
|
-
|
122
|
+
expect{Cloudinary::Uploader.upload("spec/logo.png", {:categorization => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should support requesting detection" do
|
126
|
-
|
126
|
+
expect{Cloudinary::Uploader.upload("spec/logo.png", {:detection => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should support requesting auto_tagging" do
|
130
|
-
|
130
|
+
expect{Cloudinary::Uploader.upload("spec/logo.png", {:auto_tagging => 0.5})}.to raise_error(CloudinaryException, /Must use/)
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should support upload_large" do
|
134
134
|
result = Cloudinary::Uploader.upload_large("spec/logo.png")
|
135
|
-
result["public_id"].
|
135
|
+
expect(result["public_id"]).to match(/^[a-z0-9]+.png$/)
|
136
136
|
end
|
137
137
|
|
138
138
|
context "unsigned" do
|
@@ -141,13 +141,13 @@ describe Cloudinary::Uploader do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should support unsigned uploading using presets", :upload_preset => true do
|
144
|
-
preset = Cloudinary::Api.create_upload_preset(:folder => "
|
144
|
+
preset = Cloudinary::Api.create_upload_preset(:folder => "test_folder_upload", :unsigned => true)
|
145
145
|
|
146
146
|
Cloudinary.config.api_key = nil
|
147
147
|
Cloudinary.config.api_secret = nil
|
148
148
|
|
149
149
|
result = Cloudinary::Uploader.unsigned_upload("spec/logo.png", preset["name"])
|
150
|
-
result["public_id"].
|
150
|
+
expect(result["public_id"]).to match(/^test_folder_upload\/[a-z0-9]+$/)
|
151
151
|
|
152
152
|
Cloudinary.class_variable_set(:@@config, nil)
|
153
153
|
|
data/spec/utils_spec.rb
CHANGED
@@ -16,415 +16,319 @@ describe Cloudinary::Utils do
|
|
16
16
|
end
|
17
17
|
end
|
18
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
|
+
|
19
26
|
it "should use cloud_name from config" do
|
20
|
-
|
21
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
27
|
+
test_cloudinary_url("test", {}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
22
28
|
end
|
23
29
|
|
24
30
|
it "should allow overriding cloud_name in options" do
|
25
|
-
|
26
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
27
|
-
options.should == {}
|
28
|
-
result.should == "http://res.cloudinary.com/test321/image/upload/test"
|
31
|
+
test_cloudinary_url("test", {:cloud_name=>"test321"}, "http://res.cloudinary.com/test321/image/upload/test", {})
|
29
32
|
end
|
30
33
|
|
31
34
|
it "should use default secure distribution if secure=true" do
|
32
|
-
|
33
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
34
|
-
options.should == {}
|
35
|
-
result.should == "https://res.cloudinary.com/test123/image/upload/test"
|
35
|
+
test_cloudinary_url("test", {:secure=>true}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should allow overriding secure distribution if secure=true" do
|
39
|
-
|
40
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
41
|
-
options.should == {}
|
42
|
-
result.should == "https://something.else.com/test123/image/upload/test"
|
39
|
+
test_cloudinary_url("test", {:secure=>true, :secure_distribution=>"something.else.com"}, "https://something.else.com/test123/image/upload/test", {})
|
43
40
|
end
|
44
41
|
|
45
42
|
it "should take secure distribution from config if secure=true" do
|
46
|
-
Cloudinary.config.secure_distribution = "config.secure.distribution.com"
|
47
|
-
|
48
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
49
|
-
options.should == {}
|
50
|
-
result.should == "https://config.secure.distribution.com/test123/image/upload/test"
|
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", {})
|
51
45
|
end
|
52
46
|
|
53
47
|
it "should default to akamai if secure is given with private_cdn and no secure_distribution" do
|
54
|
-
|
55
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
56
|
-
options.should == {}
|
57
|
-
result.should == "https://test123-res.cloudinary.com/image/upload/test"
|
48
|
+
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true}, "https://test123-res.cloudinary.com/image/upload/test", {})
|
58
49
|
end
|
59
50
|
|
60
51
|
it "should not add cloud_name if secure private_cdn and secure non akamai secure_distribution" do
|
61
|
-
|
62
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
63
|
-
options.should == {}
|
64
|
-
result.should == "https://something.cloudfront.net/image/upload/test"
|
52
|
+
test_cloudinary_url("test", {:secure=>true, :private_cdn=>true, :secure_distribution=>"something.cloudfront.net"}, "https://something.cloudfront.net/image/upload/test", {})
|
65
53
|
end
|
66
54
|
|
67
55
|
it "should allow overriding private_cdn if private_cdn=true" do
|
68
|
-
|
69
|
-
result.should == "http://test123-res.cloudinary.com/image/upload/test"
|
56
|
+
test_cloudinary_url("test", {:private_cdn => true}, "http://test123-res.cloudinary.com/image/upload/test", {})
|
70
57
|
end
|
71
58
|
|
72
59
|
it "should allow overriding private_cdn if private_cdn=false" do
|
73
60
|
Cloudinary.config.private_cdn = true
|
74
|
-
|
75
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
61
|
+
test_cloudinary_url("test", {:private_cdn => false}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
76
62
|
end
|
77
63
|
|
78
64
|
it "should allow overriding cname if cname=example.com" do
|
79
|
-
|
80
|
-
result.should == "http://example.com/test123/image/upload/test"
|
65
|
+
test_cloudinary_url("test", {:cname => "example.com"}, "http://example.com/test123/image/upload/test", {})
|
81
66
|
end
|
82
67
|
|
83
68
|
it "should allow overriding cname if cname=false" do
|
84
69
|
Cloudinary.config.cname = "example.com"
|
85
|
-
|
86
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
70
|
+
test_cloudinary_url("test", {:cname => nil}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
87
71
|
end
|
88
72
|
|
89
73
|
it "should use format from options" do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
+
it "should disllow use_root_path in shared distribution" do
|
112
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true})}.to raise_error(CloudinaryException)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should support use_root_path for private_cdn" do
|
116
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true}, "http://test123-res.cloudinary.com/test", {})
|
117
|
+
test_cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :angle=>0}, "http://test123-res.cloudinary.com/a_0/test", {})
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should support use_root_path together with url_suffix for private_cdn" do
|
121
|
+
test_cloudinary_url("test", {:use_root_path=>true, :url_suffix=>"hello", :private_cdn=>true}, "http://test123-res.cloudinary.com/test/hello", {})
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should disllow use_root_path if not image/upload" do
|
125
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
|
126
|
+
expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :resource_type=>:raw})}.to raise_error(CloudinaryException)
|
94
127
|
end
|
95
128
|
|
96
129
|
it "should use width and height from options only if crop is given" do
|
97
|
-
|
98
|
-
|
99
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
100
|
-
options.should == {:width=>100, :height=>100}
|
101
|
-
options = {:width=>100, :height=>100, :crop=>:crop}
|
102
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
103
|
-
options.should == {:width=>100, :height=>100}
|
104
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/test"
|
130
|
+
test_cloudinary_url("test", {:width=>100, :height=>100}, "http://res.cloudinary.com/test123/image/upload/test", {:width=>100, :height=>100})
|
131
|
+
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})
|
105
132
|
end
|
106
133
|
|
107
134
|
it "should not pass width and height to html in case of fit, lfill or limit crop" do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_limit,h_100,w_100/test"
|
112
|
-
options = {:width=>100, :height=>100, :crop=>:lfill}
|
113
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
114
|
-
options.should == {}
|
115
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_lfill,h_100,w_100/test"
|
116
|
-
options = {:width=>100, :height=>100, :crop=>:fit}
|
117
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
118
|
-
options.should == {}
|
119
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_fit,h_100,w_100/test"
|
135
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:limit}, "http://res.cloudinary.com/test123/image/upload/c_limit,h_100,w_100/test", {})
|
136
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:lfill}, "http://res.cloudinary.com/test123/image/upload/c_lfill,h_100,w_100/test", {})
|
137
|
+
test_cloudinary_url("test", {:width=>100, :height=>100, :crop=>:fit}, "http://res.cloudinary.com/test123/image/upload/c_fit,h_100,w_100/test", {})
|
120
138
|
end
|
121
139
|
|
122
140
|
it "should not pass width and height to html in case angle was used" do
|
123
|
-
|
124
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
125
|
-
options.should == {}
|
126
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/a_auto,c_scale,h_100,w_100/test"
|
141
|
+
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", {})
|
127
142
|
end
|
128
143
|
|
129
144
|
it "should use x, y, radius, prefix, gravity and quality from options" do
|
130
|
-
|
131
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
132
|
-
options.should == {}
|
133
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/g_center,p_a,q_0.4,r_3,x_1,y_2/test"
|
145
|
+
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", {})
|
134
146
|
end
|
135
147
|
|
136
148
|
it "should support named tranformation" do
|
137
|
-
|
138
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
139
|
-
options.should == {}
|
140
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/t_blip/test"
|
149
|
+
test_cloudinary_url("test", {:transformation=>"blip"}, "http://res.cloudinary.com/test123/image/upload/t_blip/test", {})
|
141
150
|
end
|
142
151
|
|
143
152
|
it "should support array of named tranformations" do
|
144
|
-
|
145
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
146
|
-
options.should == {}
|
147
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/t_blip.blop/test"
|
153
|
+
test_cloudinary_url("test", {:transformation=>["blip", "blop"]}, "http://res.cloudinary.com/test123/image/upload/t_blip.blop/test", {})
|
148
154
|
end
|
149
155
|
|
150
156
|
it "should support base tranformation" do
|
151
|
-
|
152
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
153
|
-
options.should == {:width=>100}
|
154
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/c_crop,w_100/test"
|
157
|
+
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})
|
155
158
|
end
|
156
159
|
|
157
160
|
it "should support array of base tranformations" do
|
158
|
-
|
159
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
160
|
-
options.should == {:width=>100}
|
161
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test"
|
161
|
+
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})
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should support array of tranformations" do
|
165
|
-
|
166
|
-
result
|
167
|
-
result.should == "c_fill,w_200,x_100,y_100/r_10"
|
165
|
+
result = Cloudinary::Utils.generate_transformation_string([{:x=>100, :y=>100, :width=>200, :crop=>:fill}, {:radius=>10}])
|
166
|
+
expect(result).to eq("c_fill,w_200,x_100,y_100/r_10")
|
168
167
|
end
|
169
168
|
|
170
169
|
it "should not include empty tranformations" do
|
171
|
-
|
172
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
173
|
-
options.should == {}
|
174
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/test"
|
170
|
+
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", {})
|
175
171
|
end
|
176
172
|
|
177
173
|
it "should support size" do
|
178
|
-
|
179
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
180
|
-
options.should == {:width=>"10", :height=>"10"}
|
181
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_crop,h_10,w_10/test"
|
174
|
+
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"})
|
182
175
|
end
|
183
176
|
|
184
177
|
it "should use type from options" do
|
185
|
-
|
186
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
187
|
-
options.should == {}
|
188
|
-
result.should == "http://res.cloudinary.com/test123/image/facebook/test"
|
178
|
+
test_cloudinary_url("test", {:type=>:facebook}, "http://res.cloudinary.com/test123/image/facebook/test", {})
|
189
179
|
end
|
190
180
|
|
191
181
|
it "should use resource_type from options" do
|
192
|
-
|
193
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
194
|
-
options.should == {}
|
195
|
-
result.should == "http://res.cloudinary.com/test123/raw/upload/test"
|
182
|
+
test_cloudinary_url("test", {:resource_type=>:raw}, "http://res.cloudinary.com/test123/raw/upload/test", {})
|
196
183
|
end
|
197
184
|
|
198
185
|
it "should ignore http links only if type is not given or is asset" do
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
result.should == "http://test"
|
203
|
-
options = {:type=>:asset}
|
204
|
-
result = Cloudinary::Utils.cloudinary_url("http://test", options)
|
205
|
-
options.should == {}
|
206
|
-
result.should == "http://test"
|
207
|
-
options = {:type=>:fetch}
|
208
|
-
result = Cloudinary::Utils.cloudinary_url("http://test", options)
|
209
|
-
options.should == {}
|
210
|
-
result.should == "http://res.cloudinary.com/test123/image/fetch/http://test"
|
186
|
+
test_cloudinary_url("http://test", {:type=>nil}, "http://test", {})
|
187
|
+
test_cloudinary_url("http://test", {:type=>:asset}, "http://test", {})
|
188
|
+
test_cloudinary_url("http://test", {:type=>:fetch}, "http://res.cloudinary.com/test123/image/fetch/http://test" , {})
|
211
189
|
end
|
212
190
|
|
213
191
|
it "should use allow absolute links to /images" do
|
214
|
-
|
215
|
-
result = Cloudinary::Utils.cloudinary_url("/images/test", options)
|
216
|
-
options.should == {}
|
217
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
192
|
+
test_cloudinary_url("/images/test", {}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
218
193
|
end
|
219
194
|
|
220
195
|
it "should use ignore absolute links not to /images" do
|
221
|
-
|
222
|
-
result = Cloudinary::Utils.cloudinary_url("/js/test", options)
|
223
|
-
options.should == {}
|
224
|
-
result.should == "/js/test"
|
196
|
+
test_cloudinary_url("/js/test", {}, "/js/test", {})
|
225
197
|
end
|
226
198
|
|
227
199
|
it "should escape fetch urls" do
|
228
|
-
|
229
|
-
result = Cloudinary::Utils.cloudinary_url("http://blah.com/hello?a=b", options)
|
230
|
-
options.should == {}
|
231
|
-
result.should == "http://res.cloudinary.com/test123/image/fetch/http://blah.com/hello%3Fa%3Db"
|
200
|
+
test_cloudinary_url("http://blah.com/hello?a=b", {:type=>:fetch}, "http://res.cloudinary.com/test123/image/fetch/http://blah.com/hello%3Fa%3Db", {})
|
232
201
|
end
|
233
202
|
|
234
203
|
it "should should escape http urls" do
|
235
|
-
|
236
|
-
result = Cloudinary::Utils.cloudinary_url("http://www.youtube.com/watch?v=d9NF2edxy-M", options)
|
237
|
-
options.should == {}
|
238
|
-
result.should == "http://res.cloudinary.com/test123/image/youtube/http://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M"
|
204
|
+
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", {})
|
239
205
|
end
|
240
206
|
|
241
207
|
it "should support background" do
|
242
|
-
|
243
|
-
|
244
|
-
options.should == {}
|
245
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/b_red/test"
|
246
|
-
options = {:background=>"#112233"}
|
247
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
248
|
-
options.should == {}
|
249
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/b_rgb:112233/test"
|
208
|
+
test_cloudinary_url("test", {:background=>"red"}, "http://res.cloudinary.com/test123/image/upload/b_red/test", {})
|
209
|
+
test_cloudinary_url("test", {:background=>"#112233"}, "http://res.cloudinary.com/test123/image/upload/b_rgb:112233/test", {})
|
250
210
|
end
|
251
211
|
|
252
212
|
it "should support default_image" do
|
253
|
-
|
254
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
255
|
-
options.should == {}
|
256
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/d_default/test"
|
213
|
+
test_cloudinary_url("test", {:default_image=>"default"}, "http://res.cloudinary.com/test123/image/upload/d_default/test", {})
|
257
214
|
end
|
258
215
|
|
259
216
|
it "should support angle" do
|
260
|
-
|
261
|
-
|
262
|
-
options.should == {}
|
263
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/a_55/test"
|
264
|
-
|
265
|
-
options = {:angle=>["auto", "55"]}
|
266
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
267
|
-
options.should == {}
|
268
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/a_auto.55/test"
|
217
|
+
test_cloudinary_url("test", {:angle=>"55"}, "http://res.cloudinary.com/test123/image/upload/a_55/test", {})
|
218
|
+
test_cloudinary_url("test", {:angle=>["auto", "55"]}, "http://res.cloudinary.com/test123/image/upload/a_auto.55/test", {})
|
269
219
|
end
|
270
220
|
|
271
221
|
it "should support format for fetch urls" do
|
272
|
-
|
273
|
-
result = Cloudinary::Utils.cloudinary_url("http://cloudinary.com/images/logo.png", options)
|
274
|
-
options.should == {}
|
275
|
-
result.should == "http://res.cloudinary.com/test123/image/fetch/f_jpg/http://cloudinary.com/images/logo.png"
|
222
|
+
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", {})
|
276
223
|
end
|
277
224
|
|
278
225
|
it "should support effect" do
|
279
|
-
|
280
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
281
|
-
options.should == {}
|
282
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia/test"
|
226
|
+
test_cloudinary_url("test", {:effect=>"sepia"}, "http://res.cloudinary.com/test123/image/upload/e_sepia/test", {})
|
283
227
|
end
|
284
228
|
|
285
229
|
it "should support effect with hash param" do
|
286
|
-
|
287
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
288
|
-
options.should == {}
|
289
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test"
|
230
|
+
test_cloudinary_url("test", {:effect=>{"sepia"=>10}}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
290
231
|
end
|
291
232
|
|
292
233
|
it "should support effect with array param" do
|
293
|
-
|
294
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
295
|
-
options.should == {}
|
296
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test"
|
234
|
+
test_cloudinary_url("test", {:effect=>["sepia", 10]}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
297
235
|
end
|
298
236
|
|
299
237
|
{:overlay=>:l, :underlay=>:u}.each do |param, letter|
|
300
238
|
it "should support #{param}" do
|
301
|
-
|
302
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
303
|
-
options.should == {}
|
304
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/#{letter}_text:hello/test"
|
239
|
+
test_cloudinary_url("test", {param=>"text:hello"}, "http://res.cloudinary.com/test123/image/upload/#{letter}_text:hello/test", {})
|
305
240
|
end
|
306
241
|
|
307
242
|
it "should not pass width/height to html for #{param}" do
|
308
|
-
|
309
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
310
|
-
options.should == {}
|
311
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/h_100,#{letter}_text:hello,w_100/test"
|
243
|
+
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", {})
|
312
244
|
end
|
313
245
|
end
|
314
246
|
|
315
247
|
it "should use ssl_detected if secure is not given as parameter and not set to true in configuration" do
|
316
|
-
|
317
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
318
|
-
options.should == {}
|
319
|
-
result.should == "https://res.cloudinary.com/test123/image/upload/test"
|
248
|
+
test_cloudinary_url("test", {:ssl_detected=>true}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
320
249
|
end
|
321
250
|
|
322
251
|
it "should use secure if given over ssl_detected and configuration" do
|
323
|
-
options = {:ssl_detected=>true, :secure=>false}
|
324
252
|
Cloudinary.config.secure = true
|
325
|
-
|
326
|
-
options.should == {}
|
327
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
253
|
+
test_cloudinary_url("test", {:ssl_detected=>true, :secure=>false}, "http://res.cloudinary.com/test123/image/upload/test", {})
|
328
254
|
end
|
329
255
|
|
330
256
|
it "should use secure: true from configuration over ssl_detected" do
|
331
|
-
options = {:ssl_detected=>false}
|
332
257
|
Cloudinary.config.secure = true
|
333
|
-
|
334
|
-
options.should == {}
|
335
|
-
result.should == "https://res.cloudinary.com/test123/image/upload/test"
|
258
|
+
test_cloudinary_url("test", {:ssl_detected=>false}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
336
259
|
end
|
337
260
|
|
338
261
|
it "should support extenal cname" do
|
339
|
-
|
340
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
341
|
-
options.should == {}
|
342
|
-
result.should == "http://hello.com/test123/image/upload/test"
|
262
|
+
test_cloudinary_url("test", {:cname=>"hello.com"}, "http://hello.com/test123/image/upload/test", {})
|
343
263
|
end
|
344
264
|
|
345
265
|
it "should support extenal cname with cdn_subdomain on" do
|
346
|
-
|
347
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
348
|
-
options.should == {}
|
349
|
-
result.should == "http://a2.hello.com/test123/image/upload/test"
|
266
|
+
test_cloudinary_url("test", {:cname=>"hello.com", :cdn_subdomain=>true}, "http://a2.hello.com/test123/image/upload/test", {})
|
350
267
|
end
|
351
268
|
|
269
|
+
it "should support cdn_subdomain with secure on if using shared_domain" do
|
270
|
+
test_cloudinary_url("test", {:secure=>true, :cdn_subdomain=>true}, "https://res-2.cloudinary.com/test123/image/upload/test", {})
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should support secure_cdn_subdomain false override with secure" do
|
274
|
+
test_cloudinary_url("test", {:secure=>true, :cdn_subdomain=>true, :secure_cdn_subdomain=>false}, "https://res.cloudinary.com/test123/image/upload/test", {})
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should support secure_cdn_subdomain true override with secure" do
|
278
|
+
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", {})
|
279
|
+
end
|
280
|
+
|
352
281
|
it "should support string param" do
|
353
|
-
|
354
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
355
|
-
options.should == {}
|
356
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test"
|
282
|
+
test_cloudinary_url("test", {"effect"=>{"sepia"=>10}}, "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test", {})
|
357
283
|
end
|
358
284
|
|
359
285
|
it "should support border" do
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
options = {"border"=>{:width=>5, :color=>"#ffaabbdd"}}
|
365
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
366
|
-
options.should == {}
|
367
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_rgb:ffaabbdd/test"
|
368
|
-
options = {"border"=>"1px_solid_blue"}
|
369
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
370
|
-
options.should == {}
|
371
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/bo_1px_solid_blue/test"
|
372
|
-
options = {"border"=>"2"}
|
373
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
374
|
-
options.should == {:border=>"2"}
|
375
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/test"
|
286
|
+
test_cloudinary_url("test", {"border"=>{:width=>5}}, "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_black/test", {})
|
287
|
+
test_cloudinary_url("test", {"border"=>{:width=>5, :color=>"#ffaabbdd"}}, "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_rgb:ffaabbdd/test", {})
|
288
|
+
test_cloudinary_url("test", {"border"=>"1px_solid_blue"}, "http://res.cloudinary.com/test123/image/upload/bo_1px_solid_blue/test", {})
|
289
|
+
test_cloudinary_url("test", {"border"=>"2"}, "http://res.cloudinary.com/test123/image/upload/test", {:border=>"2"})
|
376
290
|
end
|
377
291
|
|
378
292
|
it "should support flags" do
|
379
|
-
|
380
|
-
|
381
|
-
options.should == {}
|
382
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/fl_abc/test"
|
383
|
-
options = {"flags"=>["abc", "def"]}
|
384
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
385
|
-
options.should == {}
|
386
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/fl_abc.def/test"
|
293
|
+
test_cloudinary_url("test", {"flags"=>"abc"}, "http://res.cloudinary.com/test123/image/upload/fl_abc/test", {})
|
294
|
+
test_cloudinary_url("test", {"flags"=>["abc", "def"]}, "http://res.cloudinary.com/test123/image/upload/fl_abc.def/test", {})
|
387
295
|
end
|
388
296
|
|
389
297
|
it "build_upload_params should not destroy options" do
|
390
298
|
options = {:width=>100, :crop=>:scale}
|
391
|
-
Cloudinary::Uploader.build_upload_params(options)[:transformation].
|
392
|
-
options.length.
|
299
|
+
expect(Cloudinary::Uploader.build_upload_params(options)[:transformation]).to eq("c_scale,w_100")
|
300
|
+
expect(options.length).to eq(2)
|
393
301
|
end
|
394
302
|
|
395
303
|
it "build_upload_params canonize booleans" do
|
396
304
|
options = {:backup=>true, :use_filename=>false, :colors=>"true", :exif=>"false", :colors=>:true,
|
397
305
|
:image_metadata=>:false, :invalidate=>1, :eager_async=>"1"}
|
398
306
|
params = Cloudinary::Uploader.build_upload_params(options)
|
399
|
-
Cloudinary::Api.only(params, *options.keys).
|
307
|
+
expect(Cloudinary::Api.only(params, *options.keys)).to eq(
|
400
308
|
:backup=>1, :use_filename=>0, :colors=>1, :exif=>0, :colors=>1,
|
401
309
|
:image_metadata=>0, :invalidate=>1, :eager_async=>1
|
402
|
-
|
403
|
-
Cloudinary::Uploader.build_upload_params(:backup=>nil)[:backup].
|
404
|
-
Cloudinary::Uploader.build_upload_params({})[:backup].
|
310
|
+
)
|
311
|
+
expect(Cloudinary::Uploader.build_upload_params(:backup=>nil)[:backup]).to be_nil
|
312
|
+
expect(Cloudinary::Uploader.build_upload_params({})[:backup]).to be_nil
|
405
313
|
end
|
406
314
|
|
407
315
|
it "should add version if public_id contains /" do
|
408
|
-
|
409
|
-
|
410
|
-
result = Cloudinary::Utils.cloudinary_url("folder/test", :version=>123)
|
411
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/v123/folder/test"
|
316
|
+
test_cloudinary_url("folder/test", {}, "http://res.cloudinary.com/test123/image/upload/v1/folder/test", {})
|
317
|
+
test_cloudinary_url("folder/test", {:version=>123}, "http://res.cloudinary.com/test123/image/upload/v123/folder/test", {})
|
412
318
|
end
|
413
319
|
|
414
320
|
it "should not add version if public_id contains version already" do
|
415
|
-
|
416
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/v1234/test"
|
321
|
+
test_cloudinary_url("v1234/test", {}, "http://res.cloudinary.com/test123/image/upload/v1234/test", {})
|
417
322
|
end
|
418
323
|
|
419
324
|
it "should allow to shorted image/upload urls" do
|
420
|
-
|
421
|
-
result.should == "http://res.cloudinary.com/test123/iu/test"
|
325
|
+
test_cloudinary_url("test", {:shorten=>true}, "http://res.cloudinary.com/test123/iu/test", {})
|
422
326
|
end
|
423
327
|
|
424
328
|
it "should allow to use folders in PreloadedFile" do
|
425
329
|
signature = Cloudinary::Utils.api_sign_request({:public_id=>"folder/file", :version=>"1234"}, Cloudinary.config.api_secret)
|
426
330
|
preloaded = Cloudinary::PreloadedFile.new("image/upload/v1234/folder/file.jpg#" + signature)
|
427
|
-
preloaded.
|
331
|
+
expect(preloaded).to be_valid
|
428
332
|
end
|
429
333
|
|
430
334
|
it "should escape public_ids" do
|
@@ -437,50 +341,38 @@ describe Cloudinary::Utils do
|
|
437
341
|
["parentheses(interject)", "parentheses%28interject%29"]
|
438
342
|
].each do
|
439
343
|
|source, target|
|
440
|
-
Cloudinary::Utils.cloudinary_url(source).
|
344
|
+
expect(Cloudinary::Utils.cloudinary_url(source)).to eq("http://res.cloudinary.com/test123/image/upload/#{target}")
|
441
345
|
end
|
442
346
|
end
|
443
347
|
|
444
348
|
it "should correctly sign URLs", :signed => true do
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
actual = Cloudinary::Utils.cloudinary_url("image.jpg", options)
|
458
|
-
actual.should == expected
|
459
|
-
|
460
|
-
expected = "http://res.cloudinary.com/test123/image/fetch/s--_GAUclyB--/v1234/http://google.com/path/to/image.png"
|
461
|
-
actual = Cloudinary::Utils.cloudinary_url("http://google.com/path/to/image.png", :type => "fetch", :version => 1234, :sign_url => true)
|
462
|
-
actual.should == expected
|
349
|
+
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", {})
|
350
|
+
test_cloudinary_url("image.jpg", {:version => 1234, :sign_url => true}, "http://res.cloudinary.com/test123/image/upload/s----SjmNDA--/v1234/image.jpg", {})
|
351
|
+
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", {})
|
352
|
+
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", {})
|
353
|
+
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", {})
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should correctly sign URLs in deprecated sign_version mode", :signed => true do
|
357
|
+
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", {})
|
358
|
+
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", {})
|
359
|
+
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", {})
|
360
|
+
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", {})
|
463
361
|
end
|
464
362
|
|
465
363
|
it "should correctly sign_request" do
|
466
364
|
params = Cloudinary::Utils.sign_request({:public_id=>"folder/file", :version=>"1234"})
|
467
|
-
params.
|
365
|
+
expect(params).to eq(:public_id=>"folder/file", :version=>"1234", :signature=>"7a3349cbb373e4812118d625047ede50b90e7b67", :api_key=>"1234")
|
468
366
|
end
|
469
367
|
|
470
368
|
it "should support responsive width" do
|
471
|
-
|
472
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
473
|
-
options.should == {responsive: true}
|
474
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/c_limit,w_auto/test"
|
369
|
+
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})
|
475
370
|
Cloudinary.config.responsive_width_transformation = {:width => :auto, :crop => :pad}
|
476
|
-
|
477
|
-
result = Cloudinary::Utils.cloudinary_url("test", options)
|
478
|
-
options.should == {responsive: true}
|
479
|
-
result.should == "http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/c_pad,w_auto/test"
|
371
|
+
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})
|
480
372
|
end
|
481
373
|
|
482
374
|
it "should correctly encode double arrays" do
|
483
|
-
Cloudinary::Utils.encode_double_array([1,2,3,4]).
|
484
|
-
Cloudinary::Utils.encode_double_array([[1,2,3,4],[5,6,7,8]]).
|
375
|
+
expect(Cloudinary::Utils.encode_double_array([1,2,3,4])).to eq("1,2,3,4")
|
376
|
+
expect(Cloudinary::Utils.encode_double_array([[1,2,3,4],[5,6,7,8]])).to eq("1,2,3,4|5,6,7,8")
|
485
377
|
end
|
486
378
|
end
|