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.
Files changed (190) hide show
  1. checksums.yaml +5 -5
  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 -69
  61. data/spec/support/generators.rb +8 -5
  62. data/spec/support/vcr.rb +14 -0
  63. data/spec/tmp/config/initializers/uploadcare.rb +138 -0
  64. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +40 -0
  65. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +46 -0
  66. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +33 -0
  67. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +32 -0
  68. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +110 -0
  69. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +85 -0
  70. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +61 -0
  71. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +33 -0
  72. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +59 -0
  73. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +82 -0
  74. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +15 -0
  75. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +15 -0
  76. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +15 -0
  77. data/spec/uploadcare/rails/objects/file_spec.rb +77 -0
  78. data/spec/uploadcare/rails/objects/group_spec.rb +87 -0
  79. data/spec/uploadcare/rails/services/id_extractor_spec.rb +26 -0
  80. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +120 -0
  81. data/spec/uploadcare/rails_spec.rb +7 -0
  82. metadata +129 -351
  83. data/config/initializers/uploadcare.rb +0 -26
  84. data/config/uploadcare_defaults.yml +0 -12
  85. data/lib/generators/templates/uploadcare_config_template.yml +0 -67
  86. data/lib/tasks/uploadcare_rails_tasks.rake +0 -4
  87. data/lib/uploadcare/rails/action_view/include_tags.rb +0 -47
  88. data/lib/uploadcare/rails/action_view/uploader_tags.rb +0 -76
  89. data/lib/uploadcare/rails/active_record/has_file.rb +0 -92
  90. data/lib/uploadcare/rails/active_record/has_group.rb +0 -89
  91. data/lib/uploadcare/rails/active_record/has_object.rb +0 -9
  92. data/lib/uploadcare/rails/formtastic/formtastic.rb +0 -73
  93. data/lib/uploadcare/rails/operations.rb +0 -57
  94. data/lib/uploadcare/rails/settings.rb +0 -81
  95. data/lib/uploadcare/rails/simple_form/simple_form.rb +0 -63
  96. data/spec/caching/file_caching_spec.rb +0 -26
  97. data/spec/caching/group_caching_spec.rb +0 -40
  98. data/spec/dummy/README.rdoc +0 -28
  99. data/spec/dummy/Rakefile +0 -6
  100. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  101. data/spec/dummy/app/assets/javascripts/post_with_collections.js +0 -2
  102. data/spec/dummy/app/assets/javascripts/posts.js +0 -2
  103. data/spec/dummy/app/assets/javascripts/posts_with_collection_and_files.js +0 -2
  104. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  105. data/spec/dummy/app/assets/stylesheets/post_with_collections.css +0 -4
  106. data/spec/dummy/app/assets/stylesheets/posts.css +0 -4
  107. data/spec/dummy/app/assets/stylesheets/posts_with_collection_and_files.css +0 -4
  108. data/spec/dummy/app/assets/stylesheets/scaffold.css +0 -56
  109. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  110. data/spec/dummy/app/controllers/post_with_collections_controller.rb +0 -58
  111. data/spec/dummy/app/controllers/posts_controller.rb +0 -58
  112. data/spec/dummy/app/controllers/posts_with_collection_and_files_controller.rb +0 -58
  113. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  114. data/spec/dummy/app/helpers/post_with_collections_helper.rb +0 -2
  115. data/spec/dummy/app/helpers/posts_helper.rb +0 -2
  116. data/spec/dummy/app/helpers/posts_with_collection_and_files_helper.rb +0 -2
  117. data/spec/dummy/app/models/post.rb +0 -4
  118. data/spec/dummy/app/models/post_with_collection.rb +0 -4
  119. data/spec/dummy/app/models/posts_with_collection_and_file.rb +0 -4
  120. data/spec/dummy/app/views/layouts/application.html.erb +0 -16
  121. data/spec/dummy/app/views/post_with_collections/_form.html.erb +0 -25
  122. data/spec/dummy/app/views/post_with_collections/edit.html.erb +0 -6
  123. data/spec/dummy/app/views/post_with_collections/index.html.erb +0 -29
  124. data/spec/dummy/app/views/post_with_collections/new.html.erb +0 -5
  125. data/spec/dummy/app/views/post_with_collections/show.html.erb +0 -14
  126. data/spec/dummy/app/views/post_with_collections/show.json.jbuilder +0 -1
  127. data/spec/dummy/app/views/posts/_form.html.erb +0 -31
  128. data/spec/dummy/app/views/posts/edit.html.erb +0 -6
  129. data/spec/dummy/app/views/posts/index.html.erb +0 -37
  130. data/spec/dummy/app/views/posts/new.html.erb +0 -5
  131. data/spec/dummy/app/views/posts/post.json.builder +0 -1
  132. data/spec/dummy/app/views/posts/show.html.erb +0 -15
  133. data/spec/dummy/app/views/posts_with_collection_and_files/_form.html.erb +0 -27
  134. data/spec/dummy/app/views/posts_with_collection_and_files/edit.html.erb +0 -6
  135. data/spec/dummy/app/views/posts_with_collection_and_files/index.html.erb +0 -25
  136. data/spec/dummy/app/views/posts_with_collection_and_files/new.html.erb +0 -5
  137. data/spec/dummy/app/views/posts_with_collection_and_files/show.html.erb +0 -4
  138. data/spec/dummy/app/views/posts_with_collection_and_files/show.json.jbuilder +0 -1
  139. data/spec/dummy/bin/bundle +0 -3
  140. data/spec/dummy/bin/rails +0 -4
  141. data/spec/dummy/bin/rake +0 -4
  142. data/spec/dummy/config/application.rb +0 -23
  143. data/spec/dummy/config/boot.rb +0 -4
  144. data/spec/dummy/config/database.yml +0 -25
  145. data/spec/dummy/config/environment.rb +0 -5
  146. data/spec/dummy/config/environments/development.rb +0 -29
  147. data/spec/dummy/config/environments/production.rb +0 -80
  148. data/spec/dummy/config/environments/test.rb +0 -36
  149. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  150. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  151. data/spec/dummy/config/initializers/formtastic.rb +0 -111
  152. data/spec/dummy/config/initializers/inflections.rb +0 -16
  153. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  154. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  155. data/spec/dummy/config/initializers/session_store.rb +0 -3
  156. data/spec/dummy/config/initializers/simple_form.rb +0 -167
  157. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  158. data/spec/dummy/config/locales/en.yml +0 -23
  159. data/spec/dummy/config/locales/simple_form.en.yml +0 -31
  160. data/spec/dummy/config/routes.rb +0 -63
  161. data/spec/dummy/config/uploadcare.yml +0 -64
  162. data/spec/dummy/config.ru +0 -4
  163. data/spec/dummy/db/migrate/20171012001801_create_tables.rb +0 -27
  164. data/spec/dummy/db/migrate/20181001132710_add_other_file_to_post.rb +0 -8
  165. data/spec/dummy/db/migrate/20181001141434_add_other_file_to_post_with_collections.rb +0 -8
  166. data/spec/dummy/db/schema.rb +0 -39
  167. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +0 -13
  168. data/spec/dummy/public/404.html +0 -58
  169. data/spec/dummy/public/422.html +0 -58
  170. data/spec/dummy/public/500.html +0 -57
  171. data/spec/dummy/public/favicon.ico +0 -0
  172. data/spec/helpers/form_helpers_has_file_spec.rb +0 -30
  173. data/spec/helpers/form_helpers_has_group_spec.rb +0 -30
  174. data/spec/helpers/form_helpers_spec.rb +0 -33
  175. data/spec/helpers/formtastic_spec.rb +0 -25
  176. data/spec/helpers/include_tags_spec.rb +0 -54
  177. data/spec/helpers/simple_form_spec.rb +0 -25
  178. data/spec/helpers/uploader_tags_spec.rb +0 -21
  179. data/spec/models/has_both_file_and_group_spec.rb +0 -43
  180. data/spec/models/has_file_spec.rb +0 -46
  181. data/spec/models/has_group_spec.rb +0 -57
  182. data/spec/models/has_several_files_spec.rb +0 -55
  183. data/spec/models/has_several_groups_spec.rb +0 -62
  184. data/spec/objects/file_spec.rb +0 -27
  185. data/spec/objects/group_spec.rb +0 -51
  186. data/spec/operations_spec.rb +0 -28
  187. data/spec/uploadcare/rails/settings_spec.rb +0 -136
  188. data/spec/uploadcare_rails_settings_spec.rb +0 -56
  189. data/spec/view.png +0 -0
  190. data/spec/view2.jpg +0 -0
@@ -1,43 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe :has_both_file_and_group_spec do
4
- let(:subject) do
5
- PostsWithCollectionAndFile.new(
6
- title: "Post title",
7
- group: GROUP_CDN_URL,
8
- file: FILE_CDN_URL
9
- )
10
- end
11
-
12
- after :each do
13
- Rails.cache.delete FILE_CDN_URL
14
- Rails.cache.delete GROUP_CDN_URL
15
- end
16
-
17
- it 'creates empty post' do
18
- expect(PostsWithCollectionAndFile.create).to be_persisted
19
- end
20
-
21
- it "should respond to has_uploadcare_file? method" do
22
- is_expected.to respond_to("has_file_as_uploadcare_file?".to_sym)
23
- end
24
-
25
- it "should respond to has_uploadcare_group? method" do
26
- is_expected.to respond_to("has_group_as_uploadcare_group?".to_sym)
27
- end
28
-
29
- it ":has_uploadcare_file? should return true" do
30
- is_expected.to be_has_file_as_uploadcare_file
31
- is_expected.to be_has_group_as_uploadcare_group
32
- end
33
-
34
- it ":has_uploadcare_group? should return false" do
35
- is_expected.not_to be_has_group_as_uploadcare_file
36
- is_expected.not_to be_has_file_as_uploadcare_group
37
- end
38
-
39
- it "should have uploadcare file" do
40
- expect(subject.group).to be_an(Uploadcare::Rails::Group)
41
- expect(subject.file).to be_an(Uploadcare::Rails::File)
42
- end
43
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :has_uploadcare_file, :vcr do
4
- let(:post) { Post.new(title: 'Post title', file: FILE_CDN_URL) }
5
- let(:subject) { post }
6
- let(:method) { 'file' }
7
-
8
- describe 'object with uploadcare_file' do
9
- it 'creates blank post' do
10
- Post.create!
11
- end
12
- it 'responds to has_uploadcare_file? method' do
13
- is_expected.to respond_to(:has_file_as_uploadcare_file?)
14
- end
15
-
16
- it 'responds to has_uploadcare_group? method' do
17
- is_expected.to respond_to(:has_file_as_uploadcare_group?)
18
- end
19
-
20
- it 'has Uploadcare::Rails::File' do
21
- expect(post.file).to be_an(Uploadcare::Rails::File)
22
- end
23
-
24
- it 'stores file after save' do
25
- post.save
26
- expect(post.file).to be_stored
27
- end
28
-
29
- it 'deletes file after destroy',
30
- vcr: 'has_upload_care_file_destroy_file' do
31
- post.save
32
- post.destroy
33
- expect(post.file).to be_deleted
34
- end
35
- end
36
-
37
- context 'instanse methods' do
38
- it '#has_uploadcare_file? returns true' do
39
- expect(post.has_file_as_uploadcare_file?).to be_truthy
40
- end
41
-
42
- it '#has_uploadcare_group? returns false' do
43
- expect(post.has_file_as_uploadcare_group?).to be_falsey
44
- end
45
- end
46
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :has_uploadcare_group, :vcr do
4
- let(:post) { PostWithCollection.new(title: 'Title', file: GROUP_CDN_URL) }
5
- let(:method) { 'file' }
6
-
7
- after :each do
8
- Rails.cache.delete(GROUP_CDN_URL)
9
- end
10
-
11
- describe 'object with group' do
12
- let(:subject) { post }
13
- it 'should respond to has_uploadcare_file? method' do
14
- is_expected.to respond_to('has_file_as_uploadcare_file?'.to_sym)
15
- end
16
-
17
- it 'should respond to has_uploadcare_group? method' do
18
- is_expected.to respond_to('has_file_as_uploadcare_group?'.to_sym)
19
- end
20
-
21
- it ':has_uploadcare_file? should return true' do
22
- is_expected.not_to be_has_file_as_uploadcare_file
23
- end
24
-
25
- it ':has_uploadcare_group? should return false' do
26
- is_expected.to be_has_file_as_uploadcare_group
27
- end
28
- end
29
-
30
- describe 'object attachment' do
31
- let(:subject) { post.file }
32
-
33
- it 'should have uploadcare file' do
34
- is_expected.to be_an(Uploadcare::Rails::Group)
35
- end
36
-
37
- it 'dont loads group by default' do
38
- is_expected.not_to be_loaded
39
- end
40
-
41
- it 'contains files inside' do
42
- expect(subject.load.files.last).to be_an(Uploadcare::Rails::File)
43
- end
44
-
45
- it 'stores group after save', vcr: { cassette_name: 'has_uploadcare_group_save' } do
46
- post.save
47
- is_expected.to be_stored
48
- end
49
-
50
- skip 'deleteds group after destroy' do
51
- post.save
52
- post.file.load
53
- post.destroy
54
- expect(post.file).to be_deleted
55
- end
56
- end
57
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :has_two_uploadcare_files, :vcr do
4
- let(:post) { Post.new(title: 'Post title', file: FILE_CDN_URL, other_file: FILE_2_CDN_URL) }
5
- let(:subject) { post }
6
-
7
- describe 'object with uploadcare_files' do
8
- it 'creates blank post' do
9
- Post.create!
10
- end
11
-
12
- it 'responds to has_uploadcare_file? method' do
13
- is_expected.to respond_to(:has_file_as_uploadcare_file?)
14
- is_expected.to respond_to(:has_other_file_as_uploadcare_file?)
15
- end
16
-
17
- it 'responds to has_uploadcare_group? method' do
18
- is_expected.to respond_to(:has_file_as_uploadcare_group?)
19
- is_expected.to respond_to(:has_other_file_as_uploadcare_group?)
20
- end
21
-
22
- it 'has Uploadcare::Rails::File' do
23
- expect(post.file).to be_an(Uploadcare::Rails::File)
24
- expect(post.other_file).to be_an(Uploadcare::Rails::File)
25
- expect(post.file.cdn_url).not_to be(post.other_file.cdn_url)
26
- end
27
-
28
- it 'stores file after save' do
29
- post.save
30
-
31
- expect(post.file).to be_stored
32
- expect(post.other_file).to be_stored
33
- end
34
-
35
- it 'deletes file after destroy', vcr: 'has_upload_care_file_destroy_file' do
36
- post.save
37
- post.destroy
38
-
39
- expect(post.file).to be_deleted
40
- expect(post.other_file).to be_deleted
41
- end
42
- end
43
-
44
- context 'instance methods' do
45
- it '#has_uploadcare_file? returns true' do
46
- expect(post.has_file_as_uploadcare_file?).to be_truthy
47
- expect(post.has_other_file_as_uploadcare_file?).to be_truthy
48
- end
49
-
50
- it '#has_uploadcare_group? returns false' do
51
- expect(post.has_file_as_uploadcare_group?).to be_falsey
52
- expect(post.has_other_file_as_uploadcare_group?).to be_falsey
53
- end
54
- end
55
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe :has_uploadcare_group, :vcr do
4
- let(:post) { PostWithCollection.new(
5
- title: 'Title',
6
- file: GROUP_CDN_URL,
7
- other_file: GROUP_2_CDN_URL
8
- ) }
9
- let(:subject) { post }
10
-
11
- after :each do
12
- Rails.cache.delete(GROUP_CDN_URL)
13
- Rails.cache.delete(GROUP_2_CDN_URL)
14
- end
15
-
16
- describe 'object with two groups' do
17
- it 'should respond to has_uploadcare_file? method' do
18
- is_expected.to respond_to('has_file_as_uploadcare_file?'.to_sym)
19
- is_expected.to respond_to('has_other_file_as_uploadcare_file?'.to_sym)
20
- end
21
-
22
- it 'should respond to has_uploadcare_group? method' do
23
- is_expected.to respond_to('has_file_as_uploadcare_group?'.to_sym)
24
- is_expected.to respond_to('has_other_file_as_uploadcare_group?'.to_sym)
25
- end
26
-
27
- it ':has_uploadcare_file? should return true' do
28
- is_expected.not_to be_has_file_as_uploadcare_file
29
- is_expected.not_to be_has_other_file_as_uploadcare_file
30
- end
31
-
32
- it ':has_uploadcare_group? should return false' do
33
- is_expected.to be_has_file_as_uploadcare_group
34
- is_expected.to be_has_other_file_as_uploadcare_group
35
- end
36
- end
37
-
38
- describe 'object attachment' do
39
- it 'should have uploadcare file' do
40
- expect(post.file).to be_an(Uploadcare::Rails::Group)
41
- expect(post.other_file).to be_an(Uploadcare::Rails::Group)
42
- expect(post.file.cdn_url).not_to be(post.other_file.cdn_url)
43
- end
44
-
45
- it 'does not load group by default' do
46
- expect(post.file).not_to be_loaded
47
- expect(post.other_file).not_to be_loaded
48
- end
49
-
50
- it 'contains files inside' do
51
- expect(post.file.load.files.last).to be_an(Uploadcare::Rails::File)
52
- expect(post.other_file.load.files.last).to be_an(Uploadcare::Rails::File)
53
- end
54
-
55
- it 'stores group after save', vcr: { cassette_name: 'has_uploadcare_group_save' } do
56
- post.save
57
-
58
- expect(post.file).to be_stored
59
- expect(post.other_file).to be_stored
60
- end
61
- end
62
- end
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Uploadcare::Rails::File, :vcr do
4
- let(:post) { Post.new(title: "Post title", file: FILE_CDN_URL) }
5
- let(:file) { post.file }
6
-
7
- after :each do
8
- Rails.cache.delete FILE_CDN_URL
9
- end
10
-
11
- it "should be Uploadcare::Rails::File" do
12
- expect(file).to be_a(Uploadcare::Rails::File)
13
- end
14
-
15
- it "should be not loaded by default" do
16
- expect(file).not_to be_loaded
17
- end
18
-
19
- it "should load itself" do
20
- file.load
21
- expect(file).to be_loaded
22
- end
23
-
24
- it "file should respond to :cdn_url and :to_s methods" do
25
- expect(file.to_s).to eq file.cdn_url
26
- end
27
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Rails::Group, :vcr do
4
- let(:post) { PostWithCollection.new(title: 'Title', file: GROUP_CDN_URL) }
5
- let(:group) { post.file }
6
- let(:subject) { group }
7
-
8
- describe 'instance' do
9
- it 'is Uploadcare::Rails::Gropu' do
10
- is_expected.to be_an(Uploadcare::Rails::Group)
11
- end
12
-
13
- it 'is not loaded by default' do
14
- is_expected.not_to be_loaded
15
- end
16
-
17
- it 'responds to :uuid and :to_s methods' do
18
- expect(group.to_s).to eq(subject.uuid)
19
- end
20
- end
21
-
22
- describe 'loaded group', vcr: { cassette_name: :load_group} do
23
- let(:subject) { group.load }
24
-
25
- it 'loads itself' do
26
- is_expected.to be_loaded
27
- end
28
-
29
- it 'has files' do
30
- expect(subject.files).to be_an(Array)
31
- expect(subject.files.sample).to be_an(Uploadcare::Rails::File)
32
- end
33
-
34
- it 'loaded group files should be loaded too' do
35
- expect(subject.files.sample).to be_loaded
36
- end
37
- end
38
-
39
- describe 'images workaround' do
40
- it 'is an array' do
41
- expect(subject.urls).to be_an(Array)
42
- end
43
-
44
- it 'builds images url' do
45
- allow_any_instance_of(Uploadcare::Api).to receive(:options) { {static_url_base: 'http://example.com'} }
46
- expected = "http://example.com/#{ subject.uuid }/nth/0/-/resize/200x200/"
47
-
48
- expect(subject.urls(size: '200x200').first).to eq(expected)
49
- end
50
- end
51
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Rails do
4
- let(:operations) do
5
- {
6
- format: :jpeg,
7
- quality: :normal,
8
- progressive: :yes,
9
- preview: '200x150',
10
- resize: '150x',
11
- inline: '//overlay/:uuid/50%x50%/center/'
12
- }
13
- end
14
-
15
- let(:subject) { Uploadcare::Rails::Operations.new(operations).to_s }
16
-
17
- it { is_expected.to include('format/jpeg') }
18
- it { is_expected.to include('quality/normal') }
19
- it { is_expected.to include('progressive/yes') }
20
- it { is_expected.to include('preview/200x150') }
21
- it { is_expected.to include('resize/150x') }
22
- it { is_expected.to include('/overlay/:uuid/50%x50%/center/') }
23
-
24
- it do
25
- is_expected.
26
- to eq('-/format/jpeg/-/quality/normal/-/progressive/yes/-/preview/200x150/-/resize/150x/-/overlay/:uuid/50%x50%/center/')
27
- end
28
- end
@@ -1,136 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Rails::Settings do
4
- subject(:settings) { described_class.new(test: config) }
5
-
6
- let(:full_config) do
7
- {
8
- widget_version: '3.x',
9
- upload_url_base: 'http://example.com/',
10
- api_url_base: 'http://example.com/',
11
- static_url_base: 'http://example.com/',
12
- api_version: '0.3',
13
- public_key: 'test_public_key',
14
- private_key: 'test_private_key',
15
- auth_scheme: :secure,
16
- cache_files: true,
17
- cache_groups: true,
18
- delete_after_destroy: true,
19
- store_after_save: true,
20
- locale: 'en',
21
- images_only: true,
22
- multiple: true,
23
- multiple_min: 2,
24
- multiple_max: 3,
25
- preview_step: true,
26
- crop: true,
27
- clearable: true,
28
- tabs: "url file facebook",
29
- autostore: true,
30
- live: true,
31
- manual_start: true,
32
- path_value: true,
33
- }
34
- end
35
- let(:config) { full_config }
36
-
37
- it { is_expected.to respond_to(:widget_version) }
38
- it { is_expected.to respond_to(:upload_url_base) }
39
- it { is_expected.to respond_to(:api_url_base) }
40
- it { is_expected.to respond_to(:static_url_base) }
41
- it { is_expected.to respond_to(:api_version) }
42
- it { is_expected.to respond_to(:cache_files) }
43
- it { is_expected.to respond_to(:cache_groups) }
44
- it { is_expected.to respond_to(:public_key) }
45
- it { is_expected.to respond_to(:private_key) }
46
- it { is_expected.to respond_to(:auth_scheme) }
47
- it { is_expected.to respond_to(:delete_after_destroy) }
48
- it { is_expected.to respond_to(:store_after_save) }
49
- it { is_expected.to respond_to(:locale) }
50
- it { is_expected.to respond_to(:images_only) }
51
- it { is_expected.to respond_to(:multiple) }
52
- it { is_expected.to respond_to(:multiple_min) }
53
- it { is_expected.to respond_to(:multiple_max) }
54
- it { is_expected.to respond_to(:preview_step) }
55
- it { is_expected.to respond_to(:crop) }
56
- it { is_expected.to respond_to(:clearable) }
57
- it { is_expected.to respond_to(:tabs) }
58
- it { is_expected.to respond_to(:autostore) }
59
- it { is_expected.to respond_to(:live) }
60
- it { is_expected.to respond_to(:manual_start) }
61
- it { is_expected.to respond_to(:path_value) }
62
-
63
- it { is_expected.to have_attributes(full_config) }
64
-
65
- it { is_expected.to respond_to(:api) }
66
- it { expect(settings.api).to be_a(Uploadcare::Api) }
67
-
68
- it { is_expected.to respond_to(:api_settings) }
69
- it { expect(settings.api_settings).to eq(settings.to_h) }
70
-
71
- it { is_expected.to respond_to(:widget_settings) }
72
- it 'filters private settings' do
73
- expect(settings.widget_settings).to eq(
74
- public_key: "test_public_key",
75
- locale: 'en',
76
- images_only: true,
77
- multiple: true,
78
- multiple_min: 2,
79
- multiple_max: 3,
80
- preview_step: true,
81
- crop: true,
82
- clearable: true,
83
- tabs: "url file facebook",
84
- autostore: true,
85
- live: true,
86
- manual_start: true,
87
- path_value: true,
88
- )
89
- end
90
-
91
- context 'when no config for the current rails env given' do
92
- subject(:settings) { described_class.new(development: config) }
93
- it { expect { settings }.to raise_error(ArgumentError) }
94
- end
95
-
96
- context 'works with both symbols and strings in a config' do
97
- subject(:settings) { described_class.new('test' => config.stringify_keys) }
98
- it { is_expected.to have_attributes(full_config) }
99
- end
100
-
101
- context 'when some settings are missing in the config' do
102
- context 'if missing settings are some of uploadcare-ruby defaults' do
103
- let(:uploadcare_ruby_defaults) do
104
- Uploadcare::DEFAULT_SETTINGS.except(:public_key, :private_key)
105
- end
106
- let(:config) { full_config.except(*uploadcare_ruby_defaults.keys) }
107
-
108
- it 'sets missing settings from uploadcare-ruby defaults' do
109
- uploadcare_ruby_defaults.each do |k, v|
110
- expect(settings).to have_attributes(k => v)
111
- end
112
- end
113
- end
114
-
115
- context 'if public key is missing' do
116
- let(:config) { full_config.except(:public_key) }
117
- it { expect { settings }.to raise_error(ArgumentError) }
118
- end
119
-
120
- context 'if private key is missing' do
121
- let(:config) { full_config.except(:private_key) }
122
- it { expect { settings }.to raise_error(ArgumentError) }
123
- end
124
-
125
- context 'if missing settings are some of uploadcare-rails defaults' do
126
- let(:uploadcare_rails_defaults) { Uploadcare::Rails::DEFAULT_SETTINGS }
127
- let(:config) { full_config.except(uploadcare_rails_defaults.keys) }
128
-
129
- it 'sets missing settings from uploadcare-rails defaults' do
130
- uploadcare_rails_defaults.each do |k, v|
131
- expect(settings).to have_attributes(k => v)
132
- end
133
- end
134
- end
135
- end
136
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Rails do
4
- it "should load settings" do
5
- UPLOADCARE_SETTINGS.should_not be_nil
6
- UPLOADCARE_SETTINGS.should be_kind_of(Uploadcare::Rails::Settings)
7
- end
8
-
9
- it "settings should respond to all defined methods" do
10
- UPLOADCARE_SETTINGS.should respond_to(:widget_version)
11
- UPLOADCARE_SETTINGS.should respond_to(:upload_url_base)
12
- UPLOADCARE_SETTINGS.should respond_to(:api_url_base)
13
- UPLOADCARE_SETTINGS.should respond_to(:static_url_base)
14
- UPLOADCARE_SETTINGS.should respond_to(:api_version)
15
- UPLOADCARE_SETTINGS.should respond_to(:cache_files)
16
- UPLOADCARE_SETTINGS.should respond_to(:public_key)
17
- UPLOADCARE_SETTINGS.should respond_to(:private_key)
18
- end
19
-
20
- it "should have private and public keys as not empty strings" do
21
- UPLOADCARE_SETTINGS.private_key.should be_kind_of(String)
22
- UPLOADCARE_SETTINGS.public_key.should be_kind_of(String)
23
-
24
- UPLOADCARE_SETTINGS.private_key.should_not be_empty
25
- UPLOADCARE_SETTINGS.public_key.should_not be_empty
26
- end
27
-
28
- it "pub and private keys should be loaded from config file" do
29
- config_file = "#{Rails.root}/config/uploadcare.yml"
30
- config = YAML.load_file(config_file)
31
-
32
- UPLOADCARE_SETTINGS.private_key.should == config["test"]["private_key"]
33
- UPLOADCARE_SETTINGS.public_key.should == config["test"]["public_key"]
34
- end
35
-
36
- # TODO: test api settings and widget settings
37
- it "should build instanse of UC api" do
38
- UPLOADCARE_SETTINGS.api.should be_kind_of(Uploadcare::Api)
39
- end
40
-
41
- it "should build api settings hash" do
42
- UPLOADCARE_SETTINGS.api_settings.should be_a_kind_of(Hash)
43
- UPLOADCARE_SETTINGS.api_settings.should_not be_empty
44
- end
45
-
46
- it "should build widget settings hash" do
47
- UPLOADCARE_SETTINGS.widget_settings.should be_a_kind_of(Hash)
48
- UPLOADCARE_SETTINGS.widget_settings.should_not be_empty
49
- end
50
-
51
- it 'should include user agent environment config' do
52
- expect(UPLOADCARE_SETTINGS.user_agent_environment.keys).to include(
53
- :framework_name, :framework_version, :extension_name, :extension_version
54
- )
55
- end
56
- end
data/spec/view.png DELETED
Binary file
data/spec/view2.jpg DELETED
Binary file