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,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Uncomment this string in case of using locales for locale_translations parameter
|
4
|
+
# I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
|
5
|
+
|
6
|
+
Uploadcare::Rails.configure do |config|
|
7
|
+
# Sets your Uploadcare public key.
|
8
|
+
config.public_key = ENV.fetch('UPLOADCARE_PUBLIC_KEY', 'demopublickey')
|
9
|
+
# config.secret_key = ENV.fetch('UPLOADCARE_SECRET_KEY', 'demosecretkey')
|
10
|
+
|
11
|
+
# Stores files to Uploadcare servers after object save.
|
12
|
+
config.store_files_after_save = true
|
13
|
+
|
14
|
+
# Deletes files from Uploadcare servers after object destroy.
|
15
|
+
config.delete_files_after_destroy = true
|
16
|
+
|
17
|
+
# Sets caching for Uploadcare files
|
18
|
+
config.cache_namespace = 'uploadcare'
|
19
|
+
config.cache_files = true
|
20
|
+
config.cache_expires_in = 1.day
|
21
|
+
|
22
|
+
# These options enables ActiveJob background jobs to perform operations in background.
|
23
|
+
# Options work if only the option 'do_not_store' is disabled (false) and
|
24
|
+
# the option 'delete_files_after_destroy' is enabled (true).
|
25
|
+
config.store_files_async = true
|
26
|
+
config.delete_files_async = true
|
27
|
+
|
28
|
+
# If true, only image files are allowed to be uploaded.
|
29
|
+
# config.images_only = false
|
30
|
+
|
31
|
+
# If true, the preview step is present after selecting files.
|
32
|
+
# Otherwise, the file uploader dialog closes when the selection is complete.
|
33
|
+
# config.preview_step = false
|
34
|
+
|
35
|
+
# Defines the file uploader manual crop behavior (see https://uploadcare.com/docs/uploads/file-uploader/#crop-option).
|
36
|
+
# When uploading images, your users can select a crop area.
|
37
|
+
# This option does not force your file uploader to accept images only.
|
38
|
+
# The option also works in the multi-file mode since version 2.3.0.
|
39
|
+
# config.crop = 'disabled'
|
40
|
+
|
41
|
+
# Saves traffic and storage space by resizing images on a client before uploading.
|
42
|
+
# See the detailed option description for details. Using the client-side resize does not force the images only option.
|
43
|
+
# config.image_shrink = '800x600'
|
44
|
+
|
45
|
+
# Allows user to remove uploaded files from the file uploader.
|
46
|
+
# Please note that those files are not deleted from your account.
|
47
|
+
# config.clearable = true
|
48
|
+
|
49
|
+
# Allows you to define which upload sources you want to use with the file uploader.
|
50
|
+
# The value is represented by a space-separated ordered list of upload source names.
|
51
|
+
# See https://uploadcare.com/docs/uploads/file-uploader/#upload-sources for details.
|
52
|
+
# config.tabs = %w[url file facebook]
|
53
|
+
|
54
|
+
# Sets the accept attribute for the file uploader dialog.
|
55
|
+
# If the images only option is disabled, the value is empty.
|
56
|
+
# Otherwise, the default value is image/*.
|
57
|
+
# null means accept should be kept empty regardless of the images only value.
|
58
|
+
# For other possible values, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
59
|
+
# Note, this is not a replacement for
|
60
|
+
# our file validation (see https://uploadcare.com/docs/file-uploader-api/file-validation/)
|
61
|
+
# because your users will still be able to choose any file via drag&drop or from URL.
|
62
|
+
# config.input_accept_types = %w[image/*]
|
63
|
+
|
64
|
+
# Defines the list of preferred MIME types.
|
65
|
+
# The list should be ordered and contain space-separated MIME types.
|
66
|
+
# Common parts can be marked with asterisks: image/* application/vnd.openxmlformats-officedocument.*.
|
67
|
+
# If no MIME types match the criteria or preferred types are not set, default formats are used.
|
68
|
+
# Keep in mind that some cloud services can export data in different formats.
|
69
|
+
# For example, Google document can be exported as Word document, PDF or plain text.
|
70
|
+
# config.preferred_types = %w[image/* application/vnd.openxmlformats-officedocument.*]
|
71
|
+
|
72
|
+
# Forces a system-native file picking dialog to show up instead of our file uploader.
|
73
|
+
# That makes the file uploader behavior as close as possible to the generic <input type="file">.
|
74
|
+
# Native behavior is achieved at the expense of support for uploading content
|
75
|
+
# from social media and cloud storage, manual crop, and preview step.
|
76
|
+
# Multi-file selection would still work.
|
77
|
+
# The option does not work in old browser versions: the dialog falls back to the file uploader.
|
78
|
+
# config.system_dialog = false
|
79
|
+
|
80
|
+
# This option sets the file size threshold for multipart uploading.
|
81
|
+
# The value ranges from 10485760 (10 MB), which is default, up to 104857600 (100 MB).
|
82
|
+
# If a file size hits the threshold, it gets uploaded in four parallel chunks by 5 MB.
|
83
|
+
# Multipart upload makes large file uploading faster.
|
84
|
+
# Files go directly to a storage, bypassing our upload servers,
|
85
|
+
# and they're quickly available for further use. All files below the threshold get uploaded in one piece.
|
86
|
+
# Note: Multipart upload works with local sources only (files and camera).
|
87
|
+
# config.multipart_min_size = 10485760
|
88
|
+
|
89
|
+
# Available locales currently are:
|
90
|
+
# ar az ca cs da de el en es et fr he it ja ko lv nb nl pl pt ro ru sk sr sv tr uk vi zhTW zh
|
91
|
+
config.locale = 'en'
|
92
|
+
|
93
|
+
# Sets custom localization options. See https://uploadcare.com/docs/uploads/file-uploader/#localization
|
94
|
+
# config.locale_translations = {}
|
95
|
+
|
96
|
+
# Defines pluralization options. See https://uploadcare.com/docs/uploads/file-uploader/#pluralization
|
97
|
+
# config.locale_pluralize = {}
|
98
|
+
|
99
|
+
# The option can be used with Authenticated URLs. Defines your proxy backend URL.
|
100
|
+
# See https://uploadcare.com/docs/security/secure-delivery/#proxy-backend.
|
101
|
+
# config.preview_proxy = 'https://domain.com/preview?'
|
102
|
+
|
103
|
+
# If true, inputs on your page are initialized automatically, see the article for details -
|
104
|
+
# https://uploadcare.com/docs/file-uploader-api/widget-initialization/
|
105
|
+
config.live = true
|
106
|
+
|
107
|
+
# If true, input initialization is invoked manually.
|
108
|
+
# See https://uploadcare.com/docs/file-uploader-api/widget-initialization/).
|
109
|
+
config.manual_start = false
|
110
|
+
|
111
|
+
# Defines your schema and CDN domain.
|
112
|
+
# Can be changed to one of the predefined values (https://uploadcare.com/docs/delivery/cdn/) or your custom CNAME.
|
113
|
+
# config.cdn_base = 'https://ucarecdn.com/'
|
114
|
+
config.cdn_hostname = 'ucarecdn.com'
|
115
|
+
|
116
|
+
# Forces files uploaded with a file uploader not to be stored.
|
117
|
+
# See https://uploadcare.com/docs/uploads/storage/#storing-uploaded-files.
|
118
|
+
# For instance, you might want to turn this on when automatic file storing is enabled in your project,
|
119
|
+
# but you do not want to store files uploaded with a particular file uploader.
|
120
|
+
# config.do_not_store = false
|
121
|
+
|
122
|
+
# Allows you to adjust the quality of an audio recorded via the file uploader Camera Tab.
|
123
|
+
# Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
|
124
|
+
# config.audio_bits_per_second = 1
|
125
|
+
|
126
|
+
# Allows you to specify the MIME types.
|
127
|
+
# The first supported by the browser will be used as an option of
|
128
|
+
# video stream captured via the file uploader Camera Tab.
|
129
|
+
# Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
|
130
|
+
# config.video_preferred_mime_types = []
|
131
|
+
|
132
|
+
# Allows you to adjust the quality of a video stream captured via the file uploader Camera Tab.
|
133
|
+
# Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
|
134
|
+
# config.video_bits_per_second = 1
|
135
|
+
|
136
|
+
# Allows you to set the default state of image/video mirorring in the camera tab.
|
137
|
+
# config.camera_mirror_default = true
|
138
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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
|
@@ -0,0 +1,46 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,110 @@
|
|
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
|
@@ -0,0 +1,85 @@
|
|
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
|
@@ -0,0 +1,61 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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
|
@@ -0,0 +1,59 @@
|
|
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('https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png')
|
32
|
+
%w[id created updated event target_url project is_active].each do |key|
|
33
|
+
expect(response).to have_key(key)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'updates a webhook', :aggregate_failures do
|
39
|
+
VCR.use_cassette('webhook_api_update_webhook') do
|
40
|
+
new_target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
|
41
|
+
response = subject.update_webhook('811134', target_url: new_target_url, is_active: false)
|
42
|
+
expect(response['target_url']).to eq(new_target_url)
|
43
|
+
expect(response['is_active']).to eq(false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'deletes a webhook', :aggregate_failures do
|
48
|
+
VCR.use_cassette('webhook_api_delete_webhook') do
|
49
|
+
target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
|
50
|
+
response = subject.delete_webhook(target_url)
|
51
|
+
expect(response).to be_success
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|