cloudinary 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'cloudinary'
3
+ require 'rest_client'
4
+ require 'zip'
5
+
6
+ ARCHIVE_TAG = "archive_test_tag_#{rand}"
7
+
8
+ RSpec.shared_context 'archive' do
9
+ before :all do
10
+ Cloudinary::Uploader.upload(
11
+ "http://res.cloudinary.com/demo/image/upload/sample.jpg",
12
+ :public_id => 'tag_samplebw',
13
+ :tags => [TEST_TAG, ARCHIVE_TAG],
14
+ :transformation => {
15
+ :effect => :blackwhite
16
+ }
17
+ )
18
+ Cloudinary::Uploader.upload(
19
+ "http://res.cloudinary.com/demo/image/upload/sample.jpg",
20
+ :public_id => 'tag_sample',
21
+ :tags => [TEST_TAG, ARCHIVE_TAG],
22
+ :transformation => {
23
+ :effect => :blackwhite
24
+ }
25
+ )
26
+ end
27
+ include_context "cleanup"
28
+ end
29
+
30
+ describe Cloudinary::Utils do
31
+ include_context 'archive'
32
+
33
+ describe '.generate_zip_download_url' do
34
+ let(:options) { {} }
35
+ let!(:archive_result) {
36
+ Cloudinary::Utils.download_zip_url(
37
+ {
38
+ :target_public_id => 'gem_archive_test',
39
+ :public_ids => %w(tag_sample tag_samplebw),
40
+ :tags => ARCHIVE_TAG
41
+ }.merge(options))
42
+ }
43
+
44
+ describe 'public_ids' do
45
+ it 'should generate a valid url' do
46
+ expect(archive_result).not_to be_empty
47
+ end
48
+ it 'should include two files' do
49
+ Zip::File.open_buffer(RestClient.get(archive_result)) do |zip_file|
50
+ list = zip_file.glob('*').map(&:name)
51
+ expect(list.length).to be(2)
52
+ expect(list).to include('tag_sample.jpg', 'tag_samplebw.jpg')
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ describe Cloudinary::Uploader do
60
+ include_context 'archive'
61
+
62
+ let(:options) { {} }
63
+
64
+ describe '.create_archive' do
65
+ let!(:archive_result) {
66
+ Cloudinary::Uploader.create_archive(
67
+ {
68
+ :target_public_id => 'gem_archive_test',
69
+ :public_ids => %w(tag_sample tag_samplebw),
70
+ :tags => ARCHIVE_TAG
71
+ }.merge(options))
72
+ }
73
+ let(:options) { { :mode => :create } }
74
+ it 'should return a Hash' do
75
+ expect(archive_result).to be_a(Hash)
76
+ end
77
+ expected_keys = %w(
78
+ resource_type
79
+ type
80
+ public_id
81
+ version
82
+ url
83
+ secure_url
84
+ created_at
85
+ tags
86
+ signature
87
+ bytes
88
+ etag
89
+ resource_count
90
+ file_count
91
+ )
92
+ it "should include keys: #{expected_keys.join(', ')}" do
93
+ expect(archive_result.keys).to match_array(expected_keys)
94
+ end
95
+ end
96
+ describe '.create_zip' do
97
+ it 'should call create_archive with "zip" format' do
98
+ expect(Cloudinary::Uploader).to receive(:create_archive).with({ :tags => TEST_TAG }, "zip")
99
+ Cloudinary::Uploader.create_zip({ :tags => TEST_TAG })
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'cloudinary'
3
+
4
+ describe Cloudinary do
5
+ before :all do
6
+ @user_platform = Cloudinary.user_platform
7
+ end
8
+ after :all do
9
+ Cloudinary.user_platform = @user_platform
10
+ end
11
+
12
+ it 'should add a user platform to USER_AGENT' do
13
+ Cloudinary.user_platform = "Spec/1.0 (Test)"
14
+ expect(Cloudinary.USER_AGENT).to match( %r"Spec\/1.0 \(Test\) CloudinaryRuby/[\d.]+")
15
+
16
+ end
17
+ end
@@ -15,6 +15,12 @@ RSpec.configure do |config|
15
15
  config.filter_run_excluding :delete_all => true
16
16
  end
17
17
 
18
+ RSpec.shared_context "cleanup" do
19
+ after :all do
20
+ Cloudinary::Api.delete_resources_by_tag(TEST_TAG) unless Cloudinary.config.keep_test_products
21
+ end
22
+
23
+ end
18
24
  # Create a regexp with the given +tag+ name.
19
25
  def html_tag_matcher( tag)
20
26
  /<#{tag}([\s]+([-[:word:]]+)[\s]*\=\s*\"([^\"]*)\")*\s*>.*<\s*\/#{tag}\s*>/
@@ -140,3 +146,20 @@ RSpec::Matchers.define :be_served_by_cloudinary do
140
146
  end
141
147
  end
142
148
 
149
+ def deep_fetch(hash, path)
150
+ Array(path).reduce(hash) { |h, key| h && h.fetch(key, nil) }
151
+ end
152
+
153
+ # Matches deep values in the actual Hash, disregarding other keys and values.
154
+ # @example
155
+ # expect( {:foo => { :bar => 'foobar'}}).to have_deep_hash_values_of( [:foo, :bar] => 'foobar')
156
+ # expect( foo_instance).to receive(:bar_method).with(deep_hash_values_of([:foo, :bar] => 'foobar'))
157
+ RSpec::Matchers.define :deep_hash_value do |expected|
158
+ match do |actual|
159
+ expected.all? do |path, value|
160
+ values_match? deep_fetch(actual, path), value
161
+ end
162
+ end
163
+ end
164
+
165
+ RSpec::Matchers.alias_matcher :have_deep_hash_values_of, :deep_hash_value
@@ -7,9 +7,10 @@ end
7
7
 
8
8
  describe Cloudinary::Uploader do
9
9
  break puts("Please setup environment for api test to run") if Cloudinary.config.api_secret.blank?
10
+ include_context "cleanup"
10
11
 
11
12
  it "should successfully upload file" do
12
- result = Cloudinary::Uploader.upload("spec/logo.png")
13
+ result = Cloudinary::Uploader.upload("spec/logo.png", :tags => TEST_TAG)
13
14
  expect(result["width"]).to eq(241)
14
15
  expect(result["height"]).to eq(51)
15
16
  expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
@@ -17,121 +18,148 @@ describe Cloudinary::Uploader do
17
18
  end
18
19
 
19
20
  it "should successfully upload a file from pathname", :pathname => true do
20
- result = Cloudinary::Uploader.upload(Pathname.new("spec/logo.png"))
21
+ result = Cloudinary::Uploader.upload(Pathname.new("spec/logo.png"), :tags => TEST_TAG)
21
22
  expect(result["width"]).to eq(241)
22
23
  end
23
24
 
24
25
  it "should successfully upload file by url" do
25
- result = Cloudinary::Uploader.upload("http://cloudinary.com/images/old_logo.png")
26
+ result = Cloudinary::Uploader.upload("http://cloudinary.com/images/old_logo.png", :tags => TEST_TAG)
26
27
  expect(result["width"]).to eq(241)
27
28
  expect(result["height"]).to eq(51)
28
29
  expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
29
30
  expect(result["signature"]).to eq(expected_signature)
30
31
  end
31
-
32
- it "should successfully rename a file" do
33
- result = Cloudinary::Uploader.upload("spec/logo.png")
34
- Cloudinary::Uploader.rename(result["public_id"], result["public_id"]+"2")
35
- expect(Cloudinary::Api.resource(result["public_id"]+"2")).not_to be_nil
36
32
 
37
- result2 = Cloudinary::Uploader.upload("spec/favicon.ico")
38
- expect{Cloudinary::Uploader.rename(result2["public_id"], result["public_id"]+"2")}.to raise_error
39
- Cloudinary::Uploader.rename(result2["public_id"], result["public_id"]+"2", :overwrite=>true)
33
+ describe '.rename' do
34
+ before(:all) do
35
+ @result = Cloudinary::Uploader.upload("spec/logo.png", :tags => TEST_TAG)
36
+ @resource_1_id = @result["public_id"]
37
+ result = Cloudinary::Uploader.upload("spec/favicon.ico", :tags => TEST_TAG)
38
+ @resource_2_id = result["public_id"]
39
+ end
40
+
41
+ it 'should rename a resource' do
42
+ Cloudinary::Uploader.rename(@resource_1_id, @resource_1_id+"2")
43
+ expect(Cloudinary::Api.resource(@resource_1_id+"2")).not_to be_nil
44
+ @resource_1_id = @resource_1_id+"2" # will not update if expect fails
45
+ end
46
+ it 'should not allow renaming to an existing ID' do
47
+ id = @resource_2_id
48
+ @resource_2_id = @resource_1_id+"2" # if rename doesn't fail, this is the new ID
49
+ expect { Cloudinary::Uploader.rename(id, @resource_1_id+"2") }.to raise_error
50
+ @resource_2_id = id
51
+ end
52
+ context ':overwrite => true' do
53
+ it 'should rename to an existing ID' do
54
+ new_id = Cloudinary::Uploader.upload("spec/logo.png", :tags => TEST_TAG)["public_id"]
55
+ Cloudinary::Uploader.rename(@resource_2_id, new_id, :overwrite => true)
56
+ expect(Cloudinary::Api.resource(new_id)["format"]).to eq("ico")
57
+ @resource_2_id = new_id # will not update if expect fails
58
+ end
59
+ end
60
+ context ':invalidate => true' do
61
+ it 'should notidy the server to invalidate the resource in the CDN' do
62
+ # Can't test the result, so we just verify the parameter is send to the server
63
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value([:payload, :invalidate] => 1))
64
+ Cloudinary::Uploader.rename(@resource_2_id, @resource_2_id+"2", :invalidate => true) # will not affect the server
65
+ end
40
66
 
41
- expect(Cloudinary::Api.resource(result["public_id"]+"2")["format"]).to eq("ico")
67
+ end
42
68
  end
43
69
 
70
+
44
71
  it "should support explicit" do
45
- result = Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}])
72
+ result = Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}], :tags => TEST_TAG)
46
73
  url = Cloudinary::Utils.cloudinary_url("cloudinary", :type=>"twitter_name", :crop=>"scale", :width=>"2.0", :format=>"png", :version=>result["version"])
47
74
  expect(result["eager"][0]["url"]).to eq(url)
48
75
  end
49
76
 
50
77
  it "should support eager" do
51
- Cloudinary::Uploader.upload("spec/logo.png", :eager=>[{:crop=>"scale", :width=>"2.0"}])
78
+ Cloudinary::Uploader.upload("spec/logo.png", :eager=>[{:crop=>"scale", :width=>"2.0"}], :tags => TEST_TAG)
52
79
  end
53
80
 
54
81
  it "should support headers" do
55
- Cloudinary::Uploader.upload("spec/logo.png", :headers=>["Link: 1"])
56
- Cloudinary::Uploader.upload("spec/logo.png", :headers=>{"Link" => "1"})
82
+ Cloudinary::Uploader.upload("spec/logo.png", :headers=>["Link: 1"], :tags => TEST_TAG)
83
+ Cloudinary::Uploader.upload("spec/logo.png", :headers=>{"Link" => "1"}, :tags => TEST_TAG)
57
84
  end
58
85
 
59
86
  it "should successfully generate text image" do
60
- result = Cloudinary::Uploader.text("hello world")
87
+ result = Cloudinary::Uploader.text("hello world", :tags => TEST_TAG)
61
88
  expect(result["width"]).to be > 1
62
89
  expect(result["height"]).to be > 1
63
90
  end
64
91
 
65
92
  it "should correctly handle tags" do
66
- result = Cloudinary::Uploader.upload("spec/logo.png")
67
- Cloudinary::Uploader.add_tag("tag1", result["public_id"])
68
- Cloudinary::Uploader.add_tag("tag2", result["public_id"])
69
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag1", "tag2"])
70
- Cloudinary::Uploader.remove_tag("tag1", result["public_id"])
71
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag2"])
72
- Cloudinary::Uploader.replace_tag("tag3", result["public_id"])
73
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to eq(["tag3"])
93
+ new_tag = "tag#{rand(10000)}"
94
+ result = Cloudinary::Uploader.upload("spec/logo.png", :tags => TEST_TAG)
95
+ Cloudinary::Uploader.add_tag("#{new_tag}_1", result["public_id"])
96
+ Cloudinary::Uploader.add_tag("#{new_tag}_2", result["public_id"])
97
+ expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_1", "#{new_tag}_2", TEST_TAG])
98
+ Cloudinary::Uploader.remove_tag("#{new_tag}_1", result["public_id"])
99
+ expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_2", TEST_TAG])
100
+ Cloudinary::Uploader.replace_tag("#{new_tag}_3", result["public_id"])
101
+ expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_3"])
74
102
  end
75
103
 
76
104
  it "should correctly handle unique_filename" do
77
- result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true)
105
+ result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true, :tags => TEST_TAG)
78
106
  expect(result["public_id"]).to match(/logo_[a-zA-Z0-9]{6}/)
79
- result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true, :unique_filename => false)
107
+ result = Cloudinary::Uploader.upload("spec/logo.png", :use_filename => true, :unique_filename => false, :tags => TEST_TAG)
80
108
  expect(result["public_id"]).to eq("logo")
81
109
  end
82
110
 
83
111
  it "should allow whitelisted formats if allowed_formats", :allowed=>true do
84
- result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["png"])
112
+ result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["png"], :tags => TEST_TAG)
85
113
  expect(result["format"]).to eq("png")
86
114
  end
87
115
 
88
116
  it "should prevent non whitelisted formats from being uploaded if allowed_formats is specified", :allowed=>true do
89
- expect{Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"])}.to raise_error
117
+ expect{Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"], :tags => TEST_TAG)}.to raise_error
90
118
  end
91
119
 
92
120
  it "should allow non whitelisted formats if type is specified and convert to that type", :allowed=>true do
93
- result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"], :format => "jpg")
121
+ result = Cloudinary::Uploader.upload("spec/logo.png", :allowed_formats => ["jpg"], :format => "jpg", :tags => TEST_TAG)
94
122
  expect(result["format"]).to eq("jpg")
95
123
  end
96
124
 
97
125
  it "should allow sending face coordinates" do
98
126
  coordinates = [[120, 30, 109, 150], [121, 31, 110, 151]]
99
- result = Cloudinary::Uploader.upload("spec/logo.png", {:face_coordinates => coordinates, :faces => true})
127
+ result = Cloudinary::Uploader.upload("spec/logo.png", {:face_coordinates => coordinates, :faces => true, :tags => TEST_TAG})
100
128
  expect(result["faces"]).to eq(coordinates)
101
129
 
102
130
  different_coordinates = [[122, 32, 111, 152]]
103
- Cloudinary::Uploader.explicit(result["public_id"], {:face_coordinates => different_coordinates, :faces => true, :type => "upload"})
131
+ Cloudinary::Uploader.explicit(result["public_id"], {:face_coordinates => different_coordinates, :faces => true, :type => "upload", :tags => TEST_TAG})
104
132
  info = Cloudinary::Api.resource(result["public_id"], {:faces => true})
105
133
  expect(info["faces"]).to eq(different_coordinates)
106
134
  end
107
135
 
108
136
  it "should allow sending context" do
109
137
  context = {"caption" => "some caption", "alt" => "alternative"}
110
- result = Cloudinary::Uploader.upload("spec/logo.png", {:context => context})
138
+ result = Cloudinary::Uploader.upload("spec/logo.png", {:context => context, :tags => TEST_TAG})
111
139
  info = Cloudinary::Api.resource(result["public_id"], {:context => true})
112
140
  expect(info["context"]).to eq({"custom" => context})
113
141
  end
114
142
 
115
143
  it "should support requesting manual moderation" do
116
- result = Cloudinary::Uploader.upload("spec/logo.png", {:moderation => :manual})
144
+ result = Cloudinary::Uploader.upload("spec/logo.png", {:moderation => :manual, :tags => TEST_TAG})
117
145
  expect(result["moderation"][0]["status"]).to eq("pending")
118
146
  expect(result["moderation"][0]["kind"]).to eq("manual")
119
147
  end
120
148
 
121
149
  it "should support requesting raw conversion" do
122
- expect{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
150
+ expect{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
123
151
  end
124
152
 
125
153
  it "should support requesting categorization" do
126
- expect{Cloudinary::Uploader.upload("spec/logo.png", {:categorization => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
154
+ expect{Cloudinary::Uploader.upload("spec/logo.png", {:categorization => :illegal, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
127
155
  end
128
156
 
129
157
  it "should support requesting detection" do
130
- expect{Cloudinary::Uploader.upload("spec/logo.png", {:detection => :illegal})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
158
+ expect{Cloudinary::Uploader.upload("spec/logo.png", {:detection => :illegal, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
131
159
  end
132
160
 
133
161
  it "should support requesting auto_tagging" do
134
- expect{Cloudinary::Uploader.upload("spec/logo.png", {:auto_tagging => 0.5})}.to raise_error(CloudinaryException, /Must use/)
162
+ expect{Cloudinary::Uploader.upload("spec/logo.png", {:auto_tagging => 0.5, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Must use/)
135
163
  end
136
164
 
137
165
  it "should support upload_large", :large => true do
@@ -140,10 +168,10 @@ describe Cloudinary::Uploader do
140
168
  io.puts(header)
141
169
  5880000.times{ io.write("\xFF") }
142
170
  io.rewind
143
- result = Cloudinary::Uploader.upload_large(io, :chunk_size => 5243000)
171
+ result = Cloudinary::Uploader.upload_large(io, :chunk_size => 5243000, :tags => TEST_TAG)
144
172
  expect(result["resource_type"]).to eq('raw')
145
173
  io.rewind
146
- result = Cloudinary::Uploader.upload_large(io, :resource_type => 'image', :chunk_size => 5243000)
174
+ result = Cloudinary::Uploader.upload_large(io, :resource_type => 'image', :chunk_size => 5243000, :tags => TEST_TAG)
147
175
  expect(result["resource_type"]).to eq('image')
148
176
  expect(result["width"]).to eq(1400)
149
177
  expect(result["height"]).to eq(1400)
@@ -156,17 +184,16 @@ describe Cloudinary::Uploader do
156
184
  end
157
185
 
158
186
  it "should support unsigned uploading using presets", :upload_preset => true do
159
- preset = Cloudinary::Api.create_upload_preset(:folder => "test_folder_upload", :unsigned => true)
187
+ preset = Cloudinary::Api.create_upload_preset(:folder => "test_folder_upload", :unsigned => true, :tags => TEST_TAG)
160
188
 
161
189
  Cloudinary.config.api_key = nil
162
190
  Cloudinary.config.api_secret = nil
163
191
 
164
- result = Cloudinary::Uploader.unsigned_upload("spec/logo.png", preset["name"])
192
+ result = Cloudinary::Uploader.unsigned_upload("spec/logo.png", preset["name"], :tags => TEST_TAG)
165
193
  expect(result["public_id"]).to match(/^test_folder_upload\/[a-z0-9]+$/)
166
194
 
167
195
  Cloudinary.class_variable_set(:@@config, nil)
168
196
 
169
- Cloudinary::Api.delete_upload_preset(preset["name"])
170
197
  end
171
198
  end
172
199
 
@@ -180,7 +207,26 @@ describe Cloudinary::Uploader do
180
207
  end
181
208
 
182
209
  it "should fail if timeout is reached" do
183
- expect{Cloudinary::Uploader.upload(Pathname.new("spec/logo.png"))}.to raise_error
210
+ expect{Cloudinary::Uploader.upload(Pathname.new("spec/logo.png"), :tags => TEST_TAG)}.to raise_error
211
+ end
212
+ end
213
+
214
+ context ":responsive_breakpoints" do
215
+ context ":create_derived" do
216
+ result = Cloudinary::Uploader.upload("spec/logo.png", :responsive_breakpoints => {:create_derived => false }, :tags => TEST_TAG)
217
+ it 'should return a responsive_breakpoints in the response' do
218
+ expect(result).to include('responsive_breakpoints')
219
+ end
220
+ end
221
+ end
222
+ describe 'explicit' do
223
+
224
+ context ":invalidate" do
225
+ it 'should pass the invalidate value to the server' do
226
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :invalidate] => 1))
227
+ Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}], :invalidate => true, :tags => TEST_TAG)
228
+ end
184
229
  end
185
230
  end
186
231
  end
232
+
@@ -7,22 +7,17 @@ describe Cloudinary::Utils do
7
7
  Cloudinary.config do |config|
8
8
  # config.cloud_name = "demo"
9
9
  config.secure_distribution = nil
10
- config.private_cdn = false
11
- config.secure = false
12
- config.cname = nil
13
- config.cdn_subdomain = false
10
+ config.private_cdn = false
11
+ config.secure = false
12
+ config.cname = nil
13
+ config.cdn_subdomain = false
14
14
  end
15
15
  end
16
- let(:cloud_name) {Cloudinary.config.cloud_name}
16
+
17
+ let(:cloud_name) { Cloudinary.config.cloud_name }
17
18
  let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
18
19
  let(:upload_path) { "#{root_path}/image/upload" }
19
20
 
20
- it "should use cloud_name from config" do
21
- expect(["test", {}])
22
- .to produce_url( "#{upload_path}/test")
23
- .and empty_options
24
- end
25
-
26
21
  it "should allow overriding cloud_name in options" do
27
22
  expect(["test", { :cloud_name => "test321" }])
28
23
  .to produce_url("http://res.cloudinary.com/test321/image/upload/test")
@@ -30,221 +25,221 @@ describe Cloudinary::Utils do
30
25
  end
31
26
 
32
27
  it "should use default secure distribution if secure=true" do
33
- expect(["test",{:secure=>true}])
28
+ expect(["test", { :secure => true }])
34
29
  .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
35
- .and empty_options
30
+ .and empty_options
36
31
  end
37
32
 
38
33
  it "should allow overriding secure distribution if secure=true" do
39
- expect(["test",{:secure=>true, :secure_distribution=>"something.else.com"}])
34
+ expect(["test", { :secure => true, :secure_distribution => "something.else.com" }])
40
35
  .to produce_url("https://something.else.com/#{cloud_name}/image/upload/test")
41
- .and empty_options
36
+ .and empty_options
42
37
  end
43
38
 
44
39
  it "should take secure distribution from config if secure=true" do
45
40
  Cloudinary.config.secure_distribution = "config.secure.distribution.com"
46
- expect(["test",{:secure=>true}])
41
+ expect(["test", { :secure => true }])
47
42
  .to produce_url("https://config.secure.distribution.com/#{cloud_name}/image/upload/test")
48
- .and empty_options
43
+ .and empty_options
49
44
  end
50
45
 
51
46
  it "should default to akamai if secure is given with private_cdn and no secure_distribution" do
52
- expect(["test",{:secure=>true, :private_cdn=>true}])
47
+ expect(["test", { :secure => true, :private_cdn => true }])
53
48
  .to produce_url("https://#{cloud_name}-res.cloudinary.com/image/upload/test")
54
- .and empty_options
49
+ .and empty_options
55
50
  end
56
51
 
57
52
  it "should not add cloud_name if secure private_cdn and secure non akamai secure_distribution" do
58
- expect(["test",{:secure=>true, :private_cdn=>true, :secure_distribution=>"something.cloudfront.net"}])
53
+ expect(["test", { :secure => true, :private_cdn => true, :secure_distribution => "something.cloudfront.net" }])
59
54
  .to produce_url("https://something.cloudfront.net/image/upload/test")
60
- .and empty_options
55
+ .and empty_options
61
56
  end
62
57
 
63
58
  it "should allow overriding private_cdn if private_cdn=true" do
64
- expect(["test",{:private_cdn => true}])
59
+ expect(["test", { :private_cdn => true }])
65
60
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/image/upload/test")
66
- .and empty_options
61
+ .and empty_options
67
62
  end
68
63
 
69
64
  it "should allow overriding private_cdn if private_cdn=false" do
70
65
  Cloudinary.config.private_cdn = true
71
- expect(["test",{ :private_cdn => false }])
66
+ expect(["test", { :private_cdn => false }])
72
67
  .to produce_url("#{upload_path}/test")
73
- .and empty_options
68
+ .and empty_options
74
69
  end
75
70
 
76
71
  it "should allow overriding cname if cname=example.com" do
77
- expect(["test",{:cname => "example.com"}])
72
+ expect(["test", { :cname => "example.com" }])
78
73
  .to produce_url("http://example.com/#{cloud_name}/image/upload/test")
79
- .and empty_options
74
+ .and empty_options
80
75
  end
81
76
 
82
77
  it "should allow overriding cname if cname=false" do
83
78
  Cloudinary.config.cname = "example.com"
84
- expect(["test",{ :cname => false }])
79
+ expect(["test", { :cname => false }])
85
80
  .to produce_url("#{upload_path}/test")
86
- .and empty_options
81
+ .and empty_options
87
82
  end
88
83
 
89
84
  it "should use format from options" do
90
- expect(["test",{ :format => :jpg }])
85
+ expect(["test", { :format => :jpg }])
91
86
  .to produce_url("#{upload_path}/test.jpg")
92
- .and empty_options
87
+ .and empty_options
93
88
  end
94
89
 
95
90
  it "should disallow url_suffix in shared distribution" do
96
- expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello"})}.to raise_error(CloudinaryException)
91
+ expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello" }) }.to raise_error(CloudinaryException)
97
92
  end
98
93
 
99
94
  it "should disallow url_suffix in non upload types" do
100
- expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello", :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
95
+ expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello", :private_cdn => true, :type => :facebook }) }.to raise_error(CloudinaryException)
101
96
  end
102
97
 
103
98
  it "should disallow url_suffix with / or ." do
104
- expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello/world", :private_cdn=>true})}.to raise_error(CloudinaryException)
105
- expect{Cloudinary::Utils.cloudinary_url("test", {:url_suffix=>"hello.world", :private_cdn=>true})}.to raise_error(CloudinaryException)
99
+ expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello/world", :private_cdn => true }) }.to raise_error(CloudinaryException)
100
+ expect { Cloudinary::Utils.cloudinary_url("test", { :url_suffix => "hello.world", :private_cdn => true }) }.to raise_error(CloudinaryException)
106
101
  end
107
102
 
108
103
  it "should support url_suffix for private_cdn" do
109
- expect(["test",{:url_suffix=>"hello", :private_cdn=>true}])
104
+ expect(["test", { :url_suffix => "hello", :private_cdn => true }])
110
105
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/test/hello")
111
- .and empty_options
112
- expect(["test",{:url_suffix=>"hello", :angle=>0, :private_cdn=>true}])
106
+ .and empty_options
107
+ expect(["test", { :url_suffix => "hello", :angle => 0, :private_cdn => true }])
113
108
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/a_0/test/hello")
114
- .and empty_options
109
+ .and empty_options
115
110
  end
116
111
 
117
112
  it "should put format after url_suffix" do
118
- expect(["test",{:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg"}])
113
+ expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg" }])
119
114
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/test/hello.jpg")
120
- .and empty_options
115
+ .and empty_options
121
116
  end
122
117
 
123
118
  it "should not sign the url_suffix" do
124
- expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
125
- expect(["test",{:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :sign_url=>true}])
119
+ expected_signture = Cloudinary::Utils.cloudinary_url("test", :format => "jpg", :sign_url => true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
120
+ expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg", :sign_url => true }])
126
121
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/#{expected_signture}/test/hello.jpg")
127
- .and empty_options
122
+ .and empty_options
128
123
 
129
- expected_signture = Cloudinary::Utils.cloudinary_url("test", :format=>"jpg", :angle=>0, :sign_url=>true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
130
- expect(["test",{:url_suffix=>"hello", :private_cdn=>true, :format=>"jpg", :angle=>0, :sign_url=>true}])
124
+ expected_signture = Cloudinary::Utils.cloudinary_url("test", :format => "jpg", :angle => 0, :sign_url => true).match(/s--[0-9A-Za-z_-]{8}--/).to_s
125
+ expect(["test", { :url_suffix => "hello", :private_cdn => true, :format => "jpg", :angle => 0, :sign_url => true }])
131
126
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/images/#{expected_signture}/a_0/test/hello.jpg")
132
- .and empty_options
127
+ .and empty_options
133
128
  end
134
129
 
135
130
  it "should support url_suffix for raw uploads" do
136
- expect(["test",{:url_suffix=>"hello", :private_cdn=>true, :resource_type=>:raw}])
131
+ expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :raw }])
137
132
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/files/test/hello")
138
- .and empty_options
133
+ .and empty_options
139
134
  end
140
135
 
141
136
  describe 'root_path support' do
142
137
 
143
138
  it "should allow use_root_path in shared distribution" do
144
139
  # expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true})}.to raise_error(CloudinaryException)
145
- expect(["test",{ :use_root_path => true, :private_cdn => false }])
140
+ expect(["test", { :use_root_path => true, :private_cdn => false }])
146
141
  .to produce_url("#{root_path}/test")
147
- .and empty_options
148
- expect(["test",{ :use_root_path => true, :private_cdn => false, :angle => 0 }])
142
+ .and empty_options
143
+ expect(["test", { :use_root_path => true, :private_cdn => false, :angle => 0 }])
149
144
  .to produce_url("#{root_path}/a_0/test")
150
- .and empty_options
145
+ .and empty_options
151
146
  end
152
147
 
153
148
  it "should support use_root_path for private_cdn" do
154
- expect(["test",{:use_root_path=>true, :private_cdn=>true}])
149
+ expect(["test", { :use_root_path => true, :private_cdn => true }])
155
150
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/test")
156
- .and empty_options
157
- expect(["test",{:use_root_path=>true, :private_cdn=>true, :angle=>0}])
151
+ .and empty_options
152
+ expect(["test", { :use_root_path => true, :private_cdn => true, :angle => 0 }])
158
153
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/a_0/test")
159
- .and empty_options
154
+ .and empty_options
160
155
  end
161
156
 
162
157
  it "should support use_root_path together with url_suffix for private_cdn" do
163
- expect(["test",{:use_root_path=>true, :url_suffix=>"hello", :private_cdn=>true}])
158
+ expect(["test", { :use_root_path => true, :url_suffix => "hello", :private_cdn => true }])
164
159
  .to produce_url("http://#{cloud_name}-res.cloudinary.com/test/hello")
165
- .and empty_options
160
+ .and empty_options
166
161
  end
167
162
 
168
163
  it "should disallow use_root_path if not image/upload" do
169
- expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :type=>:facebook})}.to raise_error(CloudinaryException)
170
- expect{Cloudinary::Utils.cloudinary_url("test", {:use_root_path=>true, :private_cdn=>true, :resource_type=>:raw})}.to raise_error(CloudinaryException)
164
+ expect { Cloudinary::Utils.cloudinary_url("test", { :use_root_path => true, :private_cdn => true, :type => :facebook }) }.to raise_error(CloudinaryException)
165
+ expect { Cloudinary::Utils.cloudinary_url("test", { :use_root_path => true, :private_cdn => true, :resource_type => :raw }) }.to raise_error(CloudinaryException)
171
166
  end
172
167
 
173
168
  end
174
169
  describe ":width, :height" do
175
170
  it "should use width and height from options only if crop is given" do
176
- expect(["test",{ :width => 100, :height => 100 }])
171
+ expect(["test", { :width => 100, :height => 100 }])
177
172
  .to produce_url("#{upload_path}/test")
178
- .and mutate_options_to({ :width => 100, :height => 100 })
179
- expect(["test",{ :width => 100, :height => 100, :crop => :crop }])
173
+ .and mutate_options_to({ :width => 100, :height => 100 })
174
+ expect(["test", { :width => 100, :height => 100, :crop => :crop }])
180
175
  .to produce_url("#{upload_path}/c_crop,h_100,w_100/test")
181
- .and mutate_options_to({ :width => 100, :height => 100 })
176
+ .and mutate_options_to({ :width => 100, :height => 100 })
182
177
  end
183
178
 
184
179
  it "should not pass width and height to html in case of fit, lfill or limit crop" do
185
- expect(["test",{ :width => 100, :height => 100, :crop => :limit }])
180
+ expect(["test", { :width => 100, :height => 100, :crop => :limit }])
186
181
  .to produce_url("#{upload_path}/c_limit,h_100,w_100/test")
187
- .and empty_options
188
- expect(["test",{ :width => 100, :height => 100, :crop => :lfill }])
182
+ .and empty_options
183
+ expect(["test", { :width => 100, :height => 100, :crop => :lfill }])
189
184
  .to produce_url("#{upload_path}/c_lfill,h_100,w_100/test")
190
- .and empty_options
191
- expect(["test",{ :width => 100, :height => 100, :crop => :fit }])
185
+ .and empty_options
186
+ expect(["test", { :width => 100, :height => 100, :crop => :fit }])
192
187
  .to produce_url("#{upload_path}/c_fit,h_100,w_100/test")
193
- .and empty_options
188
+ .and empty_options
194
189
  end
195
190
 
196
191
  it "should not pass width and height to html in case angle was used" do
197
- expect(["test",{ :width => 100, :height => 100, :crop => :scale, :angle => :auto }])
192
+ expect(["test", { :width => 100, :height => 100, :crop => :scale, :angle => :auto }])
198
193
  .to produce_url("#{upload_path}/a_auto,c_scale,h_100,w_100/test")
199
- .and empty_options
194
+ .and empty_options
200
195
  end
201
196
  it "should support size" do
202
- expect(["test",{ :size => "10x10", :crop => :crop }])
197
+ expect(["test", { :size => "10x10", :crop => :crop }])
203
198
  .to produce_url("#{upload_path}/c_crop,h_10,w_10/test")
204
- .and mutate_options_to({ :width => "10", :height => "10" })
199
+ .and mutate_options_to({ :width => "10", :height => "10" })
205
200
  end
206
201
  end
207
202
 
208
203
  it "should use x, y, radius, prefix, gravity and quality from options" do
209
- expect(["test",{ :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => 0.4, :prefix => "a" }])
204
+ expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => 0.4, :prefix => "a" }])
210
205
  .to produce_url("#{upload_path}/g_center,p_a,q_0.4,r_3,x_1,y_2/test")
211
- .and empty_options
206
+ .and empty_options
212
207
  end
213
208
 
214
209
  describe ":transformation" do
215
210
  it "should support named tranformation" do
216
- expect(["test",{ :transformation => "blip" }])
211
+ expect(["test", { :transformation => "blip" }])
217
212
  .to produce_url("#{upload_path}/t_blip/test")
218
- .and empty_options
213
+ .and empty_options
219
214
  end
220
215
 
221
216
  it "should support array of named tranformations" do
222
- expect(["test",{ :transformation => ["blip", "blop"] }])
217
+ expect(["test", { :transformation => ["blip", "blop"] }])
223
218
  .to produce_url("#{upload_path}/t_blip.blop/test")
224
- .and empty_options
219
+ .and empty_options
225
220
  end
226
221
 
227
222
  it "should support base tranformation" do
228
- expect(["test",{ :transformation => { :x => 100, :y => 100, :crop => :fill }, :crop => :crop, :width => 100 }])
223
+ expect(["test", { :transformation => { :x => 100, :y => 100, :crop => :fill }, :crop => :crop, :width => 100 }])
229
224
  .to produce_url("#{upload_path}/c_fill,x_100,y_100/c_crop,w_100/test")
230
- .and mutate_options_to({ :width => 100 })
225
+ .and mutate_options_to({ :width => 100 })
231
226
  end
232
227
 
233
228
  it "should support array of base tranformations" do
234
- expect(["test",{ :transformation => [{ :x => 100, :y => 100, :width => 200, :crop => :fill }, { :radius => 10 }], :crop => :crop, :width => 100 }])
229
+ expect(["test", { :transformation => [{ :x => 100, :y => 100, :width => 200, :crop => :fill }, { :radius => 10 }], :crop => :crop, :width => 100 }])
235
230
  .to produce_url("#{upload_path}/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test")
236
- .and mutate_options_to({ :width => 100 })
231
+ .and mutate_options_to({ :width => 100 })
237
232
  end
238
233
 
239
234
  it "should support array of tranformations" do
240
- result = Cloudinary::Utils.generate_transformation_string([{:x=>100, :y=>100, :width=>200, :crop=>:fill}, {:radius=>10}])
235
+ result = Cloudinary::Utils.generate_transformation_string([{ :x => 100, :y => 100, :width => 200, :crop => :fill }, { :radius => 10 }])
241
236
  expect(result).to eq("c_fill,w_200,x_100,y_100/r_10")
242
237
  end
243
238
 
244
239
  it "should not include empty tranformations" do
245
- expect(["test", { :transformation => [{}, { :x => 100, :y => 100, :crop => :fill },{}] }])
240
+ expect(["test", { :transformation => [{}, { :x => 100, :y => 100, :crop => :fill }, {}] }])
246
241
  .to produce_url("#{upload_path}/c_fill,x_100,y_100/test")
247
- .and empty_options
242
+ .and empty_options
248
243
  end
249
244
  end
250
245
 
@@ -354,11 +349,11 @@ describe Cloudinary::Utils do
354
349
  :type => 'authenticated',
355
350
  :tags => TEST_TAG
356
351
  end
357
- let(:options) {{ :version => authenticated_image['version'], :sign_url => true, :type => :authenticated }.merge(specific_options)}
352
+ let(:options) { { :version => authenticated_image['version'], :sign_url => true, :type => :authenticated }.merge(specific_options) }
358
353
  let(:authenticated_path) { "#{root_path}/image/authenticated" }
359
354
 
360
355
  it "should not serve resource with the wrong signature" do
361
- expect(authenticated_image["url"].sub(/(?:s--)([\w-]+)(?:--)/) {|s| s.succ})
356
+ expect(authenticated_image["url"].sub(/(?:s--)([\w-]+)(?:--)/) { |s| s.succ })
362
357
  .not_to be_served_by_cloudinary
363
358
  end
364
359
 
@@ -395,14 +390,14 @@ describe Cloudinary::Utils do
395
390
  { 'overlay' => :l, :underlay => :u }.each do |param, letter|
396
391
  describe param do
397
392
  let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
398
- # [name, options, result]
399
393
  let(:layers_options) { [
400
- ["string", "text:hello", "text:hello"],
401
- ["public_id", { "public_id" => "logo" }, "logo"],
402
- ["public_id with folder", { "public_id" => "folder/logo" }, "folder:logo"],
403
- ["private", { "public_id" => "logo", "type" => "private" }, "private:logo"],
404
- ["format", { "public_id" => "logo", "format" => "png" }, "logo.png"],
405
- ["video", { "resource_type" => "video", "public_id" => "cat" }, "video:cat"],
394
+ # [name, options, result]
395
+ ["string", "text:hello", "text:hello"],
396
+ ["public_id", { "public_id" => "logo" }, "logo"],
397
+ ["public_id with folder", { "public_id" => "folder/logo" }, "folder:logo"],
398
+ ["private", { "public_id" => "logo", "type" => "private" }, "private:logo"],
399
+ ["format", { "public_id" => "logo", "format" => "png" }, "logo.png"],
400
+ ["video", { "resource_type" => "video", "public_id" => "cat" }, "video:cat"],
406
401
  ] }
407
402
  it "should support #{param}" do
408
403
  layers_options.each do |name, options, result|
@@ -418,11 +413,11 @@ describe Cloudinary::Utils do
418
413
  end
419
414
  end
420
415
 
421
-
422
416
  describe "text" do
423
417
 
424
- text_layer = "Hello World, /Nice to meet you?"
418
+ text_layer = "Hello World, /Nice to meet you?"
425
419
  text_encoded = "Hello%20World%252C%20%252FNice%20to%20meet%20you%3F"
420
+
426
421
  before :all do
427
422
  Cloudinary::Uploader.text(text_layer, {
428
423
  :public_id => "test_text",
@@ -431,7 +426,7 @@ describe Cloudinary::Utils do
431
426
  :font_size => "18",
432
427
  :tags => TEST_TAG
433
428
  })
434
- srt = Tempfile.new('test_subtitles.srt')
429
+ srt = Tempfile.new(['test_subtitles', '.srt'])
435
430
  srt.write <<-END
436
431
  1
437
432
  00:00:10,500 --> 00:00:13,000
@@ -443,20 +438,18 @@ describe Cloudinary::Utils do
443
438
  srt.unlink
444
439
  end
445
440
 
446
- # after :all do
447
- # Cloudinary::Api.delete_resources_by_tag TEST_TAG
448
- # end
441
+ include_context "cleanup"
449
442
 
450
443
  { 'overlay' => 'l', 'underlay' => 'u' }.each do |param, short|
451
444
  describe param do
452
445
  let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
453
446
  # [name, options, result]
454
- layers_options= [
447
+ layers_options= [
455
448
  ["string", "text:test_text:hello", "text:test_text:hello"],
456
- ["explicit layer parameter", "text:test_text:#{text_encoded}", "text:test_text:#{text_encoded}" ],
457
- ["text parameter", { :public_id => "test_text", :text => text_layer }, "text:test_text:#{text_encoded}" ],
449
+ ["explicit layer parameter", "text:test_text:#{text_encoded}", "text:test_text:#{text_encoded}"],
450
+ ["text parameter", { :public_id => "test_text", :text => text_layer }, "text:test_text:#{text_encoded}"],
458
451
  ["text with font family and size parameters", { :text => text_layer, :font_family => "Arial", :font_size => "18" }, "text:Arial_18:#{text_encoded}"],
459
- ["text with text style parameter", { :text => text_layer, :font_family => "Arial", :font_size => "18", :font_weight => "bold", :font_style => "italic", :letter_spacing => 4 }, "text:Arial_18_bold_italic_letter_spacing_4:#{text_encoded}"],
452
+ ["text with text style parameter", { :text => text_layer, :font_family => "Arial", :font_size => "18", :font_weight => "bold", :font_style => "italic", :letter_spacing => 4, :line_spacing => 2 }, "text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2:#{text_encoded}"],
460
453
  ["subtitles", { :resource_type => "subtitles", :public_id => "subtitles.srt" }, "subtitles:subtitles.srt"],
461
454
  ["subtitles with font family and size", { :resource_type => "subtitles", :public_id => "subtitles.srt", :font_family => "Arial", :font_size => "40" }, "subtitles:Arial_40:subtitles.srt"]
462
455
  ]
@@ -466,7 +459,7 @@ describe Cloudinary::Utils do
466
459
  expect("#{upload_path}/#{short}_#{result}/sample").to be_served_by_cloudinary
467
460
  end
468
461
  unless options.is_a? String
469
- op = Hash.new
462
+ op = Hash.new
470
463
  op[param] = options
471
464
  it_behaves_like "a signed url", op, "#{short}_#{result}"
472
465
  end
@@ -483,131 +476,141 @@ describe Cloudinary::Utils do
483
476
  end
484
477
 
485
478
 
486
-
487
479
  it "should use ssl_detected if secure is not given as parameter and not set to true in configuration" do
488
- expect(["test",{:ssl_detected=>true}])
480
+ expect(["test", { :ssl_detected => true }])
489
481
  .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
490
- .and empty_options
482
+ .and empty_options
491
483
  end
492
484
 
493
485
  it "should use secure if given over ssl_detected and configuration" do
494
486
  Cloudinary.config.secure = true
495
- expect(["test",{ :ssl_detected => true, :secure => false }])
487
+ expect(["test", { :ssl_detected => true, :secure => false }])
496
488
  .to produce_url("#{upload_path}/test")
497
- .and empty_options
489
+ .and empty_options
498
490
  end
499
491
 
500
492
  it "should use secure: true from configuration over ssl_detected" do
501
493
  Cloudinary.config.secure = true
502
- expect(["test",{:ssl_detected=>false}])
494
+ expect(["test", { :ssl_detected => false }])
503
495
  .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
504
- .and empty_options
496
+ .and empty_options
505
497
  end
506
498
 
507
499
  it "should support extenal cname" do
508
- expect(["test",{:cname=>"hello.com"}])
500
+ expect(["test", { :cname => "hello.com" }])
509
501
  .to produce_url("http://hello.com/#{cloud_name}/image/upload/test")
510
- .and empty_options
502
+ .and empty_options
511
503
  end
512
504
 
513
505
  it "should support extenal cname with cdn_subdomain on" do
514
- expect(["test",{:cname=>"hello.com", :cdn_subdomain=>true}])
506
+ expect(["test", { :cname => "hello.com", :cdn_subdomain => true }])
515
507
  .to produce_url("http://a2.hello.com/#{cloud_name}/image/upload/test")
516
- .and empty_options
508
+ .and empty_options
517
509
  end
518
510
 
519
511
  it "should support cdn_subdomain with secure on if using shared_domain" do
520
- expect(["test",{:secure=>true, :cdn_subdomain=>true}])
512
+ expect(["test", { :secure => true, :cdn_subdomain => true }])
521
513
  .to produce_url("https://res-2.cloudinary.com/#{cloud_name}/image/upload/test")
522
- .and empty_options
514
+ .and empty_options
523
515
  end
524
516
 
525
517
  it "should support secure_cdn_subdomain false override with secure" do
526
- expect(["test",{:secure=>true, :cdn_subdomain=>true, :secure_cdn_subdomain=>false}])
518
+ expect(["test", { :secure => true, :cdn_subdomain => true, :secure_cdn_subdomain => false }])
527
519
  .to produce_url("https://res.cloudinary.com/#{cloud_name}/image/upload/test")
528
- .and empty_options
520
+ .and empty_options
529
521
  end
530
522
 
531
523
  it "should support secure_cdn_subdomain true override with secure" do
532
- expect(["test",{:secure=>true, :cdn_subdomain=>true, :secure_cdn_subdomain=>true, :private_cdn=>true}])
524
+ expect(["test", { :secure => true, :cdn_subdomain => true, :secure_cdn_subdomain => true, :private_cdn => true }])
533
525
  .to produce_url("https://#{cloud_name}-res-2.cloudinary.com/image/upload/test")
534
- .and empty_options
526
+ .and empty_options
535
527
  end
536
528
 
537
529
  it "should support string param" do
538
- expect(["test",{ "effect" => { "sepia" => 10 } }])
530
+ expect(["test", { "effect" => { "sepia" => 10 } }])
539
531
  .to produce_url("#{upload_path}/e_sepia:10/test")
540
- .and empty_options
532
+ .and empty_options
541
533
  end
542
534
 
543
535
  it "should support border" do
544
- expect(["test",{ "border" => { :width => 5 } }])
536
+ expect(["test", { "border" => { :width => 5 } }])
545
537
  .to produce_url("#{upload_path}/bo_5px_solid_black/test")
546
- .and empty_options
547
- expect(["test",{ "border" => { :width => 5, :color => "#ffaabbdd" } }])
538
+ .and empty_options
539
+ expect(["test", { "border" => { :width => 5, :color => "#ffaabbdd" } }])
548
540
  .to produce_url("#{upload_path}/bo_5px_solid_rgb:ffaabbdd/test")
549
- .and empty_options
550
- expect(["test",{ "border" => "1px_solid_blue" }])
541
+ .and empty_options
542
+ expect(["test", { "border" => "1px_solid_blue" }])
551
543
  .to produce_url("#{upload_path}/bo_1px_solid_blue/test")
552
- .and empty_options
544
+ .and empty_options
553
545
  expect(["test", { "border" => "2" }]).to produce_url("#{upload_path}/test").and mutate_options_to({ :border => "2" })
554
546
  end
555
547
 
556
548
  it "should support flags" do
557
- expect(["test",{ "flags" => "abc" }])
549
+ expect(["test", { "flags" => "abc" }])
558
550
  .to produce_url("#{upload_path}/fl_abc/test")
559
- .and empty_options
560
- expect(["test",{ "flags" => ["abc", "def"] }])
551
+ .and empty_options
552
+ expect(["test", { "flags" => ["abc", "def"] }])
561
553
  .to produce_url("#{upload_path}/fl_abc.def/test")
562
- .and empty_options
554
+ .and empty_options
555
+ end
556
+
557
+ it "should support aspect ratio" do
558
+ expect(["test", { "aspect_ratio" => "1.0" }])
559
+ .to produce_url("#{upload_path}/ar_1.0/test")
560
+ .and empty_options
561
+ expect(["test", { "aspect_ratio" => "3:2" }])
562
+ .to produce_url("#{upload_path}/ar_3:2/test")
563
+ .and empty_options
563
564
  end
564
565
 
565
566
  it "build_upload_params should not destroy options" do
566
- options = {:width=>100, :crop=>:scale}
567
+ options = { :width => 100, :crop => :scale }
567
568
  expect(Cloudinary::Uploader.build_upload_params(options)[:transformation]).to eq("c_scale,w_100")
568
569
  expect(options.length).to eq(2)
569
570
  end
570
571
 
571
572
  it "build_upload_params canonize booleans" do
572
- options = {:backup=>true, :use_filename=>false, :colors=>:true,
573
- :image_metadata=>:false, :invalidate=>1}
574
- params = Cloudinary::Uploader.build_upload_params(options)
575
- expect(Cloudinary::Api.only(params, *options.keys)).to eq(
576
- :backup=>1, :use_filename=>0, :colors=>1,
577
- :image_metadata=>0, :invalidate=>1
578
- )
579
- options = {:colors=>"true", :exif=>"false", :eager_async=>"1"}
580
- params = Cloudinary::Uploader.build_upload_params(options)
581
- expect(Cloudinary::Api.only(params, *options.keys)).to eq(
582
- :exif=>0, :colors=>1, :eager_async=>1
583
- )
584
- expect(Cloudinary::Uploader.build_upload_params(:backup=>nil)[:backup]).to be_nil
573
+ options = { :backup => true, :use_filename => false, :colors => :true,
574
+ :image_metadata => :false, :invalidate => 1 }
575
+ params = Cloudinary::Uploader.build_upload_params(options)
576
+ expect(Cloudinary::Api.only(params, *options.keys))
577
+ .to eq(:backup => 1,
578
+ :use_filename => 0,
579
+ :colors => 1,
580
+ :image_metadata => 0,
581
+ :invalidate => 1
582
+ )
583
+ options = { :colors => "true", :exif => "false", :eager_async => "1" }
584
+ params = Cloudinary::Uploader.build_upload_params(options)
585
+ expect(Cloudinary::Api.only(params, *options.keys))
586
+ .to eq(:exif => 0, :colors => 1, :eager_async => 1)
587
+ expect(Cloudinary::Uploader.build_upload_params(:backup => nil)[:backup]).to be_nil
585
588
  expect(Cloudinary::Uploader.build_upload_params({})[:backup]).to be_nil
586
589
  end
587
590
 
588
591
  it "should add version if public_id contains /" do
589
592
  expect(["folder/test", {}])
590
- .to produce_url( "#{upload_path}/v1/folder/test")
591
- .and empty_options
592
- expect(["folder/test",{ :version => 123 }])
593
+ .to produce_url("#{upload_path}/v1/folder/test")
594
+ .and empty_options
595
+ expect(["folder/test", { :version => 123 }])
593
596
  .to produce_url("#{upload_path}/v123/folder/test")
594
- .and empty_options
597
+ .and empty_options
595
598
  end
596
599
 
597
600
  it "should not add version if public_id contains version already" do
598
601
  expect(["v1234/test", {}])
599
- .to produce_url( "#{upload_path}/v1234/test")
600
- .and empty_options
602
+ .to produce_url("#{upload_path}/v1234/test")
603
+ .and empty_options
601
604
  end
602
605
 
603
606
  it "should allow to shorted image/upload urls" do
604
- expect(["test",{ :shorten => true }])
607
+ expect(["test", { :shorten => true }])
605
608
  .to produce_url("#{root_path}/iu/test")
606
- .and empty_options
609
+ .and empty_options
607
610
  end
608
611
 
609
612
  it "should allow to use folders in PreloadedFile" do
610
- signature = Cloudinary::Utils.api_sign_request({:public_id=>"folder/file", :version=>"1234"}, Cloudinary.config.api_secret)
613
+ signature = Cloudinary::Utils.api_sign_request({ :public_id => "folder/file", :version => "1234" }, Cloudinary.config.api_secret)
611
614
  preloaded = Cloudinary::PreloadedFile.new("image/upload/v1234/folder/file.jpg#" + signature)
612
615
  expect(preloaded).to be_valid
613
616
  end
@@ -621,7 +624,7 @@ describe Cloudinary::Utils do
621
624
  ["a??b", "a%3F%3Fb"],
622
625
  ["parentheses(interject)", "parentheses%28interject%29"]
623
626
  ].each do
624
- |source, target|
627
+ |source, target|
625
628
  expect(Cloudinary::Utils.cloudinary_url(source)).to eq("#{upload_path}/#{target}")
626
629
  end
627
630
  end
@@ -636,29 +639,33 @@ describe Cloudinary::Utils do
636
639
  end
637
640
 
638
641
  it "should correctly sign_request" do
639
- params = Cloudinary::Utils.sign_request({
640
- :cloud_name => "demo",
641
- :api_key => "1234",
642
- :api_secret => "b",
643
- :public_id=>"folder/file",
644
- :version=>"1234"})
645
- expect(params).to include(
646
- :signature=>"bc812f98b6c86c7a4e7779324f554d7c010d3510"
642
+ params = Cloudinary::Utils.sign_request(
643
+ {
644
+ :public_id => "folder/file",
645
+ :version => "1234" },
646
+ {
647
+ :cloud_name => "demo",
648
+ :api_key => "1234",
649
+ :api_secret => "b"
650
+ }
647
651
  )
652
+ expect(params).to include(:signature => "7a3349cbb373e4812118d625047ede50b90e7b67")
648
653
  end
649
654
 
650
655
  it "should support responsive width" do
651
- expect(["test",{ :width => 100, :height => 100, :crop => :crop, :responsive_width => true }])
656
+ expect(["test", { :width => 100, :height => 100, :crop => :crop, :responsive_width => true }])
652
657
  .to produce_url("#{upload_path}/c_crop,h_100,w_100/c_limit,w_auto/test")
653
- .and mutate_options_to({ :responsive => true })
654
- Cloudinary.config.responsive_width_transformation = {:width => :auto, :crop => :pad}
658
+ .and mutate_options_to({ :responsive => true })
659
+ Cloudinary.config.responsive_width_transformation = { :width => :auto, :crop => :pad }
655
660
  expect(["test", { :width => 100, :height => 100, :crop => :crop, :responsive_width => true }])
656
- .to produce_url( "#{upload_path}/c_crop,h_100,w_100/c_pad,w_auto/test")
657
- .and mutate_options_to( { :responsive => true })
661
+ .to produce_url("#{upload_path}/c_crop,h_100,w_100/c_pad,w_auto/test")
662
+ .and mutate_options_to({ :responsive => true })
658
663
  end
659
664
 
660
665
  it "should correctly encode double arrays" do
661
- expect(Cloudinary::Utils.encode_double_array([1,2,3,4])).to eq("1,2,3,4")
662
- expect(Cloudinary::Utils.encode_double_array([[1,2,3,4],[5,6,7,8]])).to eq("1,2,3,4|5,6,7,8")
666
+ expect(Cloudinary::Utils.encode_double_array([1, 2, 3, 4])).to eq("1,2,3,4")
667
+ expect(Cloudinary::Utils.encode_double_array([[1, 2, 3, 4], [5, 6, 7, 8]])).to eq("1,2,3,4|5,6,7,8")
663
668
  end
669
+
670
+
664
671
  end