uploadcare-rails 1.2.0.pre.alpha3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -16
  3. data/lib/generators/templates/uploadcare_config_template.erb +138 -0
  4. data/lib/generators/uploadcare_config_generator.rb +7 -4
  5. data/lib/uploadcare/errors/type_error.rb +7 -0
  6. data/lib/uploadcare/rails/action_view/uploadcare_include_tags.rb +48 -0
  7. data/lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb +57 -0
  8. data/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb +62 -0
  9. data/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb +58 -0
  10. data/lib/uploadcare/rails/api/rest/base.rb +14 -0
  11. data/lib/uploadcare/rails/api/rest/conversion_api.rb +42 -0
  12. data/lib/uploadcare/rails/api/rest/file_api.rb +69 -0
  13. data/lib/uploadcare/rails/api/rest/group_api.rb +48 -0
  14. data/lib/uploadcare/rails/api/rest/project_api.rb +27 -0
  15. data/lib/uploadcare/rails/api/rest/webhook_api.rb +45 -0
  16. data/lib/uploadcare/rails/api/upload/base.rb +13 -0
  17. data/lib/uploadcare/rails/api/upload/upload_api.rb +53 -0
  18. data/lib/uploadcare/rails/configuration.rb +57 -0
  19. data/lib/uploadcare/rails/engine.rb +13 -17
  20. data/lib/uploadcare/rails/jobs/delete_file_job.rb +14 -0
  21. data/lib/uploadcare/rails/jobs/store_file_job.rb +14 -0
  22. data/lib/uploadcare/rails/jobs/store_group_job.rb +14 -0
  23. data/lib/uploadcare/rails/objects/concerns/loadable.rb +46 -0
  24. data/lib/uploadcare/rails/objects/file.rb +40 -20
  25. data/lib/uploadcare/rails/objects/group.rb +51 -57
  26. data/lib/uploadcare/rails/services/files_count_extractor.rb +14 -0
  27. data/lib/uploadcare/rails/services/id_extractor.rb +15 -0
  28. data/lib/uploadcare/rails/transformations/image_transformations.rb +45 -0
  29. data/lib/uploadcare/rails/version.rb +3 -1
  30. data/lib/uploadcare/rails.rb +10 -0
  31. data/lib/uploadcare-rails.rb +27 -16
  32. data/spec/fixtures/kitten.jpeg +0 -0
  33. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +62 -0
  34. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +62 -0
  35. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +62 -0
  36. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +62 -0
  37. data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +59 -0
  38. data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +59 -0
  39. data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +60 -0
  40. data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +58 -0
  41. data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +58 -0
  42. data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +58 -0
  43. data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +61 -0
  44. data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +57 -0
  45. data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +58 -0
  46. data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +57 -0
  47. data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +57 -0
  48. data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +52 -0
  49. data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +57 -0
  50. data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +57 -0
  51. data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +59 -0
  52. data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +55 -0
  53. data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +105 -0
  54. data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +111 -0
  55. data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +59 -0
  56. data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +57 -0
  57. data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +59 -0
  58. data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +59 -0
  59. data/spec/generators/uploadcare_config_generator_spec.rb +18 -26
  60. data/spec/spec_helper.rb +17 -62
  61. data/spec/support/generators.rb +8 -5
  62. data/spec/support/vcr.rb +14 -0
  63. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +40 -0
  64. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +46 -0
  65. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +33 -0
  66. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +32 -0
  67. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +110 -0
  68. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +85 -0
  69. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +61 -0
  70. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +33 -0
  71. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +67 -0
  72. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +82 -0
  73. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +15 -0
  74. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +15 -0
  75. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +15 -0
  76. data/spec/uploadcare/rails/objects/file_spec.rb +77 -0
  77. data/spec/uploadcare/rails/objects/group_spec.rb +87 -0
  78. data/spec/uploadcare/rails/services/id_extractor_spec.rb +26 -0
  79. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +120 -0
  80. data/spec/uploadcare/rails_spec.rb +7 -0
  81. metadata +129 -393
  82. data/config/initializers/uploadcare.rb +0 -26
  83. data/config/uploadcare_defaults.yml +0 -12
  84. data/lib/generators/templates/uploadcare_config_template.yml +0 -71
  85. data/lib/tasks/uploadcare_rails_tasks.rake +0 -4
  86. data/lib/uploadcare/rails/action_view/include_tags.rb +0 -47
  87. data/lib/uploadcare/rails/action_view/uploader_tags.rb +0 -76
  88. data/lib/uploadcare/rails/active_record/has_file.rb +0 -89
  89. data/lib/uploadcare/rails/active_record/has_group.rb +0 -84
  90. data/lib/uploadcare/rails/active_record/has_object.rb +0 -9
  91. data/lib/uploadcare/rails/formtastic/formtastic.rb +0 -73
  92. data/lib/uploadcare/rails/operations.rb +0 -57
  93. data/lib/uploadcare/rails/settings.rb +0 -81
  94. data/lib/uploadcare/rails/simple_form/simple_form.rb +0 -63
  95. data/spec/caching/file_caching_spec.rb +0 -26
  96. data/spec/caching/group_caching_spec.rb +0 -40
  97. data/spec/cassettes/Uploadcare_Rails_File/should_load_itself.yml +0 -263
  98. data/spec/cassettes/Uploadcare_Rails_Group/group_should_stay_loaded.yml +0 -263
  99. data/spec/cassettes/Uploadcare_Rails_Group/rails_cache_should_updates_after_load_call.yml +0 -263
  100. data/spec/cassettes/group_cahsing_file_load.yml +0 -263
  101. data/spec/cassettes/has_uploadcare_file/object_with_uploadcare_file/deletes_file_after_destroy.yml +0 -1763
  102. data/spec/cassettes/has_uploadcare_file/object_with_uploadcare_file/stores_file_after_save.yml +0 -543
  103. data/spec/cassettes/has_uploadcare_group/object_attachment/contains_files_inside.yml +0 -679
  104. data/spec/cassettes/has_uploadcare_group_save.yml +0 -705
  105. data/spec/cassettes/load_group.yml +0 -263
  106. data/spec/dummy/README.rdoc +0 -28
  107. data/spec/dummy/Rakefile +0 -6
  108. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  109. data/spec/dummy/app/assets/javascripts/post_with_collections.js +0 -2
  110. data/spec/dummy/app/assets/javascripts/posts.js +0 -2
  111. data/spec/dummy/app/assets/javascripts/posts_with_collection_and_files.js +0 -2
  112. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  113. data/spec/dummy/app/assets/stylesheets/post_with_collections.css +0 -4
  114. data/spec/dummy/app/assets/stylesheets/posts.css +0 -4
  115. data/spec/dummy/app/assets/stylesheets/posts_with_collection_and_files.css +0 -4
  116. data/spec/dummy/app/assets/stylesheets/scaffold.css +0 -56
  117. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  118. data/spec/dummy/app/controllers/post_with_collections_controller.rb +0 -58
  119. data/spec/dummy/app/controllers/posts_controller.rb +0 -58
  120. data/spec/dummy/app/controllers/posts_with_collection_and_files_controller.rb +0 -58
  121. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  122. data/spec/dummy/app/helpers/post_with_collections_helper.rb +0 -2
  123. data/spec/dummy/app/helpers/posts_helper.rb +0 -2
  124. data/spec/dummy/app/helpers/posts_with_collection_and_files_helper.rb +0 -2
  125. data/spec/dummy/app/models/post.rb +0 -3
  126. data/spec/dummy/app/models/post_with_collection.rb +0 -3
  127. data/spec/dummy/app/models/posts_with_collection_and_file.rb +0 -4
  128. data/spec/dummy/app/views/layouts/application.html.erb +0 -16
  129. data/spec/dummy/app/views/post_with_collections/_form.html.erb +0 -25
  130. data/spec/dummy/app/views/post_with_collections/edit.html.erb +0 -6
  131. data/spec/dummy/app/views/post_with_collections/index.html.erb +0 -29
  132. data/spec/dummy/app/views/post_with_collections/new.html.erb +0 -5
  133. data/spec/dummy/app/views/post_with_collections/show.html.erb +0 -14
  134. data/spec/dummy/app/views/post_with_collections/show.json.jbuilder +0 -1
  135. data/spec/dummy/app/views/posts/_form.html.erb +0 -31
  136. data/spec/dummy/app/views/posts/edit.html.erb +0 -6
  137. data/spec/dummy/app/views/posts/index.html.erb +0 -37
  138. data/spec/dummy/app/views/posts/new.html.erb +0 -5
  139. data/spec/dummy/app/views/posts/post.json.builder +0 -1
  140. data/spec/dummy/app/views/posts/show.html.erb +0 -15
  141. data/spec/dummy/app/views/posts_with_collection_and_files/_form.html.erb +0 -27
  142. data/spec/dummy/app/views/posts_with_collection_and_files/edit.html.erb +0 -6
  143. data/spec/dummy/app/views/posts_with_collection_and_files/index.html.erb +0 -25
  144. data/spec/dummy/app/views/posts_with_collection_and_files/new.html.erb +0 -5
  145. data/spec/dummy/app/views/posts_with_collection_and_files/show.html.erb +0 -4
  146. data/spec/dummy/app/views/posts_with_collection_and_files/show.json.jbuilder +0 -1
  147. data/spec/dummy/bin/bundle +0 -3
  148. data/spec/dummy/bin/rails +0 -4
  149. data/spec/dummy/bin/rake +0 -4
  150. data/spec/dummy/config/application.rb +0 -23
  151. data/spec/dummy/config/boot.rb +0 -5
  152. data/spec/dummy/config/database.yml +0 -25
  153. data/spec/dummy/config/environment.rb +0 -5
  154. data/spec/dummy/config/environments/development.rb +0 -29
  155. data/spec/dummy/config/environments/production.rb +0 -80
  156. data/spec/dummy/config/environments/test.rb +0 -36
  157. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  158. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  159. data/spec/dummy/config/initializers/formtastic.rb +0 -111
  160. data/spec/dummy/config/initializers/inflections.rb +0 -16
  161. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  162. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  163. data/spec/dummy/config/initializers/session_store.rb +0 -3
  164. data/spec/dummy/config/initializers/simple_form.rb +0 -167
  165. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  166. data/spec/dummy/config/locales/en.yml +0 -23
  167. data/spec/dummy/config/locales/simple_form.en.yml +0 -31
  168. data/spec/dummy/config/routes.rb +0 -63
  169. data/spec/dummy/config/uploadcare.yml +0 -68
  170. data/spec/dummy/config.ru +0 -4
  171. data/spec/dummy/db/migrate/20171012001801_create_tables.rb +0 -27
  172. data/spec/dummy/db/schema.rb +0 -37
  173. data/spec/dummy/db/test.sqlite3 +0 -0
  174. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +0 -13
  175. data/spec/dummy/log/development.log +0 -0
  176. data/spec/dummy/log/test.log +0 -3276
  177. data/spec/dummy/public/404.html +0 -58
  178. data/spec/dummy/public/422.html +0 -58
  179. data/spec/dummy/public/500.html +0 -57
  180. data/spec/dummy/public/favicon.ico +0 -0
  181. data/spec/dummy/tmp/cache/293/091/https%3A%2F%2Fucarecdn.com%2F19073296-2315-4726-817b-46398b2c7431%7E2%2F +0 -0
  182. data/spec/dummy/tmp/cache/2AF/761/https%3A%2F%2Fucarecdn.com%2F595319d0-a113-459f-91bd-b29c7183467b%2F +0 -0
  183. data/spec/dummy/tmp/cache/301/D41/https%3A%2F%2Fucarecdn.com%2F81332043-fa2c-452f-936b-737d87ab2ae2%2F +0 -0
  184. data/spec/dummy/tmp/cache/30A/7C1/https%3A%2F%2Fucarecdn.com%2F39b34128-a001-46fd-9773-1b6ad46e6b9e%2F +0 -0
  185. data/spec/dummy/tmp/cache/340/A41/https%3A%2F%2Fucarecdn.com%2F090bcb5f-6d19-456c-b4a3-d753e690926f%2F +0 -0
  186. data/spec/dummy/tmp/cache/3AB/5A1/https%3A%2F%2Fucarecdn.com%2F7eb0161b-cebe-4316-946b-694de6f77ef9%2F +0 -0
  187. data/spec/dummy/tmp/cache/3FC/5C1/https%3A%2F%2Fucarecdn.com%2Fc3f0464b-ce9a-4281-8eaa-5c55783ccedf%2F +0 -0
  188. data/spec/dummy/tmp/cache/431/5C1/https%3A%2F%2Fucarecdn.com%2Fa1b1bb40-bd89-4f9c-b809-e84920f24a01%7E2%2F +0 -0
  189. data/spec/dummy/tmp/cache/44B/7A1/https%3A%2F%2Fucarecdn.com%2Fd6c785a8-9761-4602-88de-65ddb04ddc6a%7E2%2F +0 -0
  190. data/spec/dummy/tmp/cache/45B/F31/https%3A%2F%2Fucarecdn.com%2F73e3cdbc-6495-4cf2-bbd1-413e6cb70004%7E2%2F +0 -0
  191. data/spec/dummy/tmp/cache/461/AA1/https%3A%2F%2Fucarecdn.com%2Fc50e9a53-0b95-48ac-a4a9-6744052dbdab%7E2%2F +0 -0
  192. data/spec/helpers/form_helpers_has_file_spec.rb +0 -30
  193. data/spec/helpers/form_helpers_has_group_spec.rb +0 -30
  194. data/spec/helpers/form_helpers_spec.rb +0 -33
  195. data/spec/helpers/formtastic_spec.rb +0 -25
  196. data/spec/helpers/include_tags_spec.rb +0 -54
  197. data/spec/helpers/simple_form_spec.rb +0 -25
  198. data/spec/helpers/uploader_tags_spec.rb +0 -21
  199. data/spec/models/has_both_file_and_group_spec.rb +0 -43
  200. data/spec/models/has_file_spec.rb +0 -46
  201. data/spec/models/has_group_spec.rb +0 -57
  202. data/spec/objects/file_spec.rb +0 -27
  203. data/spec/objects/group_spec.rb +0 -51
  204. data/spec/operations_spec.rb +0 -28
  205. data/spec/tmp/config/uploadcare.yml +0 -71
  206. data/spec/uploadcare/rails/settings_spec.rb +0 -136
  207. data/spec/uploadcare_rails_settings_spec.rb +0 -56
  208. data/spec/view.png +0 -0
  209. data/spec/view2.jpg +0 -0
@@ -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,67 @@
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
@@ -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