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
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
-
4
- describe Cloudinary do
5
- before :each do
6
- @user_platform = Cloudinary.user_platform
7
- end
8
- after :each do
9
- Cloudinary.user_platform = @user_platform
10
- end
11
-
12
- CLOUDINARY_USER_AGENT_REGEXP = %r"^CloudinaryRuby\/[\d.]+ \(Ruby [\d\.]+-p\d+\)$"
13
- CLOUDINARY_USER_PLATFORM_REGEXP = %r"^Rails\/[\d.]+ CloudinaryRuby\/[\d.]+ \(Ruby [\d\.]+-p\d+\)$"
14
-
15
- it "should return the USER_AGENT without user_platform if there's no Rails or set to empty" do
16
- Cloudinary.user_platform = ""
17
- expect(Cloudinary.USER_AGENT).to match(CLOUDINARY_USER_AGENT_REGEXP)
18
- end
19
-
20
- it 'should add a user platform to USER_AGENT' do
21
- Cloudinary.user_platform = "Rails/5.6.7"
22
- expect(Cloudinary.USER_AGENT).to match(CLOUDINARY_USER_PLATFORM_REGEXP)
23
- end
24
-
25
- describe 'config' do
26
- before do
27
- @url_backup = ENV["CLOUDINARY_URL"]
28
- end
29
- after do
30
- ENV["CLOUDINARY_URL"] = @url_backup
31
- Cloudinary::config_from_url @url_backup
32
- end
33
- it "should allow nested values in CLOUDINARY_URL" do
34
- ENV["CLOUDINARY_URL"] = "cloudinary://key:secret@test123?foo[bar]=value"
35
- Cloudinary::config_from_url ENV["CLOUDINARY_URL"]
36
- expect(Cloudinary::config.foo.bar).to eq 'value'
37
- end
38
-
39
- it "should set accept a CLOUDINARY_URL with the correct scheme (cloudinary)" do
40
- valid_cloudinary_url = "cloudinary://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test"
41
- expect{Cloudinary::config_from_url valid_cloudinary_url}.not_to raise_error
42
- end
43
- it "should raise an exception if the CLOUDINARY_URL doesn't start with 'cloudinary://'" do
44
- invalid_cloudinary_urls = [
45
- "CLOUDINARY_URL=cloudinary://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test",
46
- "https://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test",
47
- "://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test",
48
- " "
49
- ]
50
- invalid_cloudinary_urls.each do |cloudinary_url|
51
- expect{Cloudinary::config_from_url cloudinary_url}
52
- .to raise_error(/bad URI|Invalid CLOUDINARY_URL/)
53
- end
54
- end
55
- end
56
- end
@@ -1 +0,0 @@
1
- coffeescript = true
@@ -1 +0,0 @@
1
- { alert("I am javascript!");}
@@ -1,3 +0,0 @@
1
- p#css {
2
- color: red;
3
- }
data/spec/docx.docx DELETED
Binary file
data/spec/favicon.ico DELETED
Binary file
data/spec/image_spec.rb DELETED
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
- require 'action_view'
4
- require 'cloudinary/helper'
5
-
6
- COMMON_TRANS = {
7
- effect: 'sepia',
8
- cloud_name: DUMMY_CLOUD,
9
- client_hints: false
10
- }
11
- COMMON_TRANSFORMATION_STR = 'e_sepia'
12
-
13
- def expected_srcset(public_id, path, common_trans, breakpoints)
14
- breakpoints.map {|width| "#{path}/#{common_trans}/c_scale,w_#{width}/#{public_id} #{width}w"}.join(', ')
15
- end
16
-
17
- describe 'Responsive breakpoints' do
18
-
19
-
20
- before :all do
21
- # Test the helper in the context it runs in in production
22
- ActionView::Base.send :include, CloudinaryHelper
23
-
24
- end
25
-
26
- before :each do
27
- Cloudinary.reset_config
28
- end
29
-
30
- let(:cloud_name) {COMMON_TRANS[:cloud_name]}
31
- let(:root_path) {"http://res.cloudinary.com/#{cloud_name}"}
32
- let(:upload_path) {"#{root_path}/image/upload"}
33
-
34
- let(:options) {COMMON_TRANS}
35
- # let(:helper) {helper_class.new}
36
- let(:helper) {
37
- ActionView::Base.new
38
- }
39
- let(:test_tag) {TestTag.new(helper.cl_image_tag('sample.jpg', options))}
40
- describe 'srcset' do
41
- it 'Should create srcset attribute with provided breakpoints' do
42
- options[:srcset] = {:breakpoints => ResponsiveTest::BREAKPOINTS}
43
- srcset = test_tag['srcset'].split(", ")
44
- expect(srcset.length).to eq(4)
45
- expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, ResponsiveTest::BREAKPOINTS)
46
- expect(test_tag['srcset']).to match(expected_tag)
47
- end
48
- it "Support srcset attribute defined by min width max width and max images" do
49
- options[:srcset] = {:min_width => ResponsiveTest::BREAKPOINTS.first,
50
- :max_width => ResponsiveTest::BREAKPOINTS.last,
51
- :max_images => ResponsiveTest::BREAKPOINTS.length}
52
-
53
- expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, ResponsiveTest::BREAKPOINTS)
54
- expect(test_tag['srcset']).to match(expected_tag)
55
- end
56
- it "should generate a single srcset image" do
57
- options[:srcset] = {:min_width => ResponsiveTest::BREAKPOINTS.first,
58
- :max_width => ResponsiveTest::BREAKPOINTS.last,
59
- :max_images => 1}
60
-
61
- expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, [ResponsiveTest::BREAKPOINTS.last])
62
- expect(test_tag['srcset']).to match(expected_tag)
63
- end
64
- it "Should support custom transformation for srcset items" do
65
- options[:srcset] = {
66
- :breakpoints => ResponsiveTest::BREAKPOINTS,
67
- :transformation => {:crop => 'crop', :width => 10, :height => 20}
68
- }
69
-
70
- expected_tag = expected_srcset('sample.jpg', upload_path, 'c_crop,h_20,w_10', ResponsiveTest::BREAKPOINTS)
71
- expect(test_tag['srcset']).to match(expected_tag)
72
- end
73
- it "Should populate sizes attribute" do
74
- options[:srcset] = {
75
- :breakpoints => ResponsiveTest::BREAKPOINTS,
76
- :sizes => true
77
- }
78
- expected_sizes_attr = '(max-width: 100px) 100px, (max-width: 200px) 200px, ' +
79
- '(max-width: 300px) 300px, (max-width: 399px) 399px'
80
- expect(test_tag['sizes']).to match(expected_sizes_attr)
81
- end
82
- it "Should support srcset string value" do
83
- raw_src_set = "some srcset data as is"
84
- options[:srcset] = raw_src_set
85
-
86
- expect(test_tag['srcset']).to match(raw_src_set)
87
- end
88
- it "Should remove width and height attributes in case srcset is specified, but passed to transformation" do
89
- options.merge!({
90
- :srcset => {
91
- :breakpoints => ResponsiveTest::BREAKPOINTS,
92
- },
93
- :width => 500,
94
- :height => 500,
95
- :crop => 'scale'
96
-
97
- })
98
-
99
- expected_tag = expected_srcset('sample.jpg', upload_path, 'c_scale,e_sepia,h_500,w_500', ResponsiveTest::BREAKPOINTS)
100
- expect(test_tag['srcset']).to match(expected_tag)
101
- expect(test_tag['width']).to be_nil
102
- end
103
-
104
- end
105
-
106
-
107
- end
data/spec/logo.png DELETED
Binary file
data/spec/movie.mp4 DELETED
Binary file
data/spec/rake_spec.rb DELETED
@@ -1,160 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
-
4
- require 'tmpdir'
5
- require 'pathname'
6
-
7
- describe 'cloudinary:sync_static' do
8
- include_context 'rake' # context needs to have the exact rake task as name
9
- include Helpers::TempFileHelpers
10
-
11
- before(:all) do
12
- copy_root_to_temp('spec/data/sync_static/')
13
-
14
- # Reuse some existing spec assets so as not to add weight to the project
15
- copy_file_to_temp('spec/logo.png', 'app/assets/images/logo1.png')
16
- copy_file_to_temp('spec/logo.png', 'app/assets/images/logo2.png')
17
- copy_file_to_temp('samples/basic/lake.jpg', 'app/assets/images/lake1.jpg')
18
- copy_file_to_temp('samples/basic/lake.jpg', 'public/images/lake2.jpg')
19
- end
20
-
21
- after(:all) do
22
- clean_up_temp_files!
23
- end
24
-
25
- before (:each) do
26
- allow(Cloudinary).to receive(:app_root).and_return(Pathname.new(temp_root))
27
- Cloudinary::Static.send(:reset_static_file_config!)
28
- end
29
-
30
- after (:each) do
31
- # destroy all uploaded assets
32
- Cloudinary::Static.send(:build_metadata).each do |_, data|
33
- Cloudinary::Uploader.destroy(data['public_id'], {:type => :asset})
34
- end
35
- # delete metadata_file_path
36
- FileUtils.rm_f(Cloudinary::Static.send(:metadata_file_path))
37
- FileUtils.rm_f(Cloudinary::Static.send(:metadata_trash_file_path))
38
- end
39
-
40
- it 'should find correct file when running in default configuration' do
41
- # with default settings, 4 images only will be uploaded
42
- subject.invoke
43
- expect(Cloudinary::Static.send(:build_metadata).size).to eq 4
44
- end
45
-
46
- it 'should respect deprecated static_image_dirs config setting' do
47
- allow(Cloudinary.config).to receive(:static_image_dirs).and_return(['public/images'])
48
- subject.invoke
49
- expect(Cloudinary::Static.send(:build_metadata).size).to eq 1
50
- end
51
-
52
- it 'should allow to specify only dirs in images group, taking the file_mask from default' do
53
- allow(Cloudinary.config).to receive(:static_files).and_return({
54
- 'images' => {
55
- 'dirs' => ['public/images']
56
- }
57
- })
58
- subject.invoke
59
- expect(Cloudinary::Static.send(:build_metadata).size).to eq 1
60
- end
61
-
62
- it 'should allow to specify only file_mask in images group, taking the dirs from default' do
63
- allow(Cloudinary.config).to receive(:static_files).and_return({
64
- 'images' => {
65
- 'file_mask' => 'png'
66
- }
67
- })
68
- subject.invoke
69
- expect(Cloudinary::Static.send(:build_metadata).size).to eq 2
70
- end
71
-
72
- it 'should allow to specify regex expressions in file_mask' do
73
- allow(Cloudinary.config).to receive(:static_files).and_return({
74
- 'images' => {
75
- 'file_mask' => 'p.?g|jp.?'
76
- },
77
- 'javascripts' => {
78
- 'dirs' => ['app/assets/javascripts'],
79
- 'file_mask' => 'js'
80
- },
81
- 'stylesheets' => {
82
- 'dirs' => ['app/assets/stylesheets'],
83
- 'file_mask' => 'css'
84
- }
85
- })
86
- subject.invoke
87
- expect(Cloudinary::Static.send(:build_metadata).size).to eq 6
88
- end
89
-
90
- context 'Cloudinary::Utils.cloudinary_url' do
91
- def all_asset_forms_of(public_id)
92
- [ "/#{public_id}", public_id.split('/').last]
93
- end
94
-
95
- RSpec::Matchers.define :be_asset_mapped_by_cloudinary_url_to do |expected|
96
- match do |actual|
97
- actual = [actual] unless actual.respond_to? :all?
98
- actual.all? do |public_path|
99
- @public_path = public_path
100
- @actual = Cloudinary::Utils.cloudinary_url(public_path, :cloud_name => 'test', :type => 'asset')
101
- @actual == expected
102
- end
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
-
117
- end
118
-
119
- before(:each) do
120
- allow(Cloudinary.config).to receive(:static_files).and_return({
121
- 'images' => {
122
- 'dirs' => ['app/assets/images'],
123
- 'file_mask' => 'p.?g|jp.?'
124
- },
125
- 'javascripts' => {
126
- 'dirs' => ['app/assets/javascripts'],
127
- 'file_mask' => 'js'
128
- },
129
- 'stylesheets' => {
130
- 'dirs' => ['app/assets/stylesheets'],
131
- 'file_mask' => 'css'
132
- }
133
- })
134
-
135
- end
136
-
137
- it 'should return Cloudinary asset urls for assets when Cloudinary.config.static_file_support is true' do
138
- allow(Cloudinary.config).to receive(:static_file_support).and_return(true)
139
- subject.invoke
140
-
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')
147
-
148
- # without :type => 'asset'
149
- expect(Cloudinary::Utils.cloudinary_url('logo1.png')).not_to include('7dc60722d4653261648038b579fdb89e')
150
- end
151
-
152
- it 'should return Cloudinary asset urls for assets when Cloudinary.config.static_image_support is true (backwards compatibility)' do
153
- allow(Cloudinary.config).to receive(:static_image_support).and_return(true)
154
- subject.invoke
155
-
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')
157
- end
158
- end
159
-
160
- end
@@ -1,4 +0,0 @@
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
data/spec/search_spec.rb DELETED
@@ -1,109 +0,0 @@
1
- require 'spec_helper'
2
- require 'cloudinary'
3
-
4
- describe Cloudinary::Search do
5
- context 'unit' do
6
- it 'should create empty json' do
7
- query_hash = Cloudinary::Search.to_h
8
- expect(query_hash).to eq({})
9
- end
10
-
11
- it 'should always return same object in fluent interface' do
12
- instance = Cloudinary::Search.new
13
- %w(expression sort_by max_results next_cursor aggregate with_field).each do |method|
14
- same_instance = instance.send(method, 'emptyarg')
15
- expect(instance).to eq(same_instance)
16
- end
17
- end
18
-
19
- it 'should add expression to query' do
20
- query = Cloudinary::Search.expression('format:jpg').to_h
21
- expect(query).to eq(expression: 'format:jpg')
22
- end
23
-
24
- it 'should add sort_by to query' do
25
- query = Cloudinary::Search.sort_by('created_at', 'asc').sort_by('updated_at', 'desc').to_h
26
- expect(query).to eq(sort_by: [{ 'created_at' => 'asc' }, { 'updated_at' => 'desc' }])
27
- end
28
-
29
- it 'should add max_results to query' do
30
- query = Cloudinary::Search.max_results(10).to_h
31
- expect(query).to eq(max_results: 10)
32
- end
33
-
34
- it 'should add next_cursor to query' do
35
- query = Cloudinary::Search.next_cursor('ASDFIUHASF9832HAFSOF').to_h
36
- expect(query).to eq(next_cursor: 'ASDFIUHASF9832HAFSOF')
37
- end
38
-
39
- it 'should add aggregations arguments as array to query' do
40
- query = Cloudinary::Search.aggregate('format').aggregate('size_category').to_h
41
- expect(query).to eq(aggregate: %w(format size_category))
42
- end
43
-
44
- it 'should add with_field to query' do
45
- query = Cloudinary::Search.with_field('context').with_field('tags').to_h
46
- expect(query).to eq(with_field: %w(context tags))
47
- end
48
- end
49
-
50
- context 'integration' do
51
- SEARCH_TAG = TIMESTAMP_TAG + "_search"
52
- include_context 'cleanup', SEARCH_TAG
53
- prefix = "api_test_#{SUFFIX}"
54
- test_id_1 = "#{prefix}_1"
55
- test_id_2 = "#{prefix}_2"
56
- test_id_3 = "#{prefix}_3"
57
- before(:all) do
58
- Cloudinary::Uploader.upload(TEST_IMG, public_id: test_id_1, tags: [TEST_TAG, TIMESTAMP_TAG, SEARCH_TAG], context: 'stage=in_review')
59
- Cloudinary::Uploader.upload(TEST_IMG, public_id: test_id_2, tags: [TEST_TAG, TIMESTAMP_TAG, SEARCH_TAG], context: 'stage=new')
60
- Cloudinary::Uploader.upload(TEST_IMG, public_id: test_id_3, tags: [TEST_TAG, TIMESTAMP_TAG, SEARCH_TAG], context: 'stage=validated')
61
- sleep(3)
62
- end
63
-
64
- it "should return all images tagged with #{SEARCH_TAG}" do
65
- results = Cloudinary::Search.expression("tags:#{SEARCH_TAG}").execute
66
- expect(results['resources'].count).to eq 3
67
- end
68
-
69
- it "should return resource #{test_id_1}" do
70
- results = Cloudinary::Search.expression("public_id:#{test_id_1}").execute
71
- expect(results['resources'].count).to eq 1
72
- end
73
-
74
- it 'should paginate resources limited by tag and ordered by ascending public_id' do
75
- results = Cloudinary::Search.max_results(1).expression("tags:#{SEARCH_TAG}").sort_by('public_id', 'asc').execute
76
- expect(results['resources'].count).to eq 1
77
- expect(results['resources'][0]['public_id']).to eq test_id_1
78
- expect(results['total_count']).to eq 3
79
-
80
- results = Cloudinary::Search.max_results(1).expression("tags:#{SEARCH_TAG}").sort_by('public_id', 'asc').next_cursor(results['next_cursor']).execute
81
- expect(results['resources'].count).to eq 1
82
- expect(results['resources'][0]['public_id']).to eq test_id_2
83
- expect(results['total_count']).to eq 3
84
-
85
- results = Cloudinary::Search.max_results(1).expression("tags:#{SEARCH_TAG}").sort_by('public_id', 'asc').next_cursor(results['next_cursor']).execute
86
- expect(results['resources'].count).to eq 1
87
- expect(results['resources'][0]['public_id']).to eq test_id_3
88
- expect(results['total_count']).to eq 3
89
- expect(results['next_cursor']).to be_nil
90
- end
91
-
92
- it 'should include context' do
93
- results = Cloudinary::Search.expression("tags:#{SEARCH_TAG}").with_field('context').execute
94
- expect(results['resources'].count).to eq 3
95
- results['resources'].each do |res|
96
- expect(res['context'].keys).to eq ['stage']
97
- end
98
- end
99
- it 'should include context, tags and image_metadata' do
100
- results = Cloudinary::Search.expression("tags:#{SEARCH_TAG}").with_field('context').with_field('tags').with_field('image_metadata').execute
101
- expect(results['resources'].count).to eq 3
102
- results['resources'].each do |res|
103
- expect(res['context'].keys).to eq ['stage']
104
- expect(res.key?('image_metadata')).to eq true
105
- expect(res['tags'].count).to eq 3
106
- end
107
- end
108
- end
109
- end