uploadcare-rails 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uploadcare/rails/api/rest/base.rb +3 -2
  3. data/lib/uploadcare/rails/api/upload/base.rb +2 -0
  4. data/lib/uploadcare/rails/configuration.rb +3 -1
  5. data/lib/uploadcare/rails/transformations/image_transformations.rb +1 -1
  6. data/lib/uploadcare/rails/version.rb +1 -1
  7. metadata +28 -139
  8. data/spec/fixtures/kitten.jpeg +0 -0
  9. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +0 -62
  10. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +0 -62
  11. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +0 -62
  12. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +0 -62
  13. data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +0 -59
  14. data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +0 -59
  15. data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +0 -60
  16. data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +0 -61
  17. data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +0 -58
  18. data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +0 -61
  19. data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +0 -61
  20. data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +0 -57
  21. data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +0 -61
  22. data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +0 -57
  23. data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +0 -61
  24. data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +0 -56
  25. data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +0 -57
  26. data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +0 -177
  27. data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +0 -59
  28. data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +0 -59
  29. data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +0 -105
  30. data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +0 -111
  31. data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +0 -59
  32. data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +0 -59
  33. data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +0 -59
  34. data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +0 -59
  35. data/spec/generators/uploadcare_config_generator_spec.rb +0 -31
  36. data/spec/spec_helper.rb +0 -27
  37. data/spec/support/generators.rb +0 -41
  38. data/spec/support/vcr.rb +0 -14
  39. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +0 -40
  40. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +0 -46
  41. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +0 -33
  42. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +0 -32
  43. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +0 -110
  44. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +0 -76
  45. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +0 -61
  46. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +0 -33
  47. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +0 -67
  48. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +0 -82
  49. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +0 -15
  50. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +0 -15
  51. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +0 -15
  52. data/spec/uploadcare/rails/objects/file_spec.rb +0 -77
  53. data/spec/uploadcare/rails/objects/group_spec.rb +0 -65
  54. data/spec/uploadcare/rails/services/id_extractor_spec.rb +0 -26
  55. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +0 -120
  56. data/spec/uploadcare/rails_spec.rb +0 -7
@@ -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,76 +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 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 = '2254146d-3652-4419-abf6-305d36ef30a8'
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 'stores a file' do
41
- VCR.use_cassette('file_api_store_file') do
42
- uuid = '2254146d-3652-4419-abf6-305d36ef30a8'
43
- response = subject.store_file(uuid)
44
- expect(response['uuid']).to eq uuid
45
- end
46
- end
47
-
48
- it 'deletes a file' do
49
- VCR.use_cassette('file_api_delete_file') do
50
- uuid = '2254146d-3652-4419-abf6-305d36ef30a8'
51
- response = subject.delete_file(uuid)
52
- expect(response['uuid']).to eq uuid
53
- end
54
- end
55
-
56
- it 'stores a batch of files' do
57
- VCR.use_cassette('file_api_store_files') do
58
- uuid = '64215d18-1356-42cb-ab8c-7542290b6e1b'
59
- response = subject.store_files([uuid])
60
- expect(response['result'].first['uuid']).to eq uuid
61
- end
62
- end
63
-
64
- it 'stores a batch of files' do
65
- VCR.use_cassette('file_api_delete_files') do
66
- uuid = '37d70281-cc30-4c59-b8d6-e11c472dec40'
67
- response = subject.delete_files([uuid])
68
- expect(response['result'].first['uuid']).to eq uuid
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
76
- 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 = '6053b054-b8d4-4f57-992d-94b8f1d6ba65~2'
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 = '6053b054-b8d4-4f57-992d-94b8f1d6ba65~2'
43
- response = subject.store_group(uuid)
44
- expect(response).to eq('200 OK')
45
- end
46
- end
47
-
48
- it 'creates a group' do
49
- VCR.use_cassette('group_api_create_group') do
50
- file_ids = %w[272cbffa-4a27-4aba-98f1-a36e2e017e24 36892dd8-ccb1-4225-bc48-96a0fde93b33]
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
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/webhook_api'
5
-
6
- module Uploadcare
7
- module Rails
8
- module Api
9
- module Rest
10
- RSpec.describe WebhookApi do
11
- subject { Uploadcare::WebhookApi }
12
-
13
- context 'when checking methods' do
14
- it 'responds to expected REST methods' do
15
- %i[get_webhooks create_webhook update_webhook delete_webhook].each do |method|
16
- expect(subject).to respond_to(method)
17
- end
18
- end
19
- end
20
-
21
- context 'when sending requests', :aggregate_failures do
22
- it 'gets webhooks info' do
23
- VCR.use_cassette('webhook_api_get_webhooks') do
24
- response = subject.get_webhooks
25
- expect(response).not_to be_empty
26
- end
27
- end
28
-
29
- it 'creates a webhook', :aggregate_failures do
30
- VCR.use_cassette('webhook_api_create_webhook') do
31
- response = subject.create_webhook(
32
- 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png',
33
- signing_secret: '1234'
34
- )
35
- %w[id created updated event target_url project is_active].each do |key|
36
- expect(response).to have_key(key)
37
- end
38
- end
39
- end
40
-
41
- it 'updates a webhook', :aggregate_failures do
42
- VCR.use_cassette('webhook_api_update_webhook') do
43
- new_target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
44
- response = subject.update_webhook(
45
- '811134',
46
- target_url: new_target_url,
47
- is_active: false,
48
- signing_secret: '1234'
49
- )
50
- expect(response['target_url']).to eq(new_target_url)
51
- expect(response['is_active']).to eq(false)
52
- end
53
- end
54
-
55
- it 'deletes a webhook', :aggregate_failures do
56
- VCR.use_cassette('webhook_api_delete_webhook') do
57
- target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
58
- response = subject.delete_webhook(target_url)
59
- expect(response).to be_success
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/upload/upload_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 Upload
12
- RSpec.describe UploadApi do
13
- subject { Uploadcare::UploadApi }
14
-
15
- context 'when checking methods' do
16
- it 'responds to expected REST methods' do
17
- %i[upload_file upload_files].each do |method|
18
- expect(subject).to respond_to(method)
19
- end
20
- end
21
- end
22
-
23
- context 'when sending requests' do
24
- context 'and when uploading a single file' do
25
- context 'and when uploading is successful' do
26
- shared_examples 'uploads a single file' do
27
- it 'uploads a file' do
28
- VCR.use_cassette(cassete) do
29
- upload = subject.upload_file(file)
30
- expect(upload).to be_kind_of(file_type_in_response)
31
- end
32
- end
33
- end
34
-
35
- it_behaves_like 'uploads a single file' do
36
- let(:cassete) { 'upload_upload_one_file_from_cdn' }
37
- let(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
38
- let(:file_type_in_response) { Uploadcare::Entity::File }
39
- end
40
-
41
- it_behaves_like 'uploads a single file' do
42
- let(:cassete) { 'upload_upload_one_file' }
43
- let(:file) { 'https://ucarecdn.com/c3328b8f-1b27-48ca-aebe-591924011efc/thumbnail_0.jpg' }
44
- let(:file_type_in_response) { Array }
45
- end
46
- end
47
-
48
- context 'and when uploading is failed' do
49
- subject { super().upload_file([]) }
50
-
51
- it 'raises an error' do
52
- expect { subject }.to raise_error(TypeError)
53
- end
54
- end
55
- end
56
-
57
- context 'and when uploading a several files' do
58
- let(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
59
-
60
- context 'and when uploading is successful' do
61
- it 'uploads a file' do
62
- VCR.use_cassette('upload_upload_many_files') do
63
- upload = subject.upload_files([file])
64
- expect(upload).to be_kind_of(Array)
65
- end
66
- end
67
- end
68
-
69
- context 'and when uploading is failed' do
70
- subject { super().upload_files(file) }
71
-
72
- it 'raises an error' do
73
- expect { subject }.to raise_error(TypeError)
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/delete_file_job'
5
-
6
- RSpec.describe Uploadcare::Rails::DeleteFileJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a delete file job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later(SecureRandom.uuid)
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/store_file_job'
5
-
6
- RSpec.describe Uploadcare::Rails::StoreFileJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a store file job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later(SecureRandom.uuid)
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/store_group_job'
5
-
6
- RSpec.describe Uploadcare::Rails::StoreGroupJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a store file group job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later('id')
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/objects/file'
5
- require 'rails/all'
6
-
7
- describe Uploadcare::Rails::File do
8
- let(:file) do
9
- described_class.new(
10
- cdn_url: 'https://ucarecdn.com/2254146d-3652-4419-abf6-305d36ef30a8/',
11
- uuid: '2254146d-3652-4419-abf6-305d36ef30a8'
12
- )
13
- end
14
- let(:cache) { Rails.cache }
15
- let(:config) { OpenStruct.new(cache_files: true) }
16
- let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
17
-
18
- before do
19
- allow(Rails).to receive(:cache).and_return(memory_store)
20
- allow(Uploadcare::Rails).to receive(:configuration).and_return(config)
21
- Rails.cache.clear
22
- end
23
-
24
- context 'when checking file storing' do
25
- it 'stores a file', :aggregate_failures do
26
- VCR.use_cassette 'file_api_store_file' do
27
- response = file.store
28
- expect(response[:uuid]).to eq file.uuid
29
- expect(file.loaded?).to be_truthy
30
- end
31
- end
32
- end
33
-
34
- context 'when checking file deleting' do
35
- it 'deletes a file' do
36
- VCR.use_cassette 'file_api_delete_file' do
37
- response = file.delete
38
- expect(response[:uuid]).to eq file.uuid
39
- end
40
- end
41
- end
42
-
43
- context 'when checking file to_s method' do
44
- it 'check the :to_s method' do
45
- expect(file.to_s).to eq file.cdn_url
46
- end
47
- end
48
-
49
- context 'when checking file loading' do
50
- it 'checks that a file is not loaded by default' do
51
- expect(file.loaded?).to be_falsey
52
- end
53
-
54
- it 'checks that a file is loaded' do
55
- VCR.use_cassette 'file_api_get_file' do
56
- file.load
57
- expect(file.loaded?).to be_truthy
58
- end
59
- end
60
- end
61
-
62
- context 'when checking url transformations' do
63
- subject { file.transform_url(**transformation_args) }
64
-
65
- let(:transformator_class) { Uploadcare::Rails::Transformations::ImageTransformations }
66
- let(:transformation_args) { { resize: '300x500' } }
67
- let(:transformations) { '/resize/300x500/' }
68
- let(:new_url) { "#{file.cdn_url}-#{transformations}" }
69
-
70
- before { allow(transformator_class).to receive_message_chain(:new, :call).and_return(transformations) }
71
-
72
- it 'checks that the transformator received :new method', :aggregate_failures do
73
- expect(transformator_class).to receive(:new).with(transformation_args)
74
- expect(subject).to eq new_url
75
- end
76
- end
77
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/objects/group'
5
- require 'rails/all'
6
-
7
- describe Uploadcare::Rails::Group do
8
- let(:group) do
9
- described_class.new(
10
- cdn_url: 'https://ucarecdn.com/6053b054-b8d4-4f57-992d-94b8f1d6ba65~2/',
11
- id: '6053b054-b8d4-4f57-992d-94b8f1d6ba65~2',
12
- files_count: '2'
13
- )
14
- end
15
- let(:cache) { Rails.cache }
16
- let(:config) { OpenStruct.new(cache_files: true) }
17
- let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
18
-
19
- before do
20
- allow(Rails).to receive(:cache).and_return(memory_store)
21
- allow(Uploadcare::Rails).to receive(:configuration).and_return(config)
22
- Rails.cache.clear
23
- end
24
-
25
- context 'when checking group storing' do
26
- it 'stores a group', :aggregate_failures do
27
- VCR.use_cassette 'group_api_store_group' do
28
- response = group.store
29
- expect(response).to eq('200 OK')
30
- end
31
- end
32
- end
33
-
34
- context 'when checking group to_s method' do
35
- it 'returns the cdn_url of a group' do
36
- expect(group.to_s).to eq group.cdn_url
37
- end
38
- end
39
-
40
- context 'when checking file urls' do
41
- let(:expected_urls) { Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/" } }
42
-
43
- it 'returns file urls of a group' do
44
- expect(group.file_urls).to contain_exactly(*expected_urls)
45
- end
46
- end
47
-
48
- context 'when checking file urls transformations' do
49
- subject { group.transform_file_urls(**transformation_args) }
50
-
51
- let(:transformator_class) { Uploadcare::Rails::Transformations::ImageTransformations }
52
- let(:transformation_args) { { resize: '300x500' } }
53
- let(:transformations) { '/resize/300x500/' }
54
- let(:expected_urls) do
55
- Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/-#{transformations}" }
56
- end
57
-
58
- before { allow(transformator_class).to receive_message_chain(:new, :call).and_return(transformations) }
59
-
60
- it 'sends a :new method to the transformator_class', :aggregate_failures do
61
- expect(transformator_class).to receive(:new).with(transformation_args)
62
- expect(subject).to contain_exactly(*expected_urls)
63
- end
64
- end
65
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/services/id_extractor'
5
-
6
- describe Uploadcare::Rails::IdExtractor, type: :service do
7
- subject { described_class.call(cdn_url, regex) }
8
-
9
- let(:uuid) { 'a5c4b078-39ec-424d-8a51-1eb15c673e49' }
10
-
11
- context 'when extracting a UUID from a cdn_urls' do
12
- let(:regex) { /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/ }
13
-
14
- [
15
- 'https://ucarecdn.com/:uuid/',
16
- "https://ucarecdn.com/:uuid/-/overlay/#{SecureRandom.uuid}/",
17
- "https://ucarecdn.com/:uuid/image-#{SecureRandom.uuid}.jpg"
18
- ].each do |masked_url|
19
- let(:cdn_url) { masked_url.gsub(':uuid', uuid) }
20
-
21
- it "extracts an UUID from the cdn_url - #{masked_url}" do
22
- expect(subject).to eq uuid
23
- end
24
- end
25
- end
26
- end