cloudinary 1.13.0 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/cloudinary.gemspec +1 -2
  4. data/lib/active_storage/service/cloudinary_service.rb +0 -1
  5. data/lib/cloudinary/utils.rb +1 -1
  6. data/lib/cloudinary/version.rb +1 -1
  7. metadata +3 -185
  8. data/spec/access_control_spec.rb +0 -102
  9. data/spec/active_storage/Gemfile +0 -12
  10. data/spec/active_storage/application_system_test_case.rb +0 -5
  11. data/spec/active_storage/database/create_users_migration.rb +0 -9
  12. data/spec/active_storage/database/setup.rb +0 -7
  13. data/spec/active_storage/dummy/Rakefile +0 -5
  14. data/spec/active_storage/dummy/app/assets/config/manifest.js +0 -3
  15. data/spec/active_storage/dummy/app/assets/javascripts/application.js +0 -13
  16. data/spec/active_storage/dummy/app/assets/stylesheets/application.css +0 -15
  17. data/spec/active_storage/dummy/app/controllers/application_controller.rb +0 -5
  18. data/spec/active_storage/dummy/app/helpers/application_helper.rb +0 -4
  19. data/spec/active_storage/dummy/app/jobs/application_job.rb +0 -4
  20. data/spec/active_storage/dummy/app/models/application_record.rb +0 -5
  21. data/spec/active_storage/dummy/app/views/layouts/application.html.erb +0 -14
  22. data/spec/active_storage/dummy/bin/bundle +0 -5
  23. data/spec/active_storage/dummy/bin/rails +0 -6
  24. data/spec/active_storage/dummy/bin/rake +0 -6
  25. data/spec/active_storage/dummy/bin/yarn +0 -11
  26. data/spec/active_storage/dummy/config.ru +0 -7
  27. data/spec/active_storage/dummy/config/application.rb +0 -22
  28. data/spec/active_storage/dummy/config/boot.rb +0 -7
  29. data/spec/active_storage/dummy/config/database.yml +0 -25
  30. data/spec/active_storage/dummy/config/environment.rb +0 -7
  31. data/spec/active_storage/dummy/config/environments/development.rb +0 -52
  32. data/spec/active_storage/dummy/config/environments/production.rb +0 -83
  33. data/spec/active_storage/dummy/config/environments/test.rb +0 -38
  34. data/spec/active_storage/dummy/config/initializers/application_controller_renderer.rb +0 -7
  35. data/spec/active_storage/dummy/config/initializers/assets.rb +0 -16
  36. data/spec/active_storage/dummy/config/initializers/backtrace_silencers.rb +0 -8
  37. data/spec/active_storage/dummy/config/initializers/cookies_serializer.rb +0 -7
  38. data/spec/active_storage/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  39. data/spec/active_storage/dummy/config/initializers/inflections.rb +0 -17
  40. data/spec/active_storage/dummy/config/initializers/mime_types.rb +0 -5
  41. data/spec/active_storage/dummy/config/initializers/wrap_parameters.rb +0 -16
  42. data/spec/active_storage/dummy/config/routes.rb +0 -4
  43. data/spec/active_storage/dummy/config/secrets.yml +0 -32
  44. data/spec/active_storage/dummy/config/spring.rb +0 -8
  45. data/spec/active_storage/dummy/config/storage.yml +0 -3
  46. data/spec/active_storage/dummy/config/webpacker.yml +0 -72
  47. data/spec/active_storage/dummy/package.json +0 -5
  48. data/spec/active_storage/dummy/public/404.html +0 -67
  49. data/spec/active_storage/dummy/public/422.html +0 -67
  50. data/spec/active_storage/dummy/public/500.html +0 -66
  51. data/spec/active_storage/dummy/public/apple-touch-icon-precomposed.png +0 -0
  52. data/spec/active_storage/dummy/public/apple-touch-icon.png +0 -0
  53. data/spec/active_storage/dummy/public/favicon.ico +0 -0
  54. data/spec/active_storage/fixtures/files/colors.bmp +0 -0
  55. data/spec/active_storage/fixtures/files/empty_file.txt +0 -0
  56. data/spec/active_storage/fixtures/files/favicon.ico +0 -0
  57. data/spec/active_storage/fixtures/files/icon.psd +0 -0
  58. data/spec/active_storage/fixtures/files/icon.svg +0 -13
  59. data/spec/active_storage/fixtures/files/image.gif +0 -0
  60. data/spec/active_storage/fixtures/files/racecar.jpg +0 -0
  61. data/spec/active_storage/fixtures/files/racecar.tif +0 -0
  62. data/spec/active_storage/fixtures/files/racecar_rotated.jpg +0 -0
  63. data/spec/active_storage/fixtures/files/report.pdf +0 -0
  64. data/spec/active_storage/fixtures/files/rotated_video.mp4 +0 -0
  65. data/spec/active_storage/fixtures/files/video.mp4 +0 -0
  66. data/spec/active_storage/fixtures/files/video_with_rectangular_samples.mp4 +0 -0
  67. data/spec/active_storage/fixtures/files/video_with_undefined_display_aspect_ratio.mp4 +0 -0
  68. data/spec/active_storage/fixtures/files/video_without_video_stream.mp4 +0 -0
  69. data/spec/active_storage/service/cloudinary_service_spec.rb +0 -107
  70. data/spec/active_storage/service/configurations.yml +0 -4
  71. data/spec/active_storage/test_helper.rb +0 -43
  72. data/spec/api_spec.rb +0 -623
  73. data/spec/archive_spec.rb +0 -145
  74. data/spec/auth_token_spec.rb +0 -77
  75. data/spec/cache_spec.rb +0 -109
  76. data/spec/cloudinary_helper_spec.rb +0 -327
  77. data/spec/cloudinary_spec.rb +0 -56
  78. data/spec/data/sync_static/app/assets/javascripts/1.coffee +0 -1
  79. data/spec/data/sync_static/app/assets/javascripts/1.js +0 -1
  80. data/spec/data/sync_static/app/assets/stylesheets/1.css +0 -3
  81. data/spec/docx.docx +0 -0
  82. data/spec/favicon.ico +0 -0
  83. data/spec/image_spec.rb +0 -107
  84. data/spec/logo.png +0 -0
  85. data/spec/movie.mp4 +0 -0
  86. data/spec/rake_spec.rb +0 -160
  87. data/spec/sample_asset_file.tsv +0 -4
  88. data/spec/search_spec.rb +0 -109
  89. data/spec/spec_helper.rb +0 -273
  90. data/spec/storage_spec.rb +0 -44
  91. data/spec/streaminig_profiles_api_spec.rb +0 -74
  92. data/spec/support/helpers/temp_file_helpers.rb +0 -22
  93. data/spec/support/shared_contexts/rake.rb +0 -19
  94. data/spec/uploader_spec.rb +0 -409
  95. data/spec/utils_methods_spec.rb +0 -81
  96. data/spec/utils_spec.rb +0 -1052
  97. data/spec/video_tag_spec.rb +0 -253
  98. data/spec/video_url_spec.rb +0 -185
data/spec/archive_spec.rb DELETED
@@ -1,145 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
- require 'rest_client'
4
- require 'zip'
5
-
6
- RSpec.shared_context 'archive' do
7
-
8
- before :all do
9
- Cloudinary::Uploader.upload(
10
- "http://res.cloudinary.com/demo/image/upload/sample.jpg",
11
- :public_id => 'tag_samplebw',
12
- :tags => [TEST_TAG, TIMESTAMP_TAG],
13
- :transformation => {
14
- :effect => :blackwhite
15
- }
16
- )
17
- Cloudinary::Uploader.upload(
18
- "http://res.cloudinary.com/demo/image/upload/sample.jpg",
19
- :public_id => 'tag_sample',
20
- :tags => [TEST_TAG, TIMESTAMP_TAG],
21
- :transformation => {
22
- :effect => :blackwhite
23
- }
24
- )
25
- Cloudinary::Uploader.upload(
26
- "http://res.cloudinary.com/demo/image/upload/sample.jpg",
27
- :public_id => 'tag_sample_raw.jpg',
28
- :resource_type => 'raw',
29
- :tags => [TEST_TAG, TIMESTAMP_TAG],
30
- )
31
- end
32
- include_context "cleanup", TIMESTAMP_TAG
33
- end
34
-
35
- describe Cloudinary::Utils do
36
- include_context 'archive'
37
-
38
- describe '.generate_zip_download_url' do
39
- let(:options) { {} }
40
- let!(:archive_result) {
41
- Cloudinary::Utils.download_zip_url(
42
- {
43
- :target_public_id => 'gem_archive_test',
44
- :public_ids => %w(tag_sample tag_samplebw),
45
- :target_tags => [TEST_TAG, TIMESTAMP_TAG]
46
- }.merge(options))
47
- }
48
-
49
- describe 'public_ids' do
50
- it 'should generate a valid url' do
51
- expect(archive_result).not_to be_empty
52
- end
53
- it 'should include two files' do
54
- Zip::File.open_buffer(RestClient.get(archive_result)) do |zip_file|
55
- list = zip_file.glob('*').map(&:name)
56
- expect(list.length).to be(2)
57
- expect(list).to include('tag_sample.jpg', 'tag_samplebw.jpg')
58
- end
59
- end
60
- end
61
- end
62
- end
63
-
64
- describe Cloudinary::Uploader do
65
- include_context 'archive'
66
-
67
- let(:options) { {} }
68
-
69
- describe '.create_archive' do
70
- let!(:target_public_id) {
71
- "gem_test#{ SUFFIX}"
72
- }
73
- expected_keys = %w(
74
- resource_type
75
- type
76
- public_id
77
- version
78
- url
79
- secure_url
80
- created_at
81
- tags
82
- signature
83
- bytes
84
- etag
85
- resource_count
86
- file_count
87
- )
88
- let!(:archive_result) {
89
- Cloudinary::Uploader.create_archive(
90
- {
91
- :target_public_id => target_public_id,
92
- :public_ids => %w(tag_sample tag_samplebw),
93
- :tags => [TEST_TAG, TIMESTAMP_TAG],
94
- :transformations => [{width: 100, height: 100, crop: "fill"},{effect: "grayscale"}],
95
- :skip_transformation_name => true
96
- }.merge(options))
97
- }
98
- let(:options) { { :mode => :create } }
99
- it 'should return a Hash with suitable set of keys' do
100
- expect(archive_result).to be_a(Hash)
101
- expect(archive_result.keys).to include(*expected_keys)
102
- end
103
- end
104
- describe 'create archive based on raw resources and missing public IDs' do
105
- let!(:target_public_id) {
106
- "gem_test#{ SUFFIX}"
107
- }
108
- let!(:archive_result) {
109
- Cloudinary::Uploader.create_archive(
110
- {
111
- :target_public_id => target_public_id,
112
- :public_ids => %w(tag_sample_raw.jpg non-wxisting-resource),
113
- :resource_type => 'raw',
114
- :allow_missing => true
115
- }.merge(options))
116
- }
117
- let(:options) { { :mode => :create } }
118
- it 'should skip missing public IDs and successfully generate the archive containing raw resources' do
119
- expect(archive_result).to be_a(Hash)
120
- expect(archive_result["resource_count"]).to equal(1)
121
- end
122
- end
123
- describe '.create_zip' do
124
- it 'should call create_archive with "zip" format' do
125
- expect(Cloudinary::Uploader).to receive(:create_archive).with({ :tags => TEST_TAG }, "zip")
126
- Cloudinary::Uploader.create_zip({ :tags => TEST_TAG })
127
- end
128
- end
129
- describe '.create_archive based on fully_qualified_public_ids' do
130
- it 'should allow you to generate an archive by specifying multiple resource_types' do
131
- test_ids = %W(image/upload/#{TEST_IMG} video/upload/#{TEST_VIDEO} raw/upload/#{TEST_RAW})
132
- expected = {
133
- [:payload, :fully_qualified_public_ids] => test_ids,
134
- [:url] => %r"/auto/generate_archive$"
135
- }
136
- expect(RestClient::Request).to receive(:execute).with(deep_hash_value(expected))
137
- Cloudinary::Uploader.create_archive(
138
- {
139
- :resource_type => :auto,
140
- :fully_qualified_public_ids => test_ids
141
- }
142
- )
143
- end
144
- end
145
- end
@@ -1,77 +0,0 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require 'cloudinary'
4
-
5
- describe 'auth_token' do
6
-
7
- before :each do
8
- Cloudinary.reset_config
9
- Cloudinary.config_from_url 'cloudinary://a:b@test123'
10
- Cloudinary.config.auth_token = { :key => KEY, :duration => 300, :start_time => 11111111 }
11
- end
12
- it "should generate with start and duration" do
13
- token = Cloudinary::Utils.generate_auth_token :start_time => 1111111111, :acl => "/image/*", :duration => 300
14
- expect(token).to eq '__cld_token__=st=1111111111~exp=1111111411~acl=%2fimage%2f*~hmac=1751370bcc6cfe9e03f30dd1a9722ba0f2cdca283fa3e6df3342a00a7528cc51'
15
- end
16
-
17
- describe "authenticated url" do
18
- before :each do
19
- Cloudinary.class_variable_set :@@config, nil
20
- Cloudinary.config_from_url 'cloudinary://a:b@test123'
21
- Cloudinary.config :private_cdn => true
22
- Cloudinary.config.auth_token = { :key => KEY, :duration => 300, :start_time => 11111111 }
23
-
24
- end
25
- it "should add token if authToken is globally set and signed = true" do
26
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :sign_url => true, :resource_type => "image", :type => "authenticated", :version => "1486020273"
27
- expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3")
28
-
29
- end
30
- it "should add token for 'public' resource" do
31
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :sign_url => true, :resource_type => "image", :type => "public", :version => "1486020273"
32
- expect(url).to eq("http://test123-res.cloudinary.com/image/public/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=c2b77d9f81be6d89b5d0ebc67b671557e88a40bcf03dd4a6997ff4b994ceb80e")
33
-
34
- end
35
- it "should not add token if signed is false" do
36
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :type => "authenticated", :version => "1486020273"
37
- expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg")
38
-
39
- end
40
- it "should not add token if authToken is globally set but null auth token is explicitly set and signed = true" do
41
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :auth_token => false, :sign_url => true, :type => "authenticated", :version => "1486020273"
42
- expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/s--v2fTPYTu--/v1486020273/sample.jpg")
43
-
44
- end
45
- it "explicit authToken should override global setting" do
46
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :sign_url => true, :auth_token => { :key => ALT_KEY, :start_time => 222222222, :duration => 100 }, :type => "authenticated", :transformation => { :crop => "scale", :width => 300 }
47
- expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/c_scale,w_300/sample.jpg?__cld_token__=st=222222222~exp=222222322~hmac=55cfe516530461213fe3b3606014533b1eca8ff60aeab79d1bb84c9322eebc1f")
48
-
49
- end
50
- it "should compute expiration as start time + duration" do
51
- token = { :key => KEY, :start_time => 11111111, :duration => 300 }
52
- url = Cloudinary::Utils.cloudinary_url "sample.jpg", :sign_url => true, :auth_token => token, :resource_type => "image", :type => "authenticated", :version => "1486020273"
53
- expect(url).to eq("http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3")
54
-
55
- end
56
- it "should raise if key is not provided" do
57
- Cloudinary.config.auth_token[:key] = nil
58
- token = { :expiration => 111111, :duration => 0 }
59
- expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_error(/Missing auth token key configuration/)
60
- end
61
- it "should raise if expiration and duration are not provided" do
62
- token = { :key => KEY, :expiration => 0, :duration => 0 }
63
- expect{Cloudinary::Utils.generate_auth_token(token)}.to raise_error(/Must provide either expiration or duration/)
64
- end
65
- end
66
- describe "authentication token" do
67
- it "should generate token string" do
68
- user = "foobar" # we can't rely on the default "now" value in tests
69
- tokenOptions = { :key => KEY, :duration => 300, :acl => "/*/t_#{user}" }
70
- tokenOptions[:start_time] = 222222222 # we can't rely on the default "now" value in tests
71
- cookieToken = Cloudinary::Utils.generate_auth_token tokenOptions
72
- expect(cookieToken).to eq("__cld_token__=st=222222222~exp=222222522~acl=%2f*%2ft_foobar~hmac=8e39600cc18cec339b21fe2b05fcb64b98de373355f8ce732c35710d8b10259f")
73
-
74
- end
75
- end
76
- end
77
-
data/spec/cache_spec.rb DELETED
@@ -1,109 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
- require 'cloudinary/cache'
4
- require 'rspec'
5
- require 'active_support/cache'
6
-
7
- describe 'Responsive cache' do
8
-
9
- before :all do
10
- Cloudinary.reset_config
11
- unless defined? Rails and defined? Rails.cache
12
- module Rails
13
- class << self
14
- attr_accessor :cache
15
- end
16
- Rails.cache = ActiveSupport::Cache::FileStore.new("#{Dir.getwd}/../tmp/cache")
17
- end
18
- end
19
-
20
- Cloudinary::config.use_cache = true
21
- Cloudinary::Cache.storage= Rails.cache
22
- @i=0
23
- end
24
-
25
- after :all do
26
- # Rails.cache.clear
27
- end
28
-
29
- def get_cache
30
- Rails.cache.fetch CACHE_KEY do
31
- @i = @i + 1
32
- end
33
- end
34
- it 'should cache breakpoints' do
35
- j = get_cache
36
- j = get_cache
37
-
38
- expect(j).to eql(1)
39
- expect(@i).to eql(1)
40
- end
41
-
42
- it 'should cache upload results' do
43
- result = Cloudinary::Uploader.upload(
44
- TEST_IMG,
45
- :tags => [TEST_TAG, TIMESTAMP_TAG],
46
- responsive_breakpoints: [
47
- {
48
- create_derived: false,
49
- transformation: {
50
- angle: 90
51
- },
52
- format: 'gif'
53
- },
54
- {
55
- create_derived: false,
56
- transformation: {angle: 45, crop: 'scale'},
57
- format: 'png'
58
- },
59
- {
60
- create_derived: false,
61
- }
62
- ]
63
- )
64
- expect(result["responsive_breakpoints"]).to_not be_nil
65
- expect(result["responsive_breakpoints"].length).to_not eql(0)
66
- result["responsive_breakpoints"].each do |bp|
67
- bp = Cloudinary::Cache.get(
68
- result["public_id"],
69
- {
70
- type: bp["type"],
71
- resource_type: bp["resource_type"],
72
- raw_transformation: bp["transformation"]})
73
- expect(bp).to_not be_nil
74
- end
75
- end
76
- describe Cloudinary::Uploader do
77
- let (:options) { {
78
- :tags => [TEST_TAG, TIMESTAMP_TAG],
79
- :use_cache => true,
80
- :responsive_breakpoints => [
81
- {
82
- :create_derived => false,
83
- :transformation => {
84
- :angle => 90
85
- },
86
- :format => 'gif'
87
- },
88
- {
89
- :create_derived => false,
90
- :transformation => ResponsiveTest::TRANSFORMATION,
91
- :format => ResponsiveTest::FORMAT
92
- },
93
- {
94
- :create_derived => false
95
- }
96
- ]
97
- }}
98
- before :all do
99
- end
100
-
101
- it "Should save responsive breakpoints to cache after upload" do
102
- result = Cloudinary::Uploader.upload( TEST_IMG, options)
103
- cache_value = Cloudinary::Cache.get(result["public_id"], transformation: ResponsiveTest::TRANSFORMATION, format: ResponsiveTest::FORMAT)
104
-
105
- expect(cache_value).to eql(ResponsiveTest::IMAGE_BP_VALUES)
106
- end
107
- end
108
-
109
- end
@@ -1,327 +0,0 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require 'cloudinary'
4
- require 'action_view'
5
- require 'cloudinary/helper'
6
- require 'active_support/core_ext/kernel/reporting'
7
-
8
- RSpec.describe CloudinaryHelper do
9
- before :all do
10
- # Test the helper in the context it runs in in production
11
- ActionView::Base.send :include, CloudinaryHelper
12
- end
13
-
14
- let(:helper) {
15
- ActionView::Base.new
16
- }
17
- let(:cloud_name) {DUMMY_CLOUD}
18
- let(:root_path) {"http://res.cloudinary.com/#{cloud_name}"}
19
- let(:upload_path) {"#{root_path}/image/upload"}
20
-
21
- let(:options) { {} }
22
- before :each do
23
- Cloudinary.reset_config
24
- Cloudinary.config.enhance_image_tag = true
25
- end
26
- context "#cl_image_upload_tag" do
27
- let(:options) {{:multiple => true}}
28
- before do
29
- if defined? allow
30
- allow(Cloudinary::Utils).to receive_messages :cloudinary_api_url => '', :sign_request => Hash.new
31
- allow(helper).to receive(:build_callback_url).and_return('')
32
- else
33
- Cloudinary::Utils.should_receive(:cloudinary_api_url).and_return('')
34
- Cloudinary::Utils.should_receive(:sign_request).and_return(Hash.new)
35
- helper.should_receive(:build_callback_url).and_return('')
36
- end
37
- end
38
- let(:test_tag) { TestTag.new( helper.cl_image_upload_tag('image_id', options)) }
39
-
40
- it "allow multiple upload" do
41
- expect(test_tag['data-cloudinary-field']).to eq('image_id[]')
42
- expect(test_tag['multiple']).to eq('multiple')
43
- end
44
- end
45
- context "#cl_upload_tag" do
46
- let(:options) {{:multiple => true}}
47
- before do
48
- if defined? allow
49
- allow(Cloudinary::Utils).to receive_messages :cloudinary_api_url => '', :sign_request => Hash.new
50
- allow(helper).to receive(:build_callback_url).and_return('')
51
- else
52
- Cloudinary::Utils.should_receive(:cloudinary_api_url).and_return('')
53
- Cloudinary::Utils.should_receive(:sign_request).and_return(Hash.new)
54
- helper.should_receive(:build_callback_url).and_return('')
55
- end
56
- end
57
- let(:test_tag) { TestTag.new( helper.cl_upload_tag('image_id', options)) }
58
-
59
- it "allow multiple upload" do
60
- expect(test_tag['data-cloudinary-field']).to eq('image_id[]')
61
- expect(test_tag['multiple']).to eq('multiple')
62
- end
63
- end
64
-
65
- PUBLIC_ID = 'sample.jpg'
66
- context "#cl_image_tag" do
67
- let(:test_tag) { TestTag.new( helper.cl_image_tag(PUBLIC_ID, options)) }
68
-
69
- context ":responsive_width" do
70
- let(:options) { {:responsive_width => true, :cloud_name => "test"} }
71
- it "should use data-src for responsive_width" do
72
- expect(test_tag.name).to match( 'img')
73
- expect(test_tag['class']).to eq("cld-responsive")
74
- expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/c_limit,w_auto/sample.jpg")
75
- end
76
- end
77
-
78
- context ":dpr_auto" do
79
- let(:options) { {:dpr => :auto, :cloud_name => "test"} }
80
- it "should use data-src for dpr auto" do
81
- expect(test_tag.name).to match( 'img')
82
- expect(test_tag['class']).to eq( 'cld-hidpi')
83
- expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto/sample.jpg")
84
- end
85
- end
86
-
87
- context ":client_hints" do
88
- shared_examples "client_hints" do
89
- it "should not use data-src or set responsive class" do
90
- expect(test_tag.name).to match( 'img')
91
- expect(test_tag['class']).to be_nil
92
- expect(test_tag['data-src']).to be_nil
93
- expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
94
- end
95
- it "should override :responsive" do
96
- Cloudinary.config.responsive = true
97
- expect(test_tag.name).to match( 'img')
98
- expect(test_tag['class']).to be_nil
99
- expect(test_tag['data-src']).to be_nil
100
- expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto/sample.jpg")
101
- end
102
- end
103
- context "as option" do
104
- let(:options) { {:dpr => :auto, :cloud_name => "test", :width => "auto", :client_hints => true} }
105
- include_examples "client_hints"
106
- end
107
- context "as global configuration" do
108
- before do
109
- Cloudinary.config.client_hints = true
110
- end
111
- let(:options) { {:dpr => :auto, :cloud_name => "test", :width => "auto"} }
112
- include_examples "client_hints"
113
- end
114
-
115
- context "false" do
116
- let(:options) { {:width => :auto, :cloud_name => "test", :client_hints => false} }
117
- it "should use normal responsive behaviour" do
118
- expect(test_tag.name).to match( 'img')
119
- expect(test_tag['class']).to eq( 'cld-responsive')
120
- expect(test_tag['data-src']).to eq( "http://res.cloudinary.com/test/image/upload/w_auto/sample.jpg")
121
- end
122
- end
123
- context "width" do
124
- let(:options) { {:dpr => :auto, :cloud_name => "test", :width => "auto:breakpoints", :client_hints => true}}
125
- it "supports auto width" do
126
- expect(test_tag['src']).to eq( "http://res.cloudinary.com/test/image/upload/dpr_auto,w_auto:breakpoints/sample.jpg")
127
- end
128
- end
129
- end
130
- end
131
- describe "Responsive methods" do
132
- let (:options) {{
133
- :cloud_name => DUMMY_CLOUD,
134
- :width => ResponsiveTest::BREAKPOINTS.last,
135
- :height => ResponsiveTest::BREAKPOINTS.last,
136
- :crop => :fill}}
137
-
138
- describe "generate_breakpoints" do
139
- it "should accept breakpoint" do
140
- expect(helper.generate_breakpoints(:breakpoints => [1,2,3])).to eq([1,2,3])
141
- end
142
- it "should accept min_width, max_width" do
143
- expect(helper.generate_breakpoints(:min_width => 100, :max_width => 600, :max_images => 7)).to eq([ 100, 184, 268, 352, 436, 520, 600 ])
144
- end
145
- end
146
- describe "generate_scaled_url" do
147
- it "should generate url" do
148
- url = helper.generate_scaled_url('sample.jpg', 101, {:width => 200, :crop => "scale"}, options)
149
- expect(url).to eq("#{upload_path}/c_scale,w_200/c_scale,w_101/sample.jpg")
150
- end
151
- it "should generate url without a transformation" do
152
- url = helper.generate_scaled_url('sample.jpg', 101, {}, options)
153
- expect(url).to eq("#{upload_path}/c_scale,w_101/sample.jpg")
154
- end
155
- end
156
- describe "generate_srcset" do
157
- it "should generate a url for each breakpoint" do
158
- srcset = helper.generate_srcset_attribute('sample', [1,2,3], {}, options)
159
- expect(srcset.split(', ').length).to be(3)
160
- end
161
- end
162
- end
163
-
164
- context "#cl_picture_tag" do
165
- let (:options) {{
166
- :cloud_name => DUMMY_CLOUD,
167
- :width => ResponsiveTest::BREAKPOINTS.last,
168
- :height => ResponsiveTest::BREAKPOINTS.last,
169
- :crop => :fill}}
170
- let (:fill_trans_str) {Cloudinary::Utils.generate_transformation_string(options)}
171
- let (:sources) {
172
- [
173
- {
174
- :min_width => ResponsiveTest::BREAKPOINTS.third,
175
- :transformation => {:effect => "sepia", :angle => 17, :width => ResponsiveTest::BREAKPOINTS.first, :crop => :scale}
176
- },
177
- {
178
- :min_width => ResponsiveTest::BREAKPOINTS.second,
179
- :transformation => {:effect => "colorize", :angle => 18, :width => ResponsiveTest::BREAKPOINTS.second, :crop => :scale}
180
- },
181
- {
182
- :min_width => ResponsiveTest::BREAKPOINTS.first,
183
- :transformation => {:effect => "blur", :angle => 19, :width => ResponsiveTest::BREAKPOINTS.first, :crop => :scale}
184
- }
185
- ]
186
- }
187
- let(:test_tag) {TestTag.new(helper.cl_picture_tag(PUBLIC_ID, options, sources))}
188
- def source_url(t)
189
- t = Cloudinary::Utils.generate_transformation_string(t)
190
- upload_path + '/' + fill_trans_str + '/' + t + "/sample.jpg"
191
- end
192
- it "should create a picture tag" do
193
- expect(test_tag[:attributes]).to be_nil
194
- source_tags = test_tag.element.xpath('//source')
195
- expect(source_tags.length).to be(3)
196
- expect(test_tag.element.xpath('//img').length).to be(1)
197
- sources.each_with_index do |source,i|
198
- expect(source_tags[i].attribute('srcset').value).to eq(source_url(source[:transformation]))
199
- end
200
-
201
- [
202
- "(min-width: #{ResponsiveTest::BREAKPOINTS.third}px)",
203
- "(min-width: #{ResponsiveTest::BREAKPOINTS.second}px)",
204
- "(min-width: #{ResponsiveTest::BREAKPOINTS.first}px)",
205
- ].each_with_index do |expected, i|
206
- expect(source_tags[i].attribute('media').value).to eq(expected)
207
- end
208
-
209
- end
210
-
211
- end
212
-
213
- context "#cl_source_tag" do
214
- min_width = 100
215
- max_width = 399
216
- breakpoint_list = [min_width, 200, 300, max_width]
217
- common_srcset = {breakpoints: breakpoint_list}
218
- fill_transformation = {width: max_width, height: max_width, crop: "fill"}
219
- fill_transformation_str = "c_fill,h_#{max_width},w_#{max_width}"
220
- let (:options) {{
221
- :cloud_name => DUMMY_CLOUD,
222
- }}
223
- let(:test_tag) {TestTag.new(helper.cl_source_tag(PUBLIC_ID, options))}
224
- before(:each) do
225
- Cloudinary.config(cloud_name: DUMMY_CLOUD, api_secret: "1234")
226
- end
227
-
228
- it "should generate a source tag" do
229
- expect(test_tag.name).to eql("source")
230
- expect(test_tag['srcset']).to eql("#{upload_path}/sample.jpg")
231
- end
232
-
233
- it "should generate source tag with media query" do
234
- media = {min_width: min_width, max_width: max_width}
235
- tag = helper.cl_source_tag("sample.jpg", media: media)
236
- expected_media = "(min-width: #{min_width}px) and (max-width: #{max_width}px)".html_safe
237
- expected_tag = "<source srcset=\"#{upload_path}/sample.jpg\" media=\"#{expected_media}\">"
238
- expect(tag).to eql(expected_tag)
239
- end
240
-
241
- it "should generate source tag with responsive srcset" do
242
- tag = helper.cl_source_tag(PUBLIC_ID, srcset: {breakpoints: breakpoint_list})
243
- expect(tag).to eql(
244
- "<source srcset=\"" +
245
- "http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_100/sample.jpg 100w, " +
246
- "http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_200/sample.jpg 200w, " +
247
- "http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_300/sample.jpg 300w, " +
248
- "http://res.cloudinary.com/#{DUMMY_CLOUD}/image/upload/c_scale,w_399/sample.jpg 399w" +
249
- "\">")
250
- end
251
-
252
- end
253
-
254
- context "#cl_client_hints_meta_tag" do
255
- it "should create a meta tag" do
256
- tag = TestTag.new( helper.cl_client_hints_meta_tag)
257
- expect(tag.name).to match('meta')
258
- expect(tag['content']).to eq('DPR, Viewport-Width, Width')
259
- expect(tag['http-equiv']).to eq('Accept-CH')
260
- end
261
- end
262
-
263
- context "auth_token" do
264
- it "should add token to an image tag url" do
265
- tag = helper.cl_image_tag "sample.jpg",
266
- :cloud_name => DUMMY_CLOUD,
267
- :sign_url => true,
268
- :type => "authenticated",
269
- :version => "1486020273",
270
- :auth_token => {key: KEY, start_time: 11111111, duration: 300}
271
- expect(tag).to match /<img.*src="http:\/\/res.cloudinary.com\/#{DUMMY_CLOUD}\/image\/authenticated\/v1486020273\/sample.jpg\?__cld_token__=st=11111111~exp=11111411~hmac=9bd6f41e2a5893da8343dc8eb648de8bf73771993a6d1457d49851250caf3b80.*>/
272
-
273
- end
274
-
275
- end
276
- describe "image_path" do
277
-
278
- before :all do
279
- class Cloudinary::Static
280
- class << self
281
- def reset_metadata
282
- @metadata = nil
283
- @static_file_config = nil
284
- @public_prefixes = nil
285
- end
286
- end
287
- end
288
- end
289
-
290
- before :each do
291
- @static_support = Cloudinary.config.static_image_support
292
- @static_file = Cloudinary::Static::METADATA_FILE
293
- Cloudinary.reset_config
294
- Cloudinary.config.enhance_image_tag = true
295
- Cloudinary::Static.reset_metadata
296
- end
297
-
298
- after :each do
299
- Cloudinary.reset_config
300
- Cloudinary.config.static_image_support = @static_support
301
- Kernel::silence_warnings {Cloudinary::Static::METADATA_FILE = @static_file}
302
- Cloudinary::Static.reset_metadata
303
- end
304
-
305
- context 'type=="asset"' do
306
- it "should not transform images staring with /" do
307
- expect(helper.image_path('/bar')).to eq('/bar')
308
- end
309
- it "should not transform images staring with /images unless asset is found and static_support is true" do
310
- skip if RUBY_VERSION >= '2.2.2'
311
-
312
- Cloudinary.config.static_image_support = false
313
- expect(helper.image_path('/images/foo.jpg')).to eq('/images/foo.jpg')
314
- expect(helper.image_path('some-folder/foo.gif')).to eq("/images/some-folder/foo.gif")
315
- Kernel::silence_warnings { Cloudinary::Static::METADATA_FILE = "spec/sample_asset_file.tsv"}
316
- Cloudinary::Static.reset_metadata
317
- expect(helper.image_path('/images/foo.jpg'))
318
- .to eq("/images/foo.jpg")
319
- expect(helper.image_path('some-folder/foo.gif')).to eq("/images/some-folder/foo.gif")
320
- Cloudinary.config.static_image_support = true
321
- expect(helper.image_path('/images/foo.jpg')).to eq("http://res.cloudinary.com/#{Cloudinary.config.cloud_name}/image/asset/images-foo.jpg")
322
- expect(helper.image_path('foo.jpg')).to eq("http://res.cloudinary.com/#{Cloudinary.config.cloud_name}/image/asset/images-foo.jpg")
323
- expect(helper.image_path('some-folder/foo.gif')).to eq('/images/some-folder/foo.gif')
324
- end
325
- end
326
- end
327
- end