uploadcare-rails 2.1.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uploadcare/rails/api/rest/addons_api.rb +54 -0
  3. data/lib/uploadcare/rails/api/rest/base.rb +3 -2
  4. data/lib/uploadcare/rails/api/rest/conversion_api.rb +8 -8
  5. data/lib/uploadcare/rails/api/rest/file_api.rb +20 -13
  6. data/lib/uploadcare/rails/api/rest/file_metadata_api.rb +42 -0
  7. data/lib/uploadcare/rails/api/rest/group_api.rb +12 -6
  8. data/lib/uploadcare/rails/api/rest/project_api.rb +1 -1
  9. data/lib/uploadcare/rails/api/rest/webhook_api.rb +6 -6
  10. data/lib/uploadcare/rails/api/upload/base.rb +2 -0
  11. data/lib/uploadcare/rails/api/upload/upload_api.rb +4 -4
  12. data/lib/uploadcare/rails/configuration.rb +3 -1
  13. data/lib/uploadcare/rails/objects/group.rb +1 -3
  14. data/lib/uploadcare/rails/transformations/image_transformations.rb +1 -1
  15. data/lib/uploadcare/rails/version.rb +1 -1
  16. data/lib/uploadcare-rails.rb +2 -0
  17. metadata +31 -126
  18. data/spec/fixtures/kitten.jpeg +0 -0
  19. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +0 -62
  20. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +0 -62
  21. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +0 -62
  22. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +0 -62
  23. data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +0 -59
  24. data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +0 -59
  25. data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +0 -60
  26. data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +0 -58
  27. data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +0 -58
  28. data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +0 -58
  29. data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +0 -61
  30. data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +0 -57
  31. data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +0 -58
  32. data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +0 -57
  33. data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +0 -57
  34. data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +0 -52
  35. data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +0 -57
  36. data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +0 -57
  37. data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +0 -59
  38. data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +0 -55
  39. data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +0 -105
  40. data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +0 -111
  41. data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +0 -59
  42. data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +0 -57
  43. data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +0 -59
  44. data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +0 -59
  45. data/spec/generators/uploadcare_config_generator_spec.rb +0 -31
  46. data/spec/spec_helper.rb +0 -26
  47. data/spec/support/generators.rb +0 -41
  48. data/spec/support/vcr.rb +0 -14
  49. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +0 -40
  50. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +0 -46
  51. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +0 -33
  52. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +0 -32
  53. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +0 -110
  54. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +0 -85
  55. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +0 -61
  56. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +0 -33
  57. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +0 -67
  58. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +0 -82
  59. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +0 -15
  60. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +0 -15
  61. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +0 -15
  62. data/spec/uploadcare/rails/objects/file_spec.rb +0 -77
  63. data/spec/uploadcare/rails/objects/group_spec.rb +0 -87
  64. data/spec/uploadcare/rails/services/id_extractor_spec.rb +0 -26
  65. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +0 -120
  66. data/spec/uploadcare/rails_spec.rb +0 -7
@@ -1,59 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.uploadcare.com/webhooks/
6
- body:
7
- encoding: UTF-8
8
- string: ''
9
- headers:
10
- Content-Type:
11
- - application/json
12
- Accept:
13
- - application/vnd.uploadcare-v0.5+json
14
- User-Agent:
15
- - UploadcareRuby/3.0.5/demopublickey (Ruby/2.7.0)
16
- Date:
17
- - Thu, 22 Jul 2021 10:18:33 GMT
18
- Authorization:
19
- - Uploadcare demopublickey:4b73a3f9542c892973c0a85b596da8f305409e60
20
- Connection:
21
- - close
22
- Host:
23
- - api.uploadcare.com
24
- response:
25
- status:
26
- code: 200
27
- message: OK
28
- headers:
29
- Date:
30
- - Thu, 22 Jul 2021 10:18:34 GMT
31
- Content-Type:
32
- - application/vnd.uploadcare-v0.5+json
33
- Content-Length:
34
- - '460'
35
- Connection:
36
- - close
37
- Server:
38
- - nginx
39
- Warning:
40
- - '199 Miscellaneous warning: You are using the demo project'
41
- Access-Control-Allow-Origin:
42
- - https://uploadcare.com
43
- Vary:
44
- - Accept
45
- Allow:
46
- - GET, HEAD, OPTIONS, POST
47
- X-Xss-Protection:
48
- - 1; mode=block
49
- X-Content-Type-Options:
50
- - nosniff
51
- X-Frame-Options:
52
- - SAMEORIGIN
53
- X-Robots-Tag:
54
- - noindex, nofollow, nosnippet, noarchive
55
- body:
56
- encoding: ASCII-8BIT
57
- string: '[{"id":811133,"created":"2021-07-22T10:13:57.596063Z","updated":"2021-07-22T10:13:57.596135Z","event":"file.uploaded","target_url":"https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/170.png","project":159,"is_active":true},{"id":811134,"created":"2021-07-22T10:15:44.309733Z","updated":"2021-07-22T10:15:44.309757Z","event":"file.uploaded","target_url":"https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/10.png","project":159,"is_active":true}]'
58
- recorded_at: Thu, 22 Jul 2021 10:18:34 GMT
59
- recorded_with: VCR 6.0.0
@@ -1,59 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://api.uploadcare.com/webhooks/811134/
6
- body:
7
- encoding: UTF-8
8
- string: '{"target_url":"https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png","is_active":false}'
9
- headers:
10
- Content-Type:
11
- - application/json
12
- Accept:
13
- - application/vnd.uploadcare-v0.5+json
14
- User-Agent:
15
- - UploadcareRuby/3.0.5/demopublickey (Ruby/2.7.0)
16
- Date:
17
- - Thu, 22 Jul 2021 10:30:17 GMT
18
- Authorization:
19
- - Uploadcare demopublickey:3767a47a86fdf55c296b51b8cf94f18602fc2987
20
- Connection:
21
- - close
22
- Host:
23
- - api.uploadcare.com
24
- response:
25
- status:
26
- code: 200
27
- message: OK
28
- headers:
29
- Date:
30
- - Thu, 22 Jul 2021 10:30:18 GMT
31
- Content-Type:
32
- - application/vnd.uploadcare-v0.5+json
33
- Content-Length:
34
- - '229'
35
- Connection:
36
- - close
37
- Server:
38
- - nginx
39
- Warning:
40
- - '199 Miscellaneous warning: You are using the demo project'
41
- Access-Control-Allow-Origin:
42
- - https://uploadcare.com
43
- Vary:
44
- - Accept
45
- Allow:
46
- - OPTIONS, POST
47
- X-Xss-Protection:
48
- - 1; mode=block
49
- X-Content-Type-Options:
50
- - nosniff
51
- X-Frame-Options:
52
- - SAMEORIGIN
53
- X-Robots-Tag:
54
- - noindex, nofollow, nosnippet, noarchive
55
- body:
56
- encoding: ASCII-8BIT
57
- string: '{"id":811134,"created":"2021-07-22T10:15:44.309733Z","updated":"2021-07-22T10:30:18.148061Z","event":"file.uploaded","target_url":"https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png","project":159,"is_active":false}'
58
- recorded_at: Thu, 22 Jul 2021 10:30:18 GMT
59
- recorded_with: VCR 6.0.0
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/generators'
4
- require 'generators/uploadcare_config_generator'
5
-
6
- RSpec.describe UploadcareConfigGenerator, type: :generator do
7
- destination File.expand_path('../tmp', __dir__)
8
-
9
- let(:config_file_path) { 'spec/tmp/config/initializers/uploadcare.rb' }
10
-
11
- before do
12
- prepare_destination
13
- end
14
-
15
- it 'checks that no config exists before the generator run' do
16
- expect(File.exist?(config_file_path)).to be(false)
17
- end
18
-
19
- context 'when run the generator' do
20
- before { run_generator }
21
-
22
- it 'generates the config file' do
23
- run_generator
24
- expect(File.exist?(config_file_path)).to be(true)
25
- end
26
-
27
- it 'checks that the config file contains the :configure method call' do
28
- expect(File.open(config_file_path).read).to match(/Uploadcare::Rails.configure do |config|/)
29
- end
30
- end
31
- end
data/spec/spec_helper.rb DELETED
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rspec'
4
- require 'bundler/setup'
5
- require 'uploadcare/rails'
6
- require 'api_struct'
7
- require 'uploadcare'
8
- require 'action_view'
9
-
10
- Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].sort.each { |f| require f }
11
-
12
- RSpec.configure do |config|
13
- # Enable flags like --only-failures and --next-failure
14
- config.example_status_persistence_file_path = '.rspec_status'
15
-
16
- # Disable RSpec exposing methods globally on `Module` and `main`
17
- config.disable_monkey_patching!
18
-
19
- config.expose_dsl_globally = true
20
-
21
- config.expect_with :rspec do |c|
22
- c.syntax = :expect
23
- end
24
-
25
- config.include ActionView::Helpers, type: :helper
26
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators/test_case'
4
-
5
- module Uploadcare
6
- module Rails
7
- module Generators
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
- cattr_accessor :test_case, :test_case_instance
12
-
13
- self.test_case = Class.new(::Rails::Generators::TestCase) do
14
- def fake_test_case; end
15
-
16
- def add_assertion; end
17
- end
18
- self.test_case_instance = test_case.new(:fake_test_case)
19
- test_case.generator_class = described_class
20
- end
21
-
22
- def prepare_destination
23
- test_case_instance.send :prepare_destination
24
- end
25
-
26
- def run_generator
27
- test_case_instance.run_generator
28
- end
29
-
30
- module ClassMethods
31
- def destination(path)
32
- test_case.destination_root = path
33
- end
34
- end
35
- end
36
- end
37
- end
38
-
39
- RSpec.configure do |c|
40
- c.include Uploadcare::Rails::Generators, type: :generator
41
- end
data/spec/support/vcr.rb DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'vcr'
5
-
6
- VCR.configure do |config|
7
- config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
8
- config.hook_into :webmock
9
- config.before_record do |i|
10
- if i.request.body && i.request.body.size > 1024 * 1024
11
- i.request.body = "Big string (#{i.request.body.size / (1024 * 1024)}) MB"
12
- end
13
- end
14
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/action_view/uploadcare_uploader_tags'
5
-
6
- describe Uploadcare::Rails::ActionView::UploadcareUploaderTags, type: :helper do
7
- it 'includes a hidden field' do
8
- tag = uploadcare_uploader_field(:post, :title)
9
-
10
- [
11
- '<input',
12
- 'role="uploadcare-uploader"',
13
- 'type="hidden"',
14
- 'name="post[title]"',
15
- 'id="post_title"',
16
- '/>'
17
- ].each do |fragment|
18
- expect(tag).to include(fragment)
19
- end
20
- end
21
-
22
- it 'includes a hidden field tag' do
23
- tag = uploadcare_uploader_field_tag(:title)
24
-
25
- [
26
- '<input',
27
- 'role="uploadcare-uploader"',
28
- 'type="hidden"',
29
- 'name="title"',
30
- 'id="title"',
31
- '/>'
32
- ].each do |fragment|
33
- expect(tag).to include(fragment)
34
- end
35
- end
36
- end
37
-
38
- RSpec.configure do |c|
39
- c.include Uploadcare::Rails::ActionView::UploadcareUploaderTags, type: :helper
40
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/action_view/uploadcare_include_tags'
5
-
6
- describe Uploadcare::Rails::ActionView::UploadcareWidgetTags, type: :helper do
7
- let(:global_variables) { 'UPLOADCARE_PUBLIC_KEY = demopublickey;' }
8
-
9
- before do
10
- allow(Uploadcare::Rails).to receive_message_chain(:configuration, :uploader_parameters)
11
- .and_return(global_variables)
12
- allow(Uploadcare::Rails).to receive_message_chain(:configuration, :cdn_hostname).and_return('ucarecdn.com')
13
- end
14
-
15
- context 'when including a widget' do
16
- context 'and checking available bundles' do
17
- %w[full default api ie8 lang.en].each do |bundle|
18
- %w[3 3.x 2 1].each do |version|
19
- [true, false].each do |min|
20
- it "includes a widget from cdn with params: vesrion = #{version}, bundle = #{bundle} and min = #{min}" do
21
- tag = uploadcare_include_tag(version: version, bundle: bundle, min: min)
22
-
23
- expect(tag).to match(
24
- [
25
- '<script src="https://ucarecdn.com/libs/widget/',
26
- version,
27
- "/uploadcare#{bundle == 'default' ? '' : ".#{bundle}"}#{min ? '.min' : ''}.js\"></script>"
28
- ].join
29
- )
30
- end
31
- end
32
- end
33
- end
34
-
35
- context 'and checking global variables' do
36
- it 'includes global variables' do
37
- expect(uploadcare_include_tag).to match(global_variables)
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- RSpec.configure do |c|
45
- c.include Uploadcare::Rails::ActionView::UploadcareWidgetTags, type: :helper
46
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/active_record/mount_uploadcare_file'
5
- require 'uploadcare/rails/active_record/mount_uploadcare_file_group'
6
-
7
- describe Uploadcare::Rails::ActiveRecord::MountUploadcareFile do
8
- before do
9
- allow(Uploadcare::Rails).to receive(:configuration).and_return(OpenStruct.new)
10
- stub_const 'Post', Class.new
11
- Post.class_eval do
12
- include Uploadcare::Rails::ActiveRecord::MountUploadcareFile
13
- extend ActiveModel::Callbacks
14
-
15
- define_model_callbacks :save, only: :after
16
-
17
- def initialize
18
- @picture = ''
19
- end
20
-
21
- mount_uploadcare_file :picture
22
- end
23
- end
24
-
25
- context 'when checking mount file methods availability' do
26
- it 'checks that a model instance responds to mount file methods', :aggregate_failures do
27
- post = Post.new
28
- %i[uploadcare_store_picture! uploadcare_delete_picture!].each do |method|
29
- expect(post).to respond_to(method)
30
- end
31
- end
32
- end
33
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/active_record/mount_uploadcare_file'
5
- require 'uploadcare/rails/active_record/mount_uploadcare_file_group'
6
-
7
- describe Uploadcare::Rails::ActiveRecord::MountUploadcareFileGroup do
8
- before do
9
- allow(Uploadcare::Rails).to receive(:configuration).and_return(OpenStruct.new)
10
- stub_const 'Post', Class.new
11
- Post.class_eval do
12
- include Uploadcare::Rails::ActiveRecord::MountUploadcareFileGroup
13
- extend ActiveModel::Callbacks
14
-
15
- define_model_callbacks :save, only: :after
16
-
17
- def initialize
18
- @gallery = ''
19
- end
20
-
21
- mount_uploadcare_file_group :gallery
22
- end
23
- end
24
-
25
- context 'when checking mount file group methods availability' do
26
- it 'checks that a model instance responds to mount file group methods', :aggregate_failures do
27
- post = Post.new
28
- expect(post).to respond_to(:uploadcare_store_gallery!)
29
- expect(Post).to respond_to(:has_uploadcare_file_group_for_gallery?)
30
- end
31
- end
32
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/conversion_api'
5
-
6
- # These specs include specs from uploadcare-ruby to check proper work with different rails versions.
7
- # They probably will be moved to the uploadcare-ruby gem in future releases.
8
- module Uploadcare
9
- module Rails
10
- module Api
11
- module Rest
12
- RSpec.describe ConversionApi do
13
- subject { Uploadcare::ConversionApi }
14
-
15
- context 'when checking methods' do
16
- it 'responds to expected REST methods' do
17
- %i[convert_video get_video_conversion_status convert_document get_document_conversion_status].each do |m|
18
- expect(subject).to respond_to(m)
19
- end
20
- end
21
- end
22
-
23
- context 'when sending requests', :aggregate_failures do
24
- context 'and when converting a video' do
25
- let(:uuid) { '169d4bf8-206d-4fa1-8aca-a3aaa73c5cf5' }
26
-
27
- context 'and when request is succeeded' do
28
- it 'converts a video' do
29
- VCR.use_cassette('conversion_api_convert_video') do
30
- params = {
31
- uuid: uuid,
32
- size: { resize_mode: 'change_ratio', width: '600', height: '400' },
33
- quality: 'best',
34
- format: 'ogg',
35
- cut: { start_time: '0:0:0.0', length: '0:0:1.0' },
36
- thumbs: { N: 2, number: 1 }
37
- }
38
- response = subject.convert_video(params, store: false)
39
- expect(response).to be_success
40
- expect(response.success[:problems]).to be_empty
41
- end
42
- end
43
-
44
- it 'gets a video conversion job status' do
45
- VCR.use_cassette('conversion_api_get_video_conversion_status') do
46
- token = '913632082'
47
- response = subject.get_video_conversion_status(token)
48
- expect(response).to be_success
49
- expect(response.success[:error]).to be_nil
50
- end
51
- end
52
- end
53
-
54
- context 'and when request is failed' do
55
- it 'raises a conversion error' do
56
- VCR.use_cassette('conversion_api_convert_video_with_error') do
57
- params = {
58
- uuid: uuid,
59
- size: { resize_mode: 'change_ratio' }
60
- }
61
- expect(subject.convert_video(params, store: false)).to be_failure
62
- end
63
- end
64
- end
65
- end
66
-
67
- context 'and when converting a document' do
68
- let(:uuid) { '86c54d9a-3453-4b12-8dcc-49883ae8f084' }
69
-
70
- context 'and when request is succeeded' do
71
- it 'converts a document' do
72
- VCR.use_cassette('conversion_api_convert_document') do
73
- params = {
74
- uuid: '86c54d9a-3453-4b12-8dcc-49883ae8f084',
75
- format: 'pdf'
76
- }
77
- response = subject.convert_document(params, store: false)
78
- expect(response).to be_success
79
- expect(response.success[:problems]).to be_empty
80
- end
81
- end
82
-
83
- it 'gets a document conversion job status' do
84
- VCR.use_cassette('conversion_api_get_document_conversion_status') do
85
- token = '21201727'
86
- response = subject.get_document_conversion_status(token)
87
- expect(response).to be_success
88
- expect(response.success[:error]).to be_nil
89
- end
90
- end
91
- end
92
-
93
- context 'and when request is failed' do
94
- it 'raises a conversion error' do
95
- VCR.use_cassette('conversion_api_convert_document_with_error') do
96
- params = {
97
- uuid: uuid,
98
- format: 'jpg'
99
- }
100
- expect(subject.convert_document(params, store: false)).to be_failure
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
109
- end
110
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/file_api'
5
-
6
- module Uploadcare
7
- module Rails
8
- module Api
9
- module Rest
10
- RSpec.describe FileApi do
11
- subject { Uploadcare::FileApi }
12
-
13
- context 'when checking methods' do
14
- it 'responds to expected REST methods' do
15
- %i[get_files get_file copy_file delete_file store_file].each do |method|
16
- expect(subject).to respond_to(method)
17
- end
18
- end
19
- end
20
-
21
- context 'when sending requests' do
22
- it 'gets file info' do
23
- VCR.use_cassette('file_api_get_file') do
24
- uuid = '5ae54c37-754c-4982-8de4-3f242a88ce17'
25
- file = subject.get_file(uuid)
26
- expect(file.uuid).to eq(uuid)
27
- end
28
- end
29
-
30
- it 'gets files info', :aggregate_failures do
31
- VCR.use_cassette('file_api_get_files') do
32
- response = subject.get_files
33
- %w[next previous total per_page results].each do |key|
34
- expect(response).to have_key(key)
35
- end
36
- expect(response['results']).not_to be_empty
37
- end
38
- end
39
-
40
- it 'copies a file' do
41
- VCR.use_cassette('file_api_copy_file') do
42
- uuid = 'd43e8281-a42a-4f30-9fee-4a166998d15a'
43
- response = subject.copy_file(uuid, store: false)
44
- expect(response['uuid']).not_to be_nil
45
- expect(response['uuid']).not_to eq(uuid)
46
- end
47
- end
48
-
49
- it 'stores a file' do
50
- VCR.use_cassette('file_api_store_file') do
51
- uuid = '5ae54c37-754c-4982-8de4-3f242a88ce17'
52
- response = subject.store_file(uuid)
53
- expect(response['uuid']).to eq uuid
54
- end
55
- end
56
-
57
- it 'deletes a file' do
58
- VCR.use_cassette('file_api_delete_file') do
59
- uuid = '5ae54c37-754c-4982-8de4-3f242a88ce17'
60
- response = subject.delete_file(uuid)
61
- expect(response['uuid']).to eq uuid
62
- end
63
- end
64
-
65
- it 'stores a batch of files' do
66
- VCR.use_cassette('file_api_store_files') do
67
- uuid = '64215d18-1356-42cb-ab8c-7542290b6e1b'
68
- response = subject.store_files([uuid])
69
- expect(response['result'].first['uuid']).to eq uuid
70
- end
71
- end
72
-
73
- it 'stores a batch of files' do
74
- VCR.use_cassette('file_api_delete_files') do
75
- uuid = '37d70281-cc30-4c59-b8d6-e11c472dec40'
76
- response = subject.delete_files([uuid])
77
- expect(response['result'].first['uuid']).to eq uuid
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/group_api'
5
-
6
- module Uploadcare
7
- module Rails
8
- module Api
9
- module Rest
10
- RSpec.describe GroupApi do
11
- subject { Uploadcare::GroupApi }
12
-
13
- context 'when checking methods' do
14
- it 'responds to expected REST methods' do
15
- %i[get_groups get_group store_group create_group].each do |method|
16
- expect(subject).to respond_to(method)
17
- end
18
- end
19
- end
20
-
21
- context 'when sending requests' do
22
- it 'gets group info' do
23
- VCR.use_cassette('group_api_get_group') do
24
- uuid = '8b1362ed-b477-4a15-819a-2c6bb497d8bd~3'
25
- response = subject.get_group(uuid)
26
- expect(response['id']).to eq(uuid)
27
- end
28
- end
29
-
30
- it 'gets groups info', :aggregate_failures do
31
- VCR.use_cassette('group_api_get_groups') do
32
- response = subject.get_groups
33
- %w[next previous total per_page results].each do |key|
34
- expect(response).to have_key(key)
35
- end
36
- expect(response['results']).not_to be_empty
37
- end
38
- end
39
-
40
- it 'stores a group' do
41
- VCR.use_cassette('group_api_store_group') do
42
- uuid = 'aeaeeb8d-43bc-444d-954f-a171fd872e58~2'
43
- response = subject.store_group(uuid)
44
- expect(response['id']).to eq(uuid)
45
- end
46
- end
47
-
48
- it 'creates a group' do
49
- VCR.use_cassette('group_api_create_group') do
50
- file_ids = %w[f55fcc80-58c1-42eb-9e8f-54d500296d38 4a6ef027-d4cd-49be-a383-8cdbe503aa03]
51
-
52
- response = subject.create_group(file_ids.map { |f| "#{f}/resize/x600" })
53
- expect(response['files'].map { |f| f['file_id'] }).to contain_exactly(*file_ids)
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/project_api'
5
-
6
- module Uploadcare
7
- module Rails
8
- module Api
9
- module Rest
10
- RSpec.describe ProjectApi do
11
- subject { Uploadcare::ProjectApi }
12
-
13
- context 'when checking methods' do
14
- it 'responds to expected REST methods' do
15
- expect(subject).to respond_to('get_project')
16
- end
17
- end
18
-
19
- context 'when sending requests', :aggregate_failures do
20
- it 'gets project info' do
21
- VCR.use_cassette('project_api_get_project') do
22
- response = subject.get_project
23
- %w[collaborators name pub_key autostore_enabled].each do |key|
24
- expect(response).to have_key(key)
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end