cloudinary 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,13 @@ require 'cloudinary'
3
3
  require 'rest_client'
4
4
  require 'zip'
5
5
 
6
- ARCHIVE_TAG = "archive_test_tag_#{rand}"
7
-
8
6
  RSpec.shared_context 'archive' do
7
+
9
8
  before :all do
10
9
  Cloudinary::Uploader.upload(
11
10
  "http://res.cloudinary.com/demo/image/upload/sample.jpg",
12
11
  :public_id => 'tag_samplebw',
13
- :tags => [TEST_TAG, ARCHIVE_TAG],
12
+ :tags => [TEST_TAG, TIMESTAMP_TAG],
14
13
  :transformation => {
15
14
  :effect => :blackwhite
16
15
  }
@@ -18,13 +17,13 @@ RSpec.shared_context 'archive' do
18
17
  Cloudinary::Uploader.upload(
19
18
  "http://res.cloudinary.com/demo/image/upload/sample.jpg",
20
19
  :public_id => 'tag_sample',
21
- :tags => [TEST_TAG, ARCHIVE_TAG],
20
+ :tags => [TEST_TAG, TIMESTAMP_TAG],
22
21
  :transformation => {
23
22
  :effect => :blackwhite
24
23
  }
25
24
  )
26
25
  end
27
- include_context "cleanup"
26
+ include_context "cleanup", TIMESTAMP_TAG
28
27
  end
29
28
 
30
29
  describe Cloudinary::Utils do
@@ -37,7 +36,7 @@ describe Cloudinary::Utils do
37
36
  {
38
37
  :target_public_id => 'gem_archive_test',
39
38
  :public_ids => %w(tag_sample tag_samplebw),
40
- :target_tags => [TEST_TAG, ARCHIVE_TAG]
39
+ :target_tags => [TEST_TAG, TIMESTAMP_TAG]
41
40
  }.merge(options))
42
41
  }
43
42
 
@@ -62,12 +61,15 @@ describe Cloudinary::Uploader do
62
61
  let(:options) { {} }
63
62
 
64
63
  describe '.create_archive' do
64
+ let!(:target_public_id) {
65
+ "gem_test#{ rand(1000000)}"
66
+ }
65
67
  let!(:archive_result) {
66
68
  Cloudinary::Uploader.create_archive(
67
69
  {
68
- :target_public_id => 'gem_archive_test',
70
+ :target_public_id => target_public_id,
69
71
  :public_ids => %w(tag_sample tag_samplebw),
70
- :tags => ARCHIVE_TAG
72
+ :tags => [TEST_TAG, TIMESTAMP_TAG]
71
73
  }.merge(options))
72
74
  }
73
75
  let(:options) { { :mode => :create } }
@@ -5,6 +5,7 @@ require 'rest_client'
5
5
 
6
6
  TEST_IMAGE_URL = "http://cloudinary.com/images/old_logo.png"
7
7
  TEST_TAG = 'cloudinary_gem_test'
8
+ TIMESTAMP_TAG = "#{TEST_TAG}_#{rand(999999999)}_#{RUBY_VERSION}_#{ defined? Rails::version ? Rails::version : 'no_rails'}"
8
9
 
9
10
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
11
  RSpec.configure do |config|
@@ -15,12 +16,20 @@ RSpec.configure do |config|
15
16
  config.filter_run_excluding :delete_all => true
16
17
  end
17
18
 
18
- RSpec.shared_context "cleanup" do
19
+ RSpec.shared_context "cleanup" do |tag|
20
+ tag ||= TEST_TAG
19
21
  after :all do
20
- Cloudinary::Api.delete_resources_by_tag(TEST_TAG) unless Cloudinary.config.keep_test_products
22
+ Cloudinary::Api.delete_resources_by_tag(tag) unless Cloudinary.config.keep_test_products
21
23
  end
22
24
 
23
25
  end
26
+
27
+
28
+ CALLS_SERVER_WITH_PARAMETERS = "calls server with parameters"
29
+ RSpec.shared_examples CALLS_SERVER_WITH_PARAMETERS do |expected|
30
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected))
31
+ end
32
+
24
33
  # Create a regexp with the given +tag+ name.
25
34
  def html_tag_matcher( tag)
26
35
  /<#{tag}([\s]+([-[:word:]]+)[\s]*\=\s*\"([^\"]*)\")*\s*>.*<\s*\/#{tag}\s*>/
@@ -157,9 +166,54 @@ end
157
166
  RSpec::Matchers.define :deep_hash_value do |expected|
158
167
  match do |actual|
159
168
  expected.all? do |path, value|
160
- values_match? deep_fetch(actual, path), value
169
+ Cloudinary.values_match? deep_fetch(actual, path), value
161
170
  end
162
171
  end
163
172
  end
164
173
 
165
- RSpec::Matchers.alias_matcher :have_deep_hash_values_of, :deep_hash_value
174
+ RSpec::Matchers.alias_matcher :have_deep_hash_values_of, :deep_hash_value
175
+
176
+ module Cloudinary
177
+ # @api private
178
+ def self.values_match?( actual, expected)
179
+ if Hash === actual
180
+ return hashes_match?(expected, actual) if Hash === expected
181
+ elsif Array === expected && Enumerable === actual && !(Struct === actual)
182
+ return arrays_match?(expected, actual.to_a)
183
+ elsif Regexp === expected
184
+ return expected.match actual.to_s
185
+ end
186
+
187
+
188
+ return true if actual == expected
189
+
190
+ begin
191
+ expected === actual
192
+ rescue ArgumentError
193
+ # Some objects, like 0-arg lambdas on 1.9+, raise
194
+ # ArgumentError for `expected === actual`.
195
+ false
196
+ end
197
+ end
198
+
199
+ # @private
200
+ def self.arrays_match?(expected_list, actual_list)
201
+ return false if expected_list.size != actual_list.size
202
+
203
+ expected_list.zip(actual_list).all? do |expected, actual|
204
+ values_match?(expected, actual)
205
+ end
206
+ end
207
+
208
+ # @private
209
+ def self.hashes_match?(expected_hash, actual_hash)
210
+ return false if expected_hash.size != actual_hash.size
211
+
212
+ expected_hash.all? do |expected_key, expected_value|
213
+ actual_value = actual_hash.fetch(expected_key) { return false }
214
+ values_match?(expected_value, actual_value)
215
+ end
216
+ end
217
+
218
+ private_class_method :arrays_match?, :hashes_match?
219
+ end
@@ -7,14 +7,14 @@ 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
+ include_context "cleanup", TIMESTAMP_TAG
11
11
 
12
12
  TEST_IMG = "spec/logo.png"
13
13
  TEST_IMG_W = 241
14
14
  TEST_IMG_H = 51
15
15
 
16
16
  it "should successfully upload file" do
17
- result = Cloudinary::Uploader.upload(TEST_IMG, :tags => TEST_TAG)
17
+ result = Cloudinary::Uploader.upload(TEST_IMG, :tags => [TEST_TAG, TIMESTAMP_TAG])
18
18
  expect(result["width"]).to eq(TEST_IMG_W)
19
19
  expect(result["height"]).to eq(TEST_IMG_H)
20
20
  expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
@@ -22,12 +22,12 @@ describe Cloudinary::Uploader do
22
22
  end
23
23
 
24
24
  it "should successfully upload a file from pathname", :pathname => true do
25
- result = Cloudinary::Uploader.upload(Pathname.new(TEST_IMG), :tags => TEST_TAG)
25
+ result = Cloudinary::Uploader.upload(Pathname.new(TEST_IMG), :tags => [TEST_TAG, TIMESTAMP_TAG])
26
26
  expect(result["width"]).to eq(TEST_IMG_W)
27
27
  end
28
28
 
29
29
  it "should successfully upload file by url" do
30
- result = Cloudinary::Uploader.upload("http://cloudinary.com/images/old_logo.png", :tags => TEST_TAG)
30
+ result = Cloudinary::Uploader.upload("http://cloudinary.com/images/old_logo.png", :tags => [TEST_TAG, TIMESTAMP_TAG])
31
31
  expect(result["width"]).to eq(TEST_IMG_W)
32
32
  expect(result["height"]).to eq(TEST_IMG_H)
33
33
  expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
@@ -36,9 +36,9 @@ describe Cloudinary::Uploader do
36
36
 
37
37
  describe '.rename' do
38
38
  before(:all) do
39
- @result = Cloudinary::Uploader.upload(TEST_IMG, :tags => TEST_TAG)
39
+ @result = Cloudinary::Uploader.upload(TEST_IMG, :tags => [TEST_TAG, TIMESTAMP_TAG])
40
40
  @resource_1_id = @result["public_id"]
41
- result = Cloudinary::Uploader.upload("spec/favicon.ico", :tags => TEST_TAG)
41
+ result = Cloudinary::Uploader.upload("spec/favicon.ico", :tags => [TEST_TAG, TIMESTAMP_TAG])
42
42
  @resource_2_id = result["public_id"]
43
43
  end
44
44
 
@@ -55,115 +55,148 @@ describe Cloudinary::Uploader do
55
55
  end
56
56
  context ':overwrite => true' do
57
57
  it 'should rename to an existing ID' do
58
- new_id = Cloudinary::Uploader.upload(TEST_IMG, :tags => TEST_TAG)["public_id"]
58
+ new_id = Cloudinary::Uploader.upload(TEST_IMG, :tags => [TEST_TAG, TIMESTAMP_TAG])["public_id"]
59
59
  Cloudinary::Uploader.rename(@resource_2_id, new_id, :overwrite => true)
60
60
  expect(Cloudinary::Api.resource(new_id)["format"]).to eq("ico")
61
61
  @resource_2_id = new_id # will not update if expect fails
62
62
  end
63
63
  end
64
64
  context ':invalidate => true' do
65
- it 'should notidy the server to invalidate the resource in the CDN' do
65
+ it 'should notify the server to invalidate the resource in the CDN' do
66
66
  # Can't test the result, so we just verify the parameter is send to the server
67
- expect(RestClient::Request).to receive(:execute).with(deep_hash_value([:payload, :invalidate] => 1))
67
+ expected ={
68
+ :url => /.*\/rename$/,
69
+ [:payload, :invalidate] => 1,
70
+ [:payload, :from_public_id] => @resource_2_id,
71
+ [:payload, :to_public_id] => @resource_2_id+"2"
72
+ }
73
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected))
68
74
  Cloudinary::Uploader.rename(@resource_2_id, @resource_2_id+"2", :invalidate => true) # will not affect the server
69
75
  end
70
76
 
71
77
  end
72
78
  end
73
79
 
74
-
75
80
  it "should support explicit" do
81
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :public_id] => "sample", [:payload, :eager] => "c_scale,w_2.0"))
76
82
  result = Cloudinary::Uploader.explicit("sample", :type=>"upload", :eager=>[{:crop=>"scale", :width=>"2.0"}])
77
- url = Cloudinary::Utils.cloudinary_url("sample", :type=>"upload", :crop=>"scale", :width=>"2.0", :format=>"jpg", :version=>result["version"])
78
- expect(result["eager"][0]["url"]).to eq(url)
79
83
  end
80
84
 
81
85
  it "should support eager" do
82
- Cloudinary::Uploader.upload(TEST_IMG, :eager =>[{ :crop =>"scale", :width =>"2.0"}], :tags => TEST_TAG)
86
+ Cloudinary::Uploader.upload(TEST_IMG, :eager =>[{ :crop =>"scale", :width =>"2.0"}], :tags => [TEST_TAG, TIMESTAMP_TAG])
83
87
  end
84
88
 
85
89
  it "should support headers" do
86
- Cloudinary::Uploader.upload(TEST_IMG, :headers =>["Link: 1"], :tags => TEST_TAG)
87
- Cloudinary::Uploader.upload(TEST_IMG, :headers =>{ "Link" => "1"}, :tags => TEST_TAG)
90
+ Cloudinary::Uploader.upload(TEST_IMG, :headers =>["Link: 1"], :tags => [TEST_TAG, TIMESTAMP_TAG])
91
+ Cloudinary::Uploader.upload(TEST_IMG, :headers =>{ "Link" => "1"}, :tags => [TEST_TAG, TIMESTAMP_TAG])
88
92
  end
89
93
 
90
94
  it "should successfully generate text image" do
91
- result = Cloudinary::Uploader.text("hello world", :tags => TEST_TAG)
95
+ result = Cloudinary::Uploader.text("hello world", :tags => [TEST_TAG, TIMESTAMP_TAG])
92
96
  expect(result["width"]).to be > 1
93
97
  expect(result["height"]).to be > 1
94
98
  end
95
99
 
96
- it "should correctly handle tags" do
97
- new_tag = "tag#{rand(10000)}"
98
- result = Cloudinary::Uploader.upload(TEST_IMG, :tags => TEST_TAG)
99
- Cloudinary::Uploader.add_tag("#{new_tag}_1", result["public_id"])
100
- Cloudinary::Uploader.add_tag("#{new_tag}_2", result["public_id"])
101
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_1", "#{new_tag}_2", TEST_TAG])
102
- Cloudinary::Uploader.remove_tag("#{new_tag}_1", result["public_id"])
103
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_2", TEST_TAG])
104
- Cloudinary::Uploader.replace_tag("#{new_tag}_3", result["public_id"])
105
- expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_3"])
106
- end
100
+ describe "tag" do
101
+ describe "add_tag" do
102
+ it "should correctly handle tags" do
103
+ expected ={
104
+ :url => /.*\/tags/,
105
+ [:payload, :tag] => "new_tag",
106
+ [:payload, :public_ids] => ["some_public_id"],
107
+ [:payload, :command] => "add"
108
+ }
109
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected))
110
+
111
+ Cloudinary::Uploader.add_tag( "new_tag", "some_public_id")
112
+ end
113
+ describe ":exclusive" do
114
+ it "should support :exclusive" do
115
+ expected ={
116
+ :url => /.*\/tags/,
117
+ [:payload, :tag] => "new_tag",
118
+ [:payload, :public_ids] => ["some_public_id"],
119
+ [:payload, :command] => "set_exclusive"
120
+ }
121
+ expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected))
122
+
123
+ Cloudinary::Uploader.add_tag( "new_tag", "some_public_id", :exclusive => true)
124
+ end
125
+ end
126
+
127
+
128
+
129
+ end
130
+
131
+ # Cloudinary::Uploader.add_tag("#{new_tag}_2", result["public_id"])
132
+ # expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_1", "#{new_tag}_2", TEST_TAG, TIMESTAMP_TAG])
133
+ # Cloudinary::Uploader.remove_tag("#{new_tag}_1", result["public_id"])
134
+ # expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_2", TEST_TAG, TIMESTAMP_TAG])
135
+ # Cloudinary::Uploader.replace_tag("#{new_tag}_3", result["public_id"])
136
+ # expect(Cloudinary::Api.resource(result["public_id"])["tags"]).to match_array(["#{new_tag}_3"])
137
+ end
138
+
139
+
107
140
 
108
141
  it "should correctly handle unique_filename" do
109
- result = Cloudinary::Uploader.upload(TEST_IMG, :use_filename => true, :tags => TEST_TAG)
142
+ result = Cloudinary::Uploader.upload(TEST_IMG, :use_filename => true, :tags => [TEST_TAG, TIMESTAMP_TAG])
110
143
  expect(result["public_id"]).to match(/logo_[a-zA-Z0-9]{6}/)
111
- result = Cloudinary::Uploader.upload(TEST_IMG, :use_filename => true, :unique_filename => false, :tags => TEST_TAG)
144
+ result = Cloudinary::Uploader.upload(TEST_IMG, :use_filename => true, :unique_filename => false, :tags => [TEST_TAG, TIMESTAMP_TAG])
112
145
  expect(result["public_id"]).to eq("logo")
113
146
  end
114
147
 
115
148
  it "should allow whitelisted formats if allowed_formats", :allowed=>true do
116
- result = Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["png"], :tags => TEST_TAG)
149
+ result = Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["png"], :tags => [TEST_TAG, TIMESTAMP_TAG])
117
150
  expect(result["format"]).to eq("png")
118
151
  end
119
152
 
120
153
  it "should prevent non whitelisted formats from being uploaded if allowed_formats is specified", :allowed=>true do
121
- expect{Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["jpg"], :tags => TEST_TAG)}.to raise_error
154
+ expect{Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["jpg"], :tags => [TEST_TAG, TIMESTAMP_TAG])}.to raise_error
122
155
  end
123
156
 
124
157
  it "should allow non whitelisted formats if type is specified and convert to that type", :allowed=>true do
125
- result = Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["jpg"], :format => "jpg", :tags => TEST_TAG)
158
+ result = Cloudinary::Uploader.upload(TEST_IMG, :allowed_formats => ["jpg"], :format => "jpg", :tags => [TEST_TAG, TIMESTAMP_TAG])
126
159
  expect(result["format"]).to eq("jpg")
127
160
  end
128
161
 
129
162
  it "should allow sending face coordinates" do
130
163
  coordinates = [[120, 30, 109, 150], [121, 31, 110, 151]]
131
- result = Cloudinary::Uploader.upload(TEST_IMG, { :face_coordinates => coordinates, :faces => true, :tags => TEST_TAG})
164
+ result = Cloudinary::Uploader.upload(TEST_IMG, { :face_coordinates => coordinates, :faces => true, :tags => [TEST_TAG, TIMESTAMP_TAG]})
132
165
  expect(result["faces"]).to eq(coordinates)
133
166
 
134
167
  different_coordinates = [[122, 32, 111, 152]]
135
- Cloudinary::Uploader.explicit(result["public_id"], {:face_coordinates => different_coordinates, :faces => true, :type => "upload", :tags => TEST_TAG})
168
+ Cloudinary::Uploader.explicit(result["public_id"], {:face_coordinates => different_coordinates, :faces => true, :type => "upload", :tags => [TEST_TAG, TIMESTAMP_TAG]})
136
169
  info = Cloudinary::Api.resource(result["public_id"], {:faces => true})
137
170
  expect(info["faces"]).to eq(different_coordinates)
138
171
  end
139
172
 
140
173
  it "should allow sending context" do
141
174
  context = {"caption" => "some caption", "alt" => "alternative"}
142
- result = Cloudinary::Uploader.upload(TEST_IMG, { :context => context, :tags => TEST_TAG})
175
+ result = Cloudinary::Uploader.upload(TEST_IMG, { :context => context, :tags => [TEST_TAG, TIMESTAMP_TAG]})
143
176
  info = Cloudinary::Api.resource(result["public_id"], {:context => true})
144
177
  expect(info["context"]).to eq({"custom" => context})
145
178
  end
146
179
 
147
180
  it "should support requesting manual moderation" do
148
- result = Cloudinary::Uploader.upload(TEST_IMG, { :moderation => :manual, :tags => TEST_TAG})
181
+ result = Cloudinary::Uploader.upload(TEST_IMG, { :moderation => :manual, :tags => [TEST_TAG, TIMESTAMP_TAG]})
149
182
  expect(result["moderation"][0]["status"]).to eq("pending")
150
183
  expect(result["moderation"][0]["kind"]).to eq("manual")
151
184
  end
152
185
 
153
186
  it "should support requesting raw conversion" do
154
- 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/)
187
+ expect{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal, :tags => [TEST_TAG, TIMESTAMP_TAG]})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
155
188
  end
156
189
 
157
190
  it "should support requesting categorization" do
158
- expect{Cloudinary::Uploader.upload(TEST_IMG, { :categorization => :illegal, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Illegal value|not a valid|is invalid/)
191
+ expect{Cloudinary::Uploader.upload(TEST_IMG, { :categorization => :illegal, :tags => [TEST_TAG, TIMESTAMP_TAG]})}.to raise_error(CloudinaryException, /Illegal value|not a valid|is invalid/)
159
192
  end
160
193
 
161
194
  it "should support requesting detection" do
162
- expect{Cloudinary::Uploader.upload(TEST_IMG, { :detection => :illegal, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
195
+ expect{Cloudinary::Uploader.upload(TEST_IMG, { :detection => :illegal, :tags => [TEST_TAG, TIMESTAMP_TAG]})}.to raise_error(CloudinaryException, /Illegal value|not a valid/)
163
196
  end
164
197
 
165
198
  it "should support requesting auto_tagging" do
166
- expect{Cloudinary::Uploader.upload(TEST_IMG, { :auto_tagging => 0.5, :tags => TEST_TAG})}.to raise_error(CloudinaryException, /Must use/)
199
+ expect{Cloudinary::Uploader.upload(TEST_IMG, { :auto_tagging => 0.5, :tags => [TEST_TAG, TIMESTAMP_TAG]})}.to raise_error(CloudinaryException, /Must use/)
167
200
  end
168
201
 
169
202
  it "should support upload_large", :large => true do
@@ -172,10 +205,10 @@ describe Cloudinary::Uploader do
172
205
  io.puts(header)
173
206
  5880000.times{ io.write("\xFF") }
174
207
  io.rewind
175
- result = Cloudinary::Uploader.upload_large(io, :chunk_size => 5243000, :tags => TEST_TAG)
208
+ result = Cloudinary::Uploader.upload_large(io, :chunk_size => 5243000, :tags => [TEST_TAG, TIMESTAMP_TAG])
176
209
  expect(result["resource_type"]).to eq('raw')
177
210
  io.rewind
178
- result = Cloudinary::Uploader.upload_large(io, :resource_type => 'image', :chunk_size => 5243000, :tags => TEST_TAG)
211
+ result = Cloudinary::Uploader.upload_large(io, :resource_type => 'image', :chunk_size => 5243000, :tags => [TEST_TAG, TIMESTAMP_TAG])
179
212
  expect(result["resource_type"]).to eq('image')
180
213
  expect(result["width"]).to eq(1400)
181
214
  expect(result["height"]).to eq(1400)
@@ -188,12 +221,12 @@ describe Cloudinary::Uploader do
188
221
  end
189
222
 
190
223
  it "should support unsigned uploading using presets", :upload_preset => true do
191
- preset = Cloudinary::Api.create_upload_preset(:folder => "test_folder_upload", :unsigned => true, :tags => TEST_TAG)
224
+ preset = Cloudinary::Api.create_upload_preset(:folder => "test_folder_upload", :unsigned => true, :tags => [TEST_TAG, TIMESTAMP_TAG])
192
225
 
193
226
  Cloudinary.config.api_key = nil
194
227
  Cloudinary.config.api_secret = nil
195
228
 
196
- result = Cloudinary::Uploader.unsigned_upload(TEST_IMG, preset["name"], :tags => TEST_TAG)
229
+ result = Cloudinary::Uploader.unsigned_upload(TEST_IMG, preset["name"], :tags => [TEST_TAG, TIMESTAMP_TAG])
197
230
  expect(result["public_id"]).to match(/^test_folder_upload\/[a-z0-9]+$/)
198
231
 
199
232
  Cloudinary.class_variable_set(:@@config, nil)
@@ -211,13 +244,13 @@ describe Cloudinary::Uploader do
211
244
  end
212
245
 
213
246
  it "should fail if timeout is reached" do
214
- expect{Cloudinary::Uploader.upload(Pathname.new(TEST_IMG), :tags => TEST_TAG)}.to raise_error
247
+ expect{Cloudinary::Uploader.upload(Pathname.new(TEST_IMG), :tags => [TEST_TAG, TIMESTAMP_TAG])}.to raise_error
215
248
  end
216
249
  end
217
250
 
218
251
  context ":responsive_breakpoints" do
219
252
  context ":create_derived" do
220
- result = Cloudinary::Uploader.upload(TEST_IMG, :responsive_breakpoints => { :create_derived => false }, :tags => TEST_TAG)
253
+ result = Cloudinary::Uploader.upload(TEST_IMG, :responsive_breakpoints => { :create_derived => false }, :tags => [TEST_TAG, TIMESTAMP_TAG])
221
254
  it 'should return a responsive_breakpoints in the response' do
222
255
  expect(result).to include('responsive_breakpoints')
223
256
  end
@@ -228,7 +261,7 @@ describe Cloudinary::Uploader do
228
261
  context ":invalidate" do
229
262
  it 'should pass the invalidate value to the server' do
230
263
  expect(RestClient::Request).to receive(:execute).with(deep_hash_value( [:payload, :invalidate] => 1))
231
- Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}], :invalidate => true, :tags => TEST_TAG)
264
+ Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}], :invalidate => true, :tags => [TEST_TAG, TIMESTAMP_TAG])
232
265
  end
233
266
  end
234
267
  end
@@ -349,6 +349,18 @@ describe Cloudinary::Utils do
349
349
  .and empty_options
350
350
  end
351
351
 
352
+ it "should support keyframe_interval" do
353
+ expect(["test", { :keyframe_interval => 10 }])
354
+ .to produce_url("#{upload_path}/ki_10/test")
355
+ .and empty_options
356
+ end
357
+
358
+ it "should support streaming_profile" do
359
+ expect(["test", { :streaming_profile => "some-profile" }])
360
+ .to produce_url("#{upload_path}/sp_some-profile/test")
361
+ .and empty_options
362
+ end
363
+
352
364
  shared_examples "a signed url" do |specific_options = {}, specific_transformation = ""|
353
365
  let(:expected_transformation) do
354
366
  (specific_transformation.blank? || specific_transformation.match(/\/$/)) ? specific_transformation : "#{specific_transformation}/"
@@ -361,23 +373,16 @@ describe Cloudinary::Utils do
361
373
  let(:options) { { :version => authenticated_image['version'], :sign_url => true, :type => :authenticated }.merge(specific_options) }
362
374
  let(:authenticated_path) { "#{root_path}/image/authenticated" }
363
375
 
364
- it "should not serve resource with the wrong signature" do
365
- expect(authenticated_image["url"].sub(/(?:s--)([\w-]+)(?:--)/) { |s| s.succ })
366
- .not_to be_served_by_cloudinary
367
- end
368
-
369
376
  it "should correctly sign URL with version" do
370
377
  expect(["#{authenticated_image['public_id']}.jpg", options])
371
378
  .to produce_url(%r"#{authenticated_path}/s--[\w-]+--/#{expected_transformation}v#{authenticated_image['version']}/#{authenticated_image['public_id']}.jpg")
372
379
  .and empty_options
373
- .and be_served_by_cloudinary
374
380
  end
375
381
  it "should correctly sign URL with transformation and version" do
376
382
  options[:transformation] = { :crop => "crop", :width => 10, :height => 20 }
377
383
  expect(["#{authenticated_image['public_id']}.jpg", options])
378
384
  .to produce_url(%r"#{authenticated_path}/s--[\w-]+--/c_crop,h_20,w_10/#{expected_transformation}v#{authenticated_image['version']}/#{authenticated_image['public_id']}.jpg")
379
385
  .and empty_options
380
- .and be_served_by_cloudinary
381
386
  end
382
387
  it "should correctly sign URL with transformation" do
383
388
  options[:transformation] = { :crop => "crop", :width => 10, :height => 20 }
@@ -391,7 +396,6 @@ describe Cloudinary::Utils do
391
396
  expect(["http://res.cloudinary.com/demo/sample.png", options])
392
397
  .to produce_url(%r"^#{root_path}/image/fetch/s--[\w-]+--/#{expected_transformation}v#{authenticated_image['version']}/http://res.cloudinary.com/demo/sample.png$")
393
398
  .and empty_options
394
- .and be_served_by_cloudinary
395
399
  end
396
400
  end
397
401
 
@@ -449,7 +453,7 @@ describe Cloudinary::Utils do
449
453
 
450
454
  include_context "cleanup"
451
455
 
452
- { 'overlay' => 'l', 'underlay' => 'u' }.each do |param, short|
456
+ { 'overlay' => 'l' }.each do |param, short| # 'underlay' => 'u' behaves the same as overlay
453
457
  describe param do
454
458
  let(:root_path) { "http://res.cloudinary.com/#{cloud_name}" }
455
459
  # [name, options, result]
@@ -465,9 +469,9 @@ describe Cloudinary::Utils do
465
469
  layers_options.each do |name, options, result|
466
470
  it "should support #{name}" do
467
471
  expect(["sample.jpg", { param => options }]).to produce_url("#{upload_path}/#{short}_#{result}/sample.jpg").and empty_options
468
- expect("#{upload_path}/#{short}_#{result}/sample.jpg").to be_served_by_cloudinary
472
+ # expect("#{upload_path}/#{short}_#{result}/sample.jpg").to be_served_by_cloudinary
469
473
  end
470
- unless options.is_a? String
474
+ unless options.is_a? String || param == 'underlay'
471
475
  op = Hash.new
472
476
  op[param] = options
473
477
  it_behaves_like "a signed url", op, "#{short}_#{result}"