cloudinary 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7614adaac6c80b6af25b391e1224a492c609fde8
4
- data.tar.gz: 726d2520ec2adbb6d91b5ec6b1bceb46071d58e9
3
+ metadata.gz: 07e321996ca2cae3a8eec12d27de1aed453853e7
4
+ data.tar.gz: 579c2b752735619c42ae516c9cbec268136ddbbe
5
5
  SHA512:
6
- metadata.gz: 760b8e34412a2e4272edc42032aa6abf92cb655472dccd4c35e39126adbce44660b44a0210956ebf28708bc5bb234504f17799023b7062bf6812c257d7aca072
7
- data.tar.gz: 9b8869009e05cb9ee5b100cd5652a49e653aedd992dc350a55375a527dff0b5209d0fdadce221d8c7253a3c4b7dca66d2e5b8bcfcd1fb469b8bfa692d562604a
6
+ metadata.gz: 4f0bdc46e84bf87fb80a1ea3a3934088b2079d910f4dfcdbe192f1318c760d386b639d66d902d5ccdfedba3a90827483c96c0c7ff6cc2ad50fd594e389b2b8e8
7
+ data.tar.gz: 1b80560e163319804899b0aa6fb378fcdedc260ae087977938a3de172d88b0ffff762dfa0b8b9688a9cbfde2facfe956ce1b67e6eada52d874ababd16ceb5176
@@ -1,4 +1,11 @@
1
1
 
2
+ 1.8.1 / 2017-05-16
3
+ ==================
4
+
5
+ * Fix `image_path`. Fixes #257
6
+ * Add Auto Gravity modes tests.
7
+ * Use correct values in Search tests
8
+
2
9
  1.8.0 / 2017-05-01
3
10
  ==================
4
11
 
@@ -77,19 +77,14 @@ class Cloudinary::Static
77
77
 
78
78
  # ## Cloudinary::Utils support ###
79
79
  def public_id_and_resource_type_from_path(path)
80
- metadata = build_metadata
80
+ @metadata ||= build_metadata
81
81
  path = path.sub(/^\//, '')
82
- data = metadata[path]
83
- unless data
84
- public_prefixes.each do |prefix|
85
- if metadata[File.join(prefix, path)]
86
- data = metadata[File.join(prefix, path)]
87
- break
88
- end
89
- end
82
+ prefix = public_prefixes.find {|prefix| @metadata[File.join(prefix, path)]}
83
+ if prefix
84
+ [@metadata[File.join(prefix, path)]['public_id'], resource_type(path)]
85
+ else
86
+ nil
90
87
  end
91
- return unless data
92
- [data['public_id'], resource_type(path)]
93
88
  end
94
89
 
95
90
  private
@@ -375,20 +375,16 @@ class Cloudinary::Utils
375
375
  resource_type ||= "image"
376
376
  source = source.to_s
377
377
  if !force_remote
378
+ static_support = Cloudinary.config.static_file_support || Cloudinary.config.static_image_support
379
+ return original_source if !static_support && type == "asset"
378
380
  return original_source if (type.nil? || type == "asset") && source.match(%r(^https?:/)i)
381
+ return original_source if source.match(%r(^/(?!images/).*)) # starts with / but not /images/
382
+
383
+ source = source.sub(%r(^/images/), '') # remove /images/ prefix - backwards compatibility
379
384
  if type == "asset"
380
- # config.static_image_support left for backwards compatibility
381
- if (Cloudinary.config.static_file_support || Cloudinary.config.static_image_support) && defined?(Cloudinary::Static)
382
- source, resource_type = Cloudinary::Static.public_id_and_resource_type_from_path(source)
383
- end
384
- return original_source unless source
385
- source += File.extname(original_source) if !format
386
- elsif source.start_with?("/")
387
- if source.start_with?("/images/")
388
- source = source.sub(%r(/images/), '')
389
- else
390
- return original_source
391
- end
385
+ source, resource_type = Cloudinary::Static.public_id_and_resource_type_from_path(source)
386
+ return original_source unless source # asset not found in Static
387
+ source += File.extname(original_source) unless format
392
388
  end
393
389
  end
394
390
 
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.8.0"
3
+ VERSION = "1.8.1"
4
4
  end
@@ -141,4 +141,50 @@ RSpec.describe CloudinaryHelper do
141
141
  end
142
142
 
143
143
  end
144
+ describe "image_path" do
145
+
146
+ before :all do
147
+ class Cloudinary::Static
148
+ class << self
149
+ def reset_metadata
150
+ @metadata = nil
151
+ @static_file_config = nil
152
+ @public_prefixes = nil
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ before :each do
159
+ @static_support = Cloudinary.config.static_image_support
160
+ @static_file = Cloudinary::Static::METADATA_FILE
161
+ Cloudinary::Static.reset_metadata
162
+ end
163
+
164
+ after :each do
165
+ Cloudinary.config.static_image_support = @static_support
166
+ Cloudinary::Static::METADATA_FILE = @static_file
167
+ Cloudinary::Static.reset_metadata
168
+ end
169
+
170
+ context 'type=="asset"' do
171
+ it "should not transform images staring with /" do
172
+ expect(helper.image_path('/bar')).to eq('/bar')
173
+ end
174
+ it "should not transform images staring with /images unless asset is found and static_support is true" do
175
+ Cloudinary.config.static_image_support = false
176
+ expect(helper.image_path('/images/foo.jpg')).to eq('/images/foo.jpg')
177
+ expect(helper.image_path('some-folder/foo.gif')).to eq("/images/some-folder/foo.gif")
178
+ Cloudinary::Static::METADATA_FILE = "spec/sample_asset_file.tsv"
179
+ Cloudinary::Static.reset_metadata
180
+ expect(helper.image_path('/images/foo.jpg'))
181
+ .to eq("/images/foo.jpg")
182
+ expect(helper.image_path('some-folder/foo.gif')).to eq("/images/some-folder/foo.gif")
183
+ Cloudinary.config.static_image_support = true
184
+ expect(helper.image_path('/images/foo.jpg')).to eq("http://res.cloudinary.com/sdk-test/image/asset/images-foo.jpg")
185
+ expect(helper.image_path('foo.jpg')).to eq("http://res.cloudinary.com/sdk-test/image/asset/images-foo.jpg")
186
+ expect(helper.image_path('some-folder/foo.gif')).to eq('/images/some-folder/foo.gif')
187
+ end
188
+ end
189
+ end
144
190
  end
@@ -89,15 +89,31 @@ describe 'cloudinary:sync_static' do
89
89
 
90
90
  context 'Cloudinary::Utils.cloudinary_url' do
91
91
  def all_asset_forms_of(public_id)
92
- [public_id, "/#{public_id}", public_id.split('/').last]
92
+ [ "/#{public_id}", public_id.split('/').last]
93
93
  end
94
94
 
95
95
  RSpec::Matchers.define :be_asset_mapped_by_cloudinary_url_to do |expected|
96
96
  match do |actual|
97
+ actual = [actual] unless actual.respond_to? :all?
97
98
  actual.all? do |public_path|
98
- Cloudinary::Utils.cloudinary_url(public_path, :cloud_name => 'test', :type => 'asset') == expected
99
+ @public_path = public_path
100
+ @actual = Cloudinary::Utils.cloudinary_url(public_path, :cloud_name => 'test', :type => 'asset')
101
+ @actual == expected
99
102
  end
100
103
  end
104
+ failure_message do |actual|
105
+ "URL for '#{@public_path}' should have been '#{expected}' but was '#{@actual}'.#{ differ.diff_as_string(@actual, expected)}"
106
+ end
107
+ failure_message_when_negated do |actual|
108
+ "URL for '#{@public_path}' should not have been '#{expected}'."
109
+ end
110
+ def differ
111
+ RSpec::Support::Differ.new(
112
+ :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) },
113
+ :color => RSpec::Matchers.configuration.color?
114
+ )
115
+ end
116
+
101
117
  end
102
118
 
103
119
  before(:each) do
@@ -122,9 +138,12 @@ describe 'cloudinary:sync_static' do
122
138
  allow(Cloudinary.config).to receive(:static_file_support).and_return(true)
123
139
  subject.invoke
124
140
 
125
- expect(all_asset_forms_of('images/logo1.png')).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
126
- expect(all_asset_forms_of('javascripts/1.js')).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
127
- expect(all_asset_forms_of('stylesheets/1.css')).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
141
+ expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
142
+ expect('images/logo1.png').not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
143
+ expect('1.js').to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
144
+ expect(['javascripts/1.js', '/javascripts/1.js']).not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-b01de57adb485efdde843154d030644e.js')
145
+ expect('1.css').to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
146
+ expect(['stylesheets/1.css', '/stylesheets/1.css']).not_to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/raw/asset/1-f24cc6123afd401ab86d8596cabc619f.css')
128
147
 
129
148
  # without :type => 'asset'
130
149
  expect(Cloudinary::Utils.cloudinary_url('logo1.png')).not_to include('7dc60722d4653261648038b579fdb89e')
@@ -134,7 +153,7 @@ describe 'cloudinary:sync_static' do
134
153
  allow(Cloudinary.config).to receive(:static_image_support).and_return(true)
135
154
  subject.invoke
136
155
 
137
- expect(all_asset_forms_of('images/logo1.png')).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
156
+ expect(['logo1.png', '/images/logo1.png']).to be_asset_mapped_by_cloudinary_url_to('http://res.cloudinary.com/test/image/asset/logo1-7dc60722d4653261648038b579fdb89e.png')
138
157
  end
139
158
  end
140
159
 
@@ -0,0 +1,4 @@
1
+ public_path public_id upload_time.to_i version width height
2
+ stylesheets/foo.css css-foo 123 1 100 100
3
+ javascripts/bar.js bar 123 1 100 100
4
+ images/foo.jpg images-foo 123 1 100 100
@@ -27,13 +27,13 @@ describe Cloudinary::Search do
27
27
  end
28
28
 
29
29
  it 'should add max_results to query' do
30
- query = Cloudinary::Search.max_results('format:jpg').to_h
31
- expect(query).to eq(max_results: 'format:jpg')
30
+ query = Cloudinary::Search.max_results(10).to_h
31
+ expect(query).to eq(max_results: 10)
32
32
  end
33
33
 
34
34
  it 'should add next_cursor to query' do
35
- query = Cloudinary::Search.next_cursor('format:jpg').to_h
36
- expect(query).to eq(next_cursor: 'format:jpg')
35
+ query = Cloudinary::Search.next_cursor('ASDFIUHASF9832HAFSOF').to_h
36
+ expect(query).to eq(next_cursor: 'ASDFIUHASF9832HAFSOF')
37
37
  end
38
38
 
39
39
  it 'should add aggregations arguments as array to query' do
@@ -2,6 +2,9 @@ require 'rspec'
2
2
  require 'rexml/parsers/ultralightparser'
3
3
  require 'rspec/version'
4
4
  require 'rest_client'
5
+ require 'cloudinary'
6
+
7
+ Cloudinary.config.enhance_image_tag = true
5
8
 
6
9
  TEST_IMAGE_URL = "http://cloudinary.com/images/old_logo.png"
7
10
  TEST_IMG = "spec/logo.png"
@@ -252,6 +252,40 @@ describe Cloudinary::Utils do
252
252
  .to produce_url("#{upload_path}/c_crop,g_auto,w_0.5/test")
253
253
  .and empty_options
254
254
  end
255
+
256
+ describe "gravity" do
257
+ it "should support auto" do
258
+ expect(["test", {width: 100, height: 100, crop: 'crop', gravity: 'auto'}])
259
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto,h_100,w_100/test")
260
+ .and mutate_options_to({width: 100, height: 100})
261
+ expect(["test", {width: 100, height: 100, crop: 'crop', gravity: 'auto'}])
262
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto,h_100,w_100/test")
263
+ .and mutate_options_to({width: 100, height: 100})
264
+ end
265
+ it "should support focal gravity" do
266
+ ["adv_face", "adv_faces", "adv_eyes", "face", "faces", "body", "no_faces"].each do |focal|
267
+ expect(["test", {width: 100, height: 100, crop: 'crop', gravity: "auto:#{focal}"}])
268
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto:#{focal},h_100,w_100/test")
269
+ .and mutate_options_to({width: 100, height: 100})
270
+ end
271
+ end
272
+ it "should support auto level with thumb cropping" do
273
+ [0, 10, 100].each do |level|
274
+ expect(["test", {width: 100, height: 100, crop: 'thumb', gravity: "auto:#{level}"}])
275
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_thumb,g_auto:#{level},h_100,w_100/test")
276
+ .and mutate_options_to({width: 100, height: 100})
277
+ expect(["test", {width: 100, height: 100, crop: 'thumb', gravity: "auto:adv_faces:#{level}"}])
278
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_thumb,g_auto:adv_faces:#{level},h_100,w_100/test")
279
+ .and mutate_options_to({width: 100, height: 100})
280
+ end
281
+ end
282
+ it "should support custom_no_override" do
283
+ expect(["test", {width: 100, height: 100, crop: 'crop', gravity: "auto:custom_no_override"}])
284
+ .to produce_url("http://res.cloudinary.com/#{cloud_name}/image/upload/c_crop,g_auto:custom_no_override,h_100,w_100/test")
285
+ .and mutate_options_to({width: 100, height: 100})
286
+ end
287
+ end
288
+
255
289
  describe ":quality" do
256
290
  it "support a percent value" do
257
291
  expect(["test", { :x => 1, :y => 2, :radius => 3, :gravity => :center, :quality => 80, :prefix => "a" }])
@@ -270,6 +304,7 @@ describe Cloudinary::Utils do
270
304
 
271
305
  end
272
306
  end
307
+
273
308
  describe ":transformation" do
274
309
  it "should support named tranformation" do
275
310
  expect(["test", { :transformation => "blip" }])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadav Soferman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-04-30 00:00:00.000000000 Z
13
+ date: 2017-05-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws_cf_signer
@@ -181,6 +181,7 @@ files:
181
181
  - spec/favicon.ico
182
182
  - spec/logo.png
183
183
  - spec/rake_spec.rb
184
+ - spec/sample_asset_file.tsv
184
185
  - spec/search_spec.rb
185
186
  - spec/spec_helper.rb
186
187
  - spec/streaminig_profiles_api_spec.rb
@@ -223,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
224
  version: '0'
224
225
  requirements: []
225
226
  rubyforge_project: cloudinary
226
- rubygems_version: 2.4.5.1
227
+ rubygems_version: 2.6.10
227
228
  signing_key:
228
229
  specification_version: 4
229
230
  summary: Client library for easily using the Cloudinary service
@@ -240,6 +241,7 @@ test_files:
240
241
  - spec/favicon.ico
241
242
  - spec/logo.png
242
243
  - spec/rake_spec.rb
244
+ - spec/sample_asset_file.tsv
243
245
  - spec/search_spec.rb
244
246
  - spec/spec_helper.rb
245
247
  - spec/streaminig_profiles_api_spec.rb