uploadcare-rails 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +5 -16
- data/lib/generators/templates/uploadcare_config_template.erb +138 -0
- data/lib/generators/uploadcare_config_generator.rb +7 -4
- data/lib/uploadcare/errors/type_error.rb +7 -0
- data/lib/uploadcare/rails/action_view/uploadcare_include_tags.rb +48 -0
- data/lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb +57 -0
- data/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb +62 -0
- data/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb +58 -0
- data/lib/uploadcare/rails/api/rest/base.rb +14 -0
- data/lib/uploadcare/rails/api/rest/conversion_api.rb +42 -0
- data/lib/uploadcare/rails/api/rest/file_api.rb +69 -0
- data/lib/uploadcare/rails/api/rest/group_api.rb +48 -0
- data/lib/uploadcare/rails/api/rest/project_api.rb +27 -0
- data/lib/uploadcare/rails/api/rest/webhook_api.rb +45 -0
- data/lib/uploadcare/rails/api/upload/base.rb +13 -0
- data/lib/uploadcare/rails/api/upload/upload_api.rb +53 -0
- data/lib/uploadcare/rails/configuration.rb +57 -0
- data/lib/uploadcare/rails/engine.rb +13 -17
- data/lib/uploadcare/rails/jobs/delete_file_job.rb +14 -0
- data/lib/uploadcare/rails/jobs/store_file_job.rb +14 -0
- data/lib/uploadcare/rails/jobs/store_group_job.rb +14 -0
- data/lib/uploadcare/rails/objects/concerns/loadable.rb +46 -0
- data/lib/uploadcare/rails/objects/file.rb +40 -20
- data/lib/uploadcare/rails/objects/group.rb +51 -57
- data/lib/uploadcare/rails/services/files_count_extractor.rb +14 -0
- data/lib/uploadcare/rails/services/id_extractor.rb +15 -0
- data/lib/uploadcare/rails/transformations/image_transformations.rb +45 -0
- data/lib/uploadcare/rails/version.rb +3 -1
- data/lib/uploadcare/rails.rb +10 -0
- data/lib/uploadcare-rails.rb +27 -16
- data/spec/fixtures/kitten.jpeg +0 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +62 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +62 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +62 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +62 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +59 -0
- data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +59 -0
- data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +60 -0
- data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +58 -0
- data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +58 -0
- data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +58 -0
- data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +61 -0
- data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +57 -0
- data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +58 -0
- data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +57 -0
- data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +57 -0
- data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +52 -0
- data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +57 -0
- data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +57 -0
- data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +59 -0
- data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +55 -0
- data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +105 -0
- data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +111 -0
- data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +59 -0
- data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +57 -0
- data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +59 -0
- data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +59 -0
- data/spec/generators/uploadcare_config_generator_spec.rb +18 -26
- data/spec/spec_helper.rb +17 -69
- data/spec/support/generators.rb +8 -5
- data/spec/support/vcr.rb +14 -0
- data/spec/tmp/config/initializers/uploadcare.rb +138 -0
- data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +40 -0
- data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +46 -0
- data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +33 -0
- data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +32 -0
- data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +110 -0
- data/spec/uploadcare/rails/api/rest/file_api_spec.rb +85 -0
- data/spec/uploadcare/rails/api/rest/group_api_spec.rb +61 -0
- data/spec/uploadcare/rails/api/rest/project_api_spec.rb +33 -0
- data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +59 -0
- data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +82 -0
- data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +15 -0
- data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +15 -0
- data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +15 -0
- data/spec/uploadcare/rails/objects/file_spec.rb +77 -0
- data/spec/uploadcare/rails/objects/group_spec.rb +87 -0
- data/spec/uploadcare/rails/services/id_extractor_spec.rb +26 -0
- data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +120 -0
- data/spec/uploadcare/rails_spec.rb +7 -0
- metadata +129 -351
- data/config/initializers/uploadcare.rb +0 -26
- data/config/uploadcare_defaults.yml +0 -12
- data/lib/generators/templates/uploadcare_config_template.yml +0 -67
- data/lib/tasks/uploadcare_rails_tasks.rake +0 -4
- data/lib/uploadcare/rails/action_view/include_tags.rb +0 -47
- data/lib/uploadcare/rails/action_view/uploader_tags.rb +0 -76
- data/lib/uploadcare/rails/active_record/has_file.rb +0 -92
- data/lib/uploadcare/rails/active_record/has_group.rb +0 -89
- data/lib/uploadcare/rails/active_record/has_object.rb +0 -9
- data/lib/uploadcare/rails/formtastic/formtastic.rb +0 -73
- data/lib/uploadcare/rails/operations.rb +0 -57
- data/lib/uploadcare/rails/settings.rb +0 -81
- data/lib/uploadcare/rails/simple_form/simple_form.rb +0 -63
- data/spec/caching/file_caching_spec.rb +0 -26
- data/spec/caching/group_caching_spec.rb +0 -40
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/javascripts/post_with_collections.js +0 -2
- data/spec/dummy/app/assets/javascripts/posts.js +0 -2
- data/spec/dummy/app/assets/javascripts/posts_with_collection_and_files.js +0 -2
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/assets/stylesheets/post_with_collections.css +0 -4
- data/spec/dummy/app/assets/stylesheets/posts.css +0 -4
- data/spec/dummy/app/assets/stylesheets/posts_with_collection_and_files.css +0 -4
- data/spec/dummy/app/assets/stylesheets/scaffold.css +0 -56
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/post_with_collections_controller.rb +0 -58
- data/spec/dummy/app/controllers/posts_controller.rb +0 -58
- data/spec/dummy/app/controllers/posts_with_collection_and_files_controller.rb +0 -58
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/helpers/post_with_collections_helper.rb +0 -2
- data/spec/dummy/app/helpers/posts_helper.rb +0 -2
- data/spec/dummy/app/helpers/posts_with_collection_and_files_helper.rb +0 -2
- data/spec/dummy/app/models/post.rb +0 -4
- data/spec/dummy/app/models/post_with_collection.rb +0 -4
- data/spec/dummy/app/models/posts_with_collection_and_file.rb +0 -4
- data/spec/dummy/app/views/layouts/application.html.erb +0 -16
- data/spec/dummy/app/views/post_with_collections/_form.html.erb +0 -25
- data/spec/dummy/app/views/post_with_collections/edit.html.erb +0 -6
- data/spec/dummy/app/views/post_with_collections/index.html.erb +0 -29
- data/spec/dummy/app/views/post_with_collections/new.html.erb +0 -5
- data/spec/dummy/app/views/post_with_collections/show.html.erb +0 -14
- data/spec/dummy/app/views/post_with_collections/show.json.jbuilder +0 -1
- data/spec/dummy/app/views/posts/_form.html.erb +0 -31
- data/spec/dummy/app/views/posts/edit.html.erb +0 -6
- data/spec/dummy/app/views/posts/index.html.erb +0 -37
- data/spec/dummy/app/views/posts/new.html.erb +0 -5
- data/spec/dummy/app/views/posts/post.json.builder +0 -1
- data/spec/dummy/app/views/posts/show.html.erb +0 -15
- data/spec/dummy/app/views/posts_with_collection_and_files/_form.html.erb +0 -27
- data/spec/dummy/app/views/posts_with_collection_and_files/edit.html.erb +0 -6
- data/spec/dummy/app/views/posts_with_collection_and_files/index.html.erb +0 -25
- data/spec/dummy/app/views/posts_with_collection_and_files/new.html.erb +0 -5
- data/spec/dummy/app/views/posts_with_collection_and_files/show.html.erb +0 -4
- data/spec/dummy/app/views/posts_with_collection_and_files/show.json.jbuilder +0 -1
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -4
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -29
- data/spec/dummy/config/environments/production.rb +0 -80
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/formtastic.rb +0 -111
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -12
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/simple_form.rb +0 -167
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/locales/simple_form.en.yml +0 -31
- data/spec/dummy/config/routes.rb +0 -63
- data/spec/dummy/config/uploadcare.yml +0 -64
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20171012001801_create_tables.rb +0 -27
- data/spec/dummy/db/migrate/20181001132710_add_other_file_to_post.rb +0 -8
- data/spec/dummy/db/migrate/20181001141434_add_other_file_to_post_with_collections.rb +0 -8
- data/spec/dummy/db/schema.rb +0 -39
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +0 -13
- data/spec/dummy/public/404.html +0 -58
- data/spec/dummy/public/422.html +0 -58
- data/spec/dummy/public/500.html +0 -57
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/form_helpers_has_file_spec.rb +0 -30
- data/spec/helpers/form_helpers_has_group_spec.rb +0 -30
- data/spec/helpers/form_helpers_spec.rb +0 -33
- data/spec/helpers/formtastic_spec.rb +0 -25
- data/spec/helpers/include_tags_spec.rb +0 -54
- data/spec/helpers/simple_form_spec.rb +0 -25
- data/spec/helpers/uploader_tags_spec.rb +0 -21
- data/spec/models/has_both_file_and_group_spec.rb +0 -43
- data/spec/models/has_file_spec.rb +0 -46
- data/spec/models/has_group_spec.rb +0 -57
- data/spec/models/has_several_files_spec.rb +0 -55
- data/spec/models/has_several_groups_spec.rb +0 -62
- data/spec/objects/file_spec.rb +0 -27
- data/spec/objects/group_spec.rb +0 -51
- data/spec/operations_spec.rb +0 -28
- data/spec/uploadcare/rails/settings_spec.rb +0 -136
- data/spec/uploadcare_rails_settings_spec.rb +0 -56
- data/spec/view.png +0 -0
- data/spec/view2.jpg +0 -0
@@ -0,0 +1,82 @@
|
|
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
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,77 @@
|
|
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/5ae54c37-754c-4982-8de4-3f242a88ce17/',
|
11
|
+
uuid: '5ae54c37-754c-4982-8de4-3f242a88ce17'
|
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
|
@@ -0,0 +1,87 @@
|
|
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/aeaeeb8d-43bc-444d-954f-a171fd872e58~2/',
|
11
|
+
id: 'aeaeeb8d-43bc-444d-954f-a171fd872e58~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[:id]).to eq group.id
|
30
|
+
expect(group.loaded?).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when checking group to_s method' do
|
36
|
+
it 'returns the cdn_url of a group' do
|
37
|
+
expect(group.to_s).to eq group.cdn_url
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when checking group loading' do
|
42
|
+
let(:group) do
|
43
|
+
described_class.new(
|
44
|
+
cdn_url: 'https://ucarecdn.com/8b1362ed-b477-4a15-819a-2c6bb497d8bd~3/',
|
45
|
+
id: '8b1362ed-b477-4a15-819a-2c6bb497d8bd~3',
|
46
|
+
files_count: '2'
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'checks that a group is not loaded by default' do
|
51
|
+
expect(group.loaded?).to be_falsey
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'checks that a group is loaded' do
|
55
|
+
VCR.use_cassette 'group_api_get_group' do
|
56
|
+
group.load
|
57
|
+
expect(group.loaded?).to be_truthy
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when checking file urls' do
|
63
|
+
let(:expected_urls) { Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/" } }
|
64
|
+
|
65
|
+
it 'returns file urls of a group' do
|
66
|
+
expect(group.file_urls).to contain_exactly(*expected_urls)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when checking file urls transformations' do
|
71
|
+
subject { group.transform_file_urls(**transformation_args) }
|
72
|
+
|
73
|
+
let(:transformator_class) { Uploadcare::Rails::Transformations::ImageTransformations }
|
74
|
+
let(:transformation_args) { { resize: '300x500' } }
|
75
|
+
let(:transformations) { '/resize/300x500/' }
|
76
|
+
let(:expected_urls) do
|
77
|
+
Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/-#{transformations}" }
|
78
|
+
end
|
79
|
+
|
80
|
+
before { allow(transformator_class).to receive_message_chain(:new, :call).and_return(transformations) }
|
81
|
+
|
82
|
+
it 'sends a :new method to the transformator_class', :aggregate_failures do
|
83
|
+
expect(transformator_class).to receive(:new).with(**transformation_args)
|
84
|
+
expect(subject).to contain_exactly(*expected_urls)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'uploadcare/rails/transformations/image_transformations'
|
5
|
+
|
6
|
+
describe Uploadcare::Rails::Transformations::ImageTransformations do
|
7
|
+
subject { described_class.new(**arguments).call }
|
8
|
+
|
9
|
+
let(:arguments) do
|
10
|
+
{
|
11
|
+
# Resize and crop
|
12
|
+
preview: '300x500',
|
13
|
+
resize: '300x500',
|
14
|
+
smart_resize: '300x500',
|
15
|
+
crop: {
|
16
|
+
dimensions: '300x500',
|
17
|
+
coords: '2400,700',
|
18
|
+
alignment: 'center'
|
19
|
+
},
|
20
|
+
scale_crop: {
|
21
|
+
dimensions: '300x500',
|
22
|
+
offsets: '50%,50%',
|
23
|
+
smart_mode: 'smart'
|
24
|
+
},
|
25
|
+
setfill: 'ece3d2',
|
26
|
+
# Compression
|
27
|
+
format: 'png',
|
28
|
+
quality: 'smart',
|
29
|
+
progressive: 'yes',
|
30
|
+
gif2video: true,
|
31
|
+
# Colors
|
32
|
+
brightness: '50',
|
33
|
+
exposure: '50',
|
34
|
+
gamma: '50',
|
35
|
+
contrast: '50',
|
36
|
+
saturation: '50',
|
37
|
+
vibrance: '50',
|
38
|
+
warmth: '50',
|
39
|
+
enhance: '50',
|
40
|
+
grayscale: true,
|
41
|
+
invert: true,
|
42
|
+
filter: {
|
43
|
+
name: 'adaris',
|
44
|
+
amount: 50
|
45
|
+
},
|
46
|
+
srgb: 'fast',
|
47
|
+
max_icc_size: 2,
|
48
|
+
# Blur and sharpen
|
49
|
+
blur: {
|
50
|
+
strength: 50,
|
51
|
+
amount: 90
|
52
|
+
},
|
53
|
+
blur_region: {
|
54
|
+
dimensions: '300x500',
|
55
|
+
coords: '2400,700',
|
56
|
+
strength: 50
|
57
|
+
},
|
58
|
+
sharp: 50,
|
59
|
+
# Overlay
|
60
|
+
overlay: {
|
61
|
+
uuid: 'self',
|
62
|
+
relative_dimensions: '50%x50%',
|
63
|
+
relative_coordinates: 'center',
|
64
|
+
opacity: '20p'
|
65
|
+
},
|
66
|
+
# Rotate and flip
|
67
|
+
autorotate: 'yes',
|
68
|
+
rotate: 90,
|
69
|
+
flip: true,
|
70
|
+
mirror: true
|
71
|
+
}
|
72
|
+
end
|
73
|
+
let(:expected_string) do
|
74
|
+
"/preview/#{arguments[:preview]}/-" \
|
75
|
+
"/resize/#{arguments[:resize]}/-" \
|
76
|
+
"/smart_resize/#{arguments[:smart_resize]}/-" \
|
77
|
+
"/crop/#{arguments[:crop].values.join('/')}/-" \
|
78
|
+
"/scale_crop/#{arguments[:scale_crop].values.join('/')}/-" \
|
79
|
+
"/setfill/#{arguments[:setfill]}/-" \
|
80
|
+
"/format/#{arguments[:format]}/-" \
|
81
|
+
"/quality/#{arguments[:quality]}/-" \
|
82
|
+
"/progressive/#{arguments[:progressive]}/-" \
|
83
|
+
'/gif2video/-' \
|
84
|
+
"/brightness/#{arguments[:brightness]}/-" \
|
85
|
+
"/exposure/#{arguments[:exposure]}/-" \
|
86
|
+
"/gamma/#{arguments[:gamma]}/-" \
|
87
|
+
"/contrast/#{arguments[:contrast]}/-" \
|
88
|
+
"/saturation/#{arguments[:saturation]}/-" \
|
89
|
+
"/vibrance/#{arguments[:vibrance]}/-" \
|
90
|
+
"/warmth/#{arguments[:warmth]}/-" \
|
91
|
+
"/enhance/#{arguments[:enhance]}/-" \
|
92
|
+
'/grayscale/-' \
|
93
|
+
'/invert/-' \
|
94
|
+
"/filter/#{arguments[:filter].values.join('/')}/-" \
|
95
|
+
"/srgb/#{arguments[:srgb]}/-" \
|
96
|
+
"/max_icc_size/#{arguments[:max_icc_size]}/-" \
|
97
|
+
"/blur/#{arguments[:blur].values.join('/')}/-" \
|
98
|
+
"/blur_region/#{arguments[:blur_region].values.join('/')}/-" \
|
99
|
+
"/sharp/#{arguments[:sharp]}/-" \
|
100
|
+
"/overlay/#{arguments[:overlay].values.join('/')}/-" \
|
101
|
+
"/autorotate/#{arguments[:autorotate]}/-" \
|
102
|
+
"/rotate/#{arguments[:rotate]}/-" \
|
103
|
+
'/flip/-' \
|
104
|
+
'/mirror/'
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'builds image transformations params url' do
|
108
|
+
expect(subject).to eq expected_string
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when sending invalid data' do
|
112
|
+
context 'and when including spaces in params' do
|
113
|
+
let(:arguments) { { preview: '300x 500' } }
|
114
|
+
|
115
|
+
it 'removes all spaces from the result string' do
|
116
|
+
expect(subject).not_to match(/\s/)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|