kt-paperclip 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +17 -0
  3. data/.github/issue_template.md +3 -0
  4. data/.gitignore +19 -0
  5. data/.hound.yml +1050 -0
  6. data/.rubocop.yml +1 -0
  7. data/.travis.yml +47 -0
  8. data/Appraisals +24 -0
  9. data/CONTRIBUTING.md +86 -0
  10. data/Gemfile +18 -0
  11. data/LICENSE +24 -0
  12. data/NEWS +515 -0
  13. data/README.md +1053 -0
  14. data/RELEASING.md +17 -0
  15. data/Rakefile +52 -0
  16. data/UPGRADING +17 -0
  17. data/features/basic_integration.feature +85 -0
  18. data/features/migration.feature +29 -0
  19. data/features/rake_tasks.feature +62 -0
  20. data/features/step_definitions/attachment_steps.rb +110 -0
  21. data/features/step_definitions/html_steps.rb +15 -0
  22. data/features/step_definitions/rails_steps.rb +257 -0
  23. data/features/step_definitions/s3_steps.rb +14 -0
  24. data/features/step_definitions/web_steps.rb +106 -0
  25. data/features/support/env.rb +12 -0
  26. data/features/support/fakeweb.rb +11 -0
  27. data/features/support/file_helpers.rb +34 -0
  28. data/features/support/fixtures/boot_config.txt +15 -0
  29. data/features/support/fixtures/gemfile.txt +5 -0
  30. data/features/support/fixtures/preinitializer.txt +20 -0
  31. data/features/support/paths.rb +28 -0
  32. data/features/support/rails.rb +39 -0
  33. data/features/support/selectors.rb +19 -0
  34. data/gemfiles/4.2.gemfile +20 -0
  35. data/gemfiles/5.0.gemfile +20 -0
  36. data/gemfiles/5.1.gemfile +20 -0
  37. data/gemfiles/5.2.gemfile +20 -0
  38. data/gemfiles/6.0.gemfile +20 -0
  39. data/lib/generators/paperclip/USAGE +8 -0
  40. data/lib/generators/paperclip/paperclip_generator.rb +36 -0
  41. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +15 -0
  42. data/lib/paperclip.rb +215 -0
  43. data/lib/paperclip/attachment.rb +617 -0
  44. data/lib/paperclip/attachment_registry.rb +60 -0
  45. data/lib/paperclip/callbacks.rb +42 -0
  46. data/lib/paperclip/content_type_detector.rb +80 -0
  47. data/lib/paperclip/errors.rb +34 -0
  48. data/lib/paperclip/file_command_content_type_detector.rb +28 -0
  49. data/lib/paperclip/filename_cleaner.rb +15 -0
  50. data/lib/paperclip/geometry.rb +157 -0
  51. data/lib/paperclip/geometry_detector_factory.rb +45 -0
  52. data/lib/paperclip/geometry_parser_factory.rb +31 -0
  53. data/lib/paperclip/glue.rb +17 -0
  54. data/lib/paperclip/has_attached_file.rb +116 -0
  55. data/lib/paperclip/helpers.rb +60 -0
  56. data/lib/paperclip/interpolations.rb +201 -0
  57. data/lib/paperclip/interpolations/plural_cache.rb +18 -0
  58. data/lib/paperclip/io_adapters/abstract_adapter.rb +75 -0
  59. data/lib/paperclip/io_adapters/attachment_adapter.rb +47 -0
  60. data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
  61. data/lib/paperclip/io_adapters/empty_string_adapter.rb +19 -0
  62. data/lib/paperclip/io_adapters/file_adapter.rb +26 -0
  63. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +16 -0
  64. data/lib/paperclip/io_adapters/identity_adapter.rb +17 -0
  65. data/lib/paperclip/io_adapters/nil_adapter.rb +37 -0
  66. data/lib/paperclip/io_adapters/registry.rb +36 -0
  67. data/lib/paperclip/io_adapters/stringio_adapter.rb +36 -0
  68. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +44 -0
  69. data/lib/paperclip/io_adapters/uri_adapter.rb +68 -0
  70. data/lib/paperclip/locales/en.yml +18 -0
  71. data/lib/paperclip/logger.rb +21 -0
  72. data/lib/paperclip/matchers.rb +64 -0
  73. data/lib/paperclip/matchers/have_attached_file_matcher.rb +54 -0
  74. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +101 -0
  75. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +59 -0
  76. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +97 -0
  77. data/lib/paperclip/media_type_spoof_detector.rb +90 -0
  78. data/lib/paperclip/missing_attachment_styles.rb +84 -0
  79. data/lib/paperclip/processor.rb +56 -0
  80. data/lib/paperclip/processor_helpers.rb +52 -0
  81. data/lib/paperclip/rails_environment.rb +21 -0
  82. data/lib/paperclip/railtie.rb +31 -0
  83. data/lib/paperclip/schema.rb +81 -0
  84. data/lib/paperclip/storage.rb +3 -0
  85. data/lib/paperclip/storage/filesystem.rb +99 -0
  86. data/lib/paperclip/storage/fog.rb +252 -0
  87. data/lib/paperclip/storage/s3.rb +461 -0
  88. data/lib/paperclip/style.rb +106 -0
  89. data/lib/paperclip/tempfile.rb +42 -0
  90. data/lib/paperclip/tempfile_factory.rb +22 -0
  91. data/lib/paperclip/thumbnail.rb +131 -0
  92. data/lib/paperclip/url_generator.rb +76 -0
  93. data/lib/paperclip/validators.rb +73 -0
  94. data/lib/paperclip/validators/attachment_content_type_validator.rb +88 -0
  95. data/lib/paperclip/validators/attachment_file_name_validator.rb +75 -0
  96. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +28 -0
  97. data/lib/paperclip/validators/attachment_presence_validator.rb +28 -0
  98. data/lib/paperclip/validators/attachment_size_validator.rb +109 -0
  99. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +29 -0
  100. data/lib/paperclip/version.rb +3 -0
  101. data/lib/tasks/paperclip.rake +140 -0
  102. data/paperclip.gemspec +50 -0
  103. data/shoulda_macros/paperclip.rb +134 -0
  104. data/spec/database.yml +4 -0
  105. data/spec/paperclip/attachment_definitions_spec.rb +13 -0
  106. data/spec/paperclip/attachment_processing_spec.rb +79 -0
  107. data/spec/paperclip/attachment_registry_spec.rb +158 -0
  108. data/spec/paperclip/attachment_spec.rb +1590 -0
  109. data/spec/paperclip/content_type_detector_spec.rb +47 -0
  110. data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
  111. data/spec/paperclip/filename_cleaner_spec.rb +13 -0
  112. data/spec/paperclip/geometry_detector_spec.rb +38 -0
  113. data/spec/paperclip/geometry_parser_spec.rb +73 -0
  114. data/spec/paperclip/geometry_spec.rb +255 -0
  115. data/spec/paperclip/glue_spec.rb +42 -0
  116. data/spec/paperclip/has_attached_file_spec.rb +78 -0
  117. data/spec/paperclip/integration_spec.rb +702 -0
  118. data/spec/paperclip/interpolations_spec.rb +270 -0
  119. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +160 -0
  120. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +140 -0
  121. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +88 -0
  122. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
  123. data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
  124. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +137 -0
  125. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
  126. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +25 -0
  127. data/spec/paperclip/io_adapters/registry_spec.rb +35 -0
  128. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
  129. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
  130. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +221 -0
  131. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
  132. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +108 -0
  133. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
  134. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
  135. data/spec/paperclip/media_type_spoof_detector_spec.rb +120 -0
  136. data/spec/paperclip/meta_class_spec.rb +30 -0
  137. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +88 -0
  138. data/spec/paperclip/paperclip_spec.rb +196 -0
  139. data/spec/paperclip/plural_cache_spec.rb +37 -0
  140. data/spec/paperclip/processor_helpers_spec.rb +57 -0
  141. data/spec/paperclip/processor_spec.rb +26 -0
  142. data/spec/paperclip/rails_environment_spec.rb +30 -0
  143. data/spec/paperclip/rake_spec.rb +103 -0
  144. data/spec/paperclip/schema_spec.rb +252 -0
  145. data/spec/paperclip/storage/filesystem_spec.rb +79 -0
  146. data/spec/paperclip/storage/fog_spec.rb +560 -0
  147. data/spec/paperclip/storage/s3_live_spec.rb +188 -0
  148. data/spec/paperclip/storage/s3_spec.rb +1695 -0
  149. data/spec/paperclip/style_spec.rb +251 -0
  150. data/spec/paperclip/tempfile_factory_spec.rb +33 -0
  151. data/spec/paperclip/tempfile_spec.rb +35 -0
  152. data/spec/paperclip/thumbnail_spec.rb +504 -0
  153. data/spec/paperclip/url_generator_spec.rb +221 -0
  154. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
  155. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +159 -0
  156. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +85 -0
  157. data/spec/paperclip/validators/attachment_size_validator_spec.rb +235 -0
  158. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +48 -0
  159. data/spec/paperclip/validators_spec.rb +164 -0
  160. data/spec/spec_helper.rb +45 -0
  161. data/spec/support/assertions.rb +84 -0
  162. data/spec/support/fake_model.rb +24 -0
  163. data/spec/support/fake_rails.rb +12 -0
  164. data/spec/support/fixtures/12k.png +0 -0
  165. data/spec/support/fixtures/50x50.png +0 -0
  166. data/spec/support/fixtures/5k.png +0 -0
  167. data/spec/support/fixtures/animated +0 -0
  168. data/spec/support/fixtures/animated.gif +0 -0
  169. data/spec/support/fixtures/animated.unknown +0 -0
  170. data/spec/support/fixtures/bad.png +1 -0
  171. data/spec/support/fixtures/empty.html +1 -0
  172. data/spec/support/fixtures/empty.xlsx +0 -0
  173. data/spec/support/fixtures/fog.yml +8 -0
  174. data/spec/support/fixtures/rotated.jpg +0 -0
  175. data/spec/support/fixtures/s3.yml +8 -0
  176. data/spec/support/fixtures/spaced file.jpg +0 -0
  177. data/spec/support/fixtures/spaced file.png +0 -0
  178. data/spec/support/fixtures/text.txt +1 -0
  179. data/spec/support/fixtures/twopage.pdf +0 -0
  180. data/spec/support/fixtures/uppercase.PNG +0 -0
  181. data/spec/support/matchers/accept.rb +5 -0
  182. data/spec/support/matchers/exist.rb +5 -0
  183. data/spec/support/matchers/have_column.rb +23 -0
  184. data/spec/support/mock_attachment.rb +24 -0
  185. data/spec/support/mock_interpolator.rb +24 -0
  186. data/spec/support/mock_url_generator_builder.rb +26 -0
  187. data/spec/support/model_reconstruction.rb +72 -0
  188. data/spec/support/reporting.rb +11 -0
  189. data/spec/support/test_data.rb +13 -0
  190. data/spec/support/version_helper.rb +9 -0
  191. metadata +586 -0
@@ -0,0 +1,17 @@
1
+ Releasing paperclip
2
+
3
+ 1. Update `lib/paperclip/version.rb` file accordingly.
4
+ 2. Update `NEWS` to reflect the changes since last release.
5
+ 3. Commit changes. There shouldn’t be code changes, and thus CI doesn’t need to
6
+ run, you can then add “[ci skip]” to the commit message.
7
+ 4. Tag the release: `git tag -m 'vVERSION' vVERSION`
8
+ 5. Push changes: `git push --tags`
9
+ 6. Build and publish the gem:
10
+
11
+ ```bash
12
+ gem build paperclip.gemspec
13
+ gem push paperclip-VERSION.gem
14
+ ```
15
+
16
+ 7. Announce the new release, making sure to say “thank you” to the contributors
17
+ who helped shape this version.
@@ -0,0 +1,52 @@
1
+ require "bundler/gem_tasks"
2
+ require "appraisal"
3
+ require "rspec/core/rake_task"
4
+ require "cucumber/rake/task"
5
+
6
+ desc "Default: run unit tests."
7
+ task default: [:clean, :all]
8
+
9
+ desc "Test the paperclip plugin under all supported Rails versions."
10
+ task :all do |_t|
11
+ if ENV["BUNDLE_GEMFILE"]
12
+ exec("rake spec && cucumber")
13
+ else
14
+ exec("rm -f gemfiles/*.lock")
15
+ Rake::Task["appraisal:gemfiles"].execute
16
+ Rake::Task["appraisal:install"].execute
17
+ exec("rake appraisal")
18
+ end
19
+ end
20
+
21
+ desc "Test the paperclip plugin."
22
+ RSpec::Core::RakeTask.new(:spec)
23
+
24
+ desc "Run integration test"
25
+ Cucumber::Rake::Task.new do |t|
26
+ t.cucumber_opts = %w{--format progress}
27
+ end
28
+
29
+ desc "Start an IRB session with all necessary files required."
30
+ task :shell do |_t|
31
+ chdir File.dirname(__FILE__)
32
+ exec "irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init"
33
+ end
34
+
35
+ desc "Clean up files."
36
+ task :clean do |_t|
37
+ FileUtils.rm_rf "doc"
38
+ FileUtils.rm_rf "tmp"
39
+ FileUtils.rm_rf "pkg"
40
+ FileUtils.rm_rf "public"
41
+ begin
42
+ FileUtils.rm "test/debug.log"
43
+ rescue StandardError
44
+ nil
45
+ end
46
+ begin
47
+ FileUtils.rm "test/paperclip.db"
48
+ rescue StandardError
49
+ nil
50
+ end
51
+ Dir.glob("paperclip-*.gem").each { |f| FileUtils.rm f }
52
+ end
@@ -0,0 +1,17 @@
1
+ ##################################################
2
+ # NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
3
+ ##################################################
4
+
5
+ Paperclip is now compatible with aws-sdk-s3.
6
+
7
+ If you are using S3 storage, aws-sdk-s3 requires you to make a few small
8
+ changes:
9
+
10
+ * You must set the `s3_region`
11
+ * If you are explicitly setting permissions anywhere, such as in an initializer,
12
+ note that the format of the permissions changed from using an underscore to
13
+ using a hyphen. For example, `:public_read` needs to be changed to
14
+ `public-read`.
15
+
16
+ For a walkthrough of upgrading from 4 to *5* (not 6) and aws-sdk >= 2.0 you can watch
17
+ http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
@@ -0,0 +1,85 @@
1
+ Feature: Rails integration
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I run a rails generator to generate a "User" scaffold with "name:string"
6
+ And I run a paperclip generator to add a paperclip "attachment" to the "User" model
7
+ And I run a migration
8
+ And I update my new user view to include the file upload field
9
+ And I update my user view to include the attachment
10
+ And I allow the attachment to be submitted
11
+ And I replace this snippet to app/views/layouts/application.html.erb:
12
+ """
13
+ <%= javascript_tag 'application', 'data-turbolinks-track': 'reload' %>
14
+ """
15
+
16
+ Scenario: Configure defaults for all attachments through Railtie
17
+ Given I add this snippet to config/application.rb:
18
+ """
19
+ config.paperclip_defaults = {
20
+ :url => "/paperclip/custom/:attachment/:style/:filename",
21
+ :validate_media_type => false
22
+ }
23
+ """
24
+ And I attach :attachment
25
+ And I start the rails application
26
+ When I go to the new user page
27
+ And I fill in "Name" with "something"
28
+ And I attach the file "spec/support/fixtures/animated.unknown" to "Attachment"
29
+ And I press "Submit"
30
+ Then I should see "Name: something"
31
+ And I should see an image with a path of "/paperclip/custom/attachments/original/animated.unknown"
32
+ And the file at "/paperclip/custom/attachments/original/animated.unknown" should be the same as "spec/support/fixtures/animated.unknown"
33
+
34
+ Scenario: Add custom processors
35
+ Given I add a "test" processor in "lib/paperclip"
36
+ And I add a "cool" processor in "lib/paperclip_processors"
37
+ And I attach :attachment with:
38
+ """
39
+ styles: { original: {} }, processors: [:test, :cool]
40
+ """
41
+ And I start the rails application
42
+ When I go to the new user page
43
+ And I fill in "Name" with "something"
44
+ And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
45
+ And I press "Submit"
46
+ Then I should see "Name: something"
47
+ And I should see an image with a path of "/paperclip/custom/attachments/original/5k.png"
48
+
49
+ Scenario: Filesystem integration test
50
+ Given I attach :attachment with:
51
+ """
52
+ :url => "/system/:attachment/:style/:filename"
53
+ """
54
+ And I start the rails application
55
+ When I go to the new user page
56
+ And I fill in "Name" with "something"
57
+ And I attach the file "spec/support/fixtures/5k.png" to "Attachment"
58
+ And I press "Submit"
59
+ Then I should see "Name: something"
60
+ And I should see an image with a path of "/system/attachments/original/5k.png"
61
+ And the file at "/system/attachments/original/5k.png" should be the same as "spec/support/fixtures/5k.png"
62
+
63
+ Scenario: S3 Integration test
64
+ Given I attach :attachment with:
65
+ """
66
+ :storage => :s3,
67
+ :path => "/:attachment/:style/:filename",
68
+ :s3_credentials => Rails.root.join("config/s3.yml"),
69
+ :styles => { :square => "100x100#" }
70
+ """
71
+ And I write to "config/s3.yml" with:
72
+ """
73
+ bucket: paperclip
74
+ access_key_id: access_key
75
+ secret_access_key: secret_key
76
+ s3_region: us-west-2
77
+ """
78
+ And I start the rails application
79
+ When I go to the new user page
80
+ And I fill in "Name" with "something"
81
+ And I attach the file "spec/support/fixtures/5k.png" to "Attachment" on S3
82
+ And I press "Submit"
83
+ Then I should see "Name: something"
84
+ And I should see an image with a path of "//s3.amazonaws.com/paperclip/attachments/original/5k.png"
85
+ And the file at "//s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
@@ -0,0 +1,29 @@
1
+ Feature: Migration
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I generate a "User" model:
6
+
7
+ Scenario: Vintage syntax
8
+ Given I run a paperclip migration to add a paperclip "attach" to the "User" model
9
+
10
+ And I run a migration
11
+ Then I should have attachment columns for "attach"
12
+
13
+ When I rollback a migration
14
+ Then I should not have attachment columns for "attach"
15
+
16
+ Scenario: New syntax with create_table
17
+ Given I run a paperclip migration to add a paperclip "attach" to the "User" model
18
+
19
+ And I run a migration
20
+ Then I should have attachment columns for "attach"
21
+
22
+ Scenario: New syntax outside of create_table
23
+ Given I run a paperclip migration to add a paperclip "attachment_sample" to the "User" model
24
+
25
+ And I run a migration
26
+ Then I should have attachment columns for "attachment_sample"
27
+
28
+ When I rollback a migration
29
+ Then I should not have attachment columns for "attachment_sample"
@@ -0,0 +1,62 @@
1
+ Feature: Rake tasks
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I run a rails generator to generate a "User" scaffold with "name:string"
6
+ And I run a paperclip generator to add a paperclip "attachment" to the "User" model
7
+ And I run a migration
8
+ And I attach :attachment with:
9
+ """
10
+ :path => ":rails_root/public/system/:attachment/:style/:filename"
11
+ """
12
+
13
+ Scenario: Paperclip refresh thumbnails task
14
+ When I modify my attachment definition to:
15
+ """
16
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
17
+ :styles => { :medium => "200x200#" }
18
+ """
19
+ And I upload the fixture "5k.png"
20
+ Then the attachment "medium/5k.png" should have a dimension of 200x200
21
+ When I modify my attachment definition to:
22
+ """
23
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
24
+ :styles => { :medium => "100x100#" }
25
+ """
26
+ When I successfully run `bundle exec rake paperclip:refresh:thumbnails CLASS=User --trace`
27
+ Then the attachment "original/5k.png" should exist
28
+ And the attachment "medium/5k.png" should have a dimension of 100x100
29
+
30
+ Scenario: Paperclip refresh metadata task
31
+ When I upload the fixture "5k.png"
32
+ And I swap the attachment "original/5k.png" with the fixture "12k.png"
33
+ And I successfully run `bundle exec rake paperclip:refresh:metadata CLASS=User --trace`
34
+ Then the attachment should have the same content type as the fixture "12k.png"
35
+ And the attachment should have the same file size as the fixture "12k.png"
36
+
37
+ Scenario: Paperclip refresh missing styles task
38
+ When I upload the fixture "5k.png"
39
+ Then the attachment file "original/5k.png" should exist
40
+ And the attachment file "medium/5k.png" should not exist
41
+ When I modify my attachment definition to:
42
+ """
43
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
44
+ :styles => { :medium => "200x200#" }
45
+ """
46
+ When I successfully run `bundle exec rake paperclip:refresh:missing_styles --trace`
47
+ Then the attachment file "original/5k.png" should exist
48
+ And the attachment file "medium/5k.png" should exist
49
+
50
+ Scenario: Paperclip clean task
51
+ When I upload the fixture "5k.png"
52
+ And I upload the fixture "12k.png"
53
+ Then the attachment file "original/5k.png" should exist
54
+ And the attachment file "original/12k.png" should exist
55
+ When I modify my attachment definition to:
56
+ """
57
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
58
+ validates_attachment_size :attachment, :less_than => 10.kilobytes
59
+ """
60
+ And I successfully run `bundle exec rake paperclip:clean CLASS=User --trace`
61
+ Then the attachment file "original/5k.png" should exist
62
+ But the attachment file "original/12k.png" should not exist
@@ -0,0 +1,110 @@
1
+ module AttachmentHelpers
2
+ def fixture_path(filename)
3
+ File.expand_path("#{PROJECT_ROOT}/spec/support/fixtures/#{filename}")
4
+ end
5
+
6
+ def attachment_path(filename)
7
+ File.expand_path("public/system/attachments/#{filename}")
8
+ end
9
+ end
10
+ World(AttachmentHelpers)
11
+
12
+ When /^I modify my attachment definition to:$/ do |definition|
13
+ content = cd(".") { File.read("app/models/user.rb") }
14
+ name = content[/has_attached_file :\w+/][/:\w+/]
15
+ content.gsub!(/has_attached_file.+end/m, <<-FILE)
16
+ #{definition}
17
+ do_not_validate_attachment_file_type #{name}
18
+ end
19
+ FILE
20
+
21
+ write_file "app/models/user.rb", content
22
+ cd(".") { FileUtils.rm_rf ".rbx" }
23
+ end
24
+
25
+ When /^I upload the fixture "([^"]*)"$/ do |filename|
26
+ run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
27
+ end
28
+
29
+ Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
30
+ cd(".") do
31
+ geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
32
+ expect(geometry).to eq(dimension)
33
+ end
34
+ end
35
+
36
+ Then /^the attachment "([^"]*)" should exist$/ do |filename|
37
+ cd(".") do
38
+ expect(File.exist?(attachment_path(filename))).to be true
39
+ end
40
+ end
41
+
42
+ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
43
+ cd(".") do
44
+ require "fileutils"
45
+ FileUtils.rm_f attachment_path(attachment_filename)
46
+ FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
47
+ end
48
+ end
49
+
50
+ Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
51
+ cd(".") do
52
+ begin
53
+ # Use mime/types/columnar if available, for reduced memory usage
54
+ require "mime/types/columnar"
55
+ rescue LoadError
56
+ require "mime/types"
57
+ end
58
+
59
+ attachment_content_type = `bundle exec rails runner "puts User.last.attachment_content_type"`.strip
60
+ expected = MIME::Types.type_for(filename).first.content_type
61
+ expect(attachment_content_type).to eq(expected)
62
+ end
63
+ end
64
+
65
+ Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
66
+ cd(".") do
67
+ attachment_file_name = `bundle exec rails runner "puts User.last.attachment_file_name"`.strip
68
+ expect(attachment_file_name).to eq(File.name(fixture_path(filename)).to_s)
69
+ end
70
+ end
71
+
72
+ Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
73
+ cd(".") do
74
+ attachment_file_size = `bundle exec rails runner "puts User.last.attachment_file_size"`.strip
75
+ expect(attachment_file_size).to eq(File.size(fixture_path(filename)).to_s)
76
+ end
77
+ end
78
+
79
+ Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, _not_exist|
80
+ cd(".") do
81
+ expect(attachment_path(filename)).not_to be_an_existing_file
82
+ end
83
+ end
84
+
85
+ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
86
+ cd(".") do
87
+ columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.sql_type] }.inspect"`.strip)
88
+ expect_columns = [
89
+ ["#{attachment_name}_file_name", "varchar"],
90
+ ["#{attachment_name}_content_type", "varchar"],
91
+ ["#{attachment_name}_file_size", "bigint"],
92
+ ["#{attachment_name}_updated_at", "datetime"]
93
+ ]
94
+ expect(columns).to include(*expect_columns)
95
+ end
96
+ end
97
+
98
+ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
99
+ cd(".") do
100
+ columns = eval(`bundle exec rails runner "puts User.columns.map{ |column| [column.name, column.sql_type] }.inspect"`.strip)
101
+ expect_columns = [
102
+ ["#{attachment_name}_file_name", "varchar"],
103
+ ["#{attachment_name}_content_type", "varchar"],
104
+ ["#{attachment_name}_file_size", "bigint"],
105
+ ["#{attachment_name}_updated_at", "datetime"]
106
+ ]
107
+
108
+ expect(columns).not_to include(*expect_columns)
109
+ end
110
+ end
@@ -0,0 +1,15 @@
1
+ Then %r{I should see an image with a path of "([^"]*)"} do |path|
2
+ expect(page).to have_css("img[src^='#{path}']")
3
+ end
4
+
5
+ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
6
+ expected = IO.read(path)
7
+ actual = if web_file.match %r{^https?://}
8
+ Net::HTTP.get(URI.parse(web_file))
9
+ else
10
+ visit(web_file)
11
+ page.body
12
+ end
13
+ actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
14
+ expect(actual).to eq(expected)
15
+ end
@@ -0,0 +1,257 @@
1
+ Given /^I generate a new rails application$/ do
2
+ steps %{
3
+ When I successfully run `rails new #{APP_NAME} --skip-bundle`
4
+ And I cd to "#{APP_NAME}"
5
+ }
6
+
7
+ FileUtils.chdir("tmp/aruba/testapp/")
8
+
9
+ steps %{
10
+ And I turn off class caching
11
+ And I write to "Gemfile" with:
12
+ """
13
+ source "http://rubygems.org"
14
+ gem "rails", "#{framework_version}"
15
+ gem "sqlite3", :platform => [:ruby, :rbx]
16
+ gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
17
+ gem "jruby-openssl", :platform => :jruby
18
+ gem "capybara"
19
+ gem "gherkin"
20
+ gem "aws-sdk-s3"
21
+ gem "racc", :platform => :rbx
22
+ gem "rubysl", :platform => :rbx
23
+ """
24
+ And I remove turbolinks
25
+ And I comment out lines that contain "action_mailer" in "config/environments/*.rb"
26
+ And I empty the application.js file
27
+ And I configure the application to use "paperclip" from this project
28
+ }
29
+
30
+ FileUtils.chdir("../../..")
31
+ end
32
+
33
+ Given /^I generate a "([^"]*)" model:$/ do |model_name|
34
+ step %[I successfully run `rails generate model #{model_name}`]
35
+ end
36
+
37
+ Given /^I run a paperclip migration to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
38
+ step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
39
+ end
40
+
41
+ Given "I allow the attachment to be submitted" do
42
+ cd(".") do
43
+ transform_file("app/controllers/users_controller.rb") do |content|
44
+ content.gsub("params.require(:user).permit(:name)",
45
+ "params.require(:user).permit!")
46
+ end
47
+ end
48
+ end
49
+
50
+ Given "I remove turbolinks" do
51
+ cd(".") do
52
+ transform_file("app/assets/javascripts/application.js") do |content|
53
+ content.gsub("//= require turbolinks", "")
54
+ end
55
+ transform_file("app/views/layouts/application.html.erb") do |content|
56
+ content.gsub(', "data-turbolinks-track" => true', "")
57
+ end
58
+ end
59
+ end
60
+
61
+ Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
62
+ cd(".") do
63
+ Dir.glob(glob).each do |file|
64
+ transform_file(file) do |content|
65
+ content.gsub(/^(.*?#{contains}.*?)$/) { |line| "# #{line}" }
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ Given /^I attach :attachment$/ do
72
+ attach_attachment("attachment")
73
+ end
74
+
75
+ Given /^I attach :attachment with:$/ do |definition|
76
+ attach_attachment("attachment", definition)
77
+ end
78
+
79
+ def attach_attachment(name, definition = nil)
80
+ snippet = "has_attached_file :#{name}"
81
+ if definition
82
+ snippet += ", \n"
83
+ snippet += definition
84
+ end
85
+ snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
86
+ cd(".") do
87
+ transform_file("app/models/user.rb") do |content|
88
+ content.sub(/end\Z/, "#{snippet}\nend")
89
+ end
90
+ end
91
+ end
92
+
93
+ Given "I empty the application.js file" do
94
+ cd(".") do
95
+ transform_file("app/assets/javascripts/application.js") do |_content|
96
+ ""
97
+ end
98
+ end
99
+ end
100
+
101
+ Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
102
+ step %[I successfully run `rails generate scaffold #{model_name} #{attributes}`]
103
+ end
104
+
105
+ Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
106
+ step %[I successfully run `rails generate paperclip #{model_name} #{attachment_name}`]
107
+ end
108
+
109
+ Given /^I run a migration$/ do
110
+ step %[I successfully run `rake db:migrate --trace`]
111
+ end
112
+
113
+ When /^I rollback a migration$/ do
114
+ step %[I successfully run `rake db:rollback STEPS=1 --trace`]
115
+ end
116
+
117
+ Given /^I update my new user view to include the file upload field$/ do
118
+ steps %{
119
+ Given I overwrite "app/views/users/new.html.erb" with:
120
+ """
121
+ <%= form_for @user, :html => { :multipart => true } do |f| %>
122
+ <%= f.label :name %>
123
+ <%= f.text_field :name %>
124
+ <%= f.label :attachment %>
125
+ <%= f.file_field :attachment %>
126
+ <%= submit_tag "Submit" %>
127
+ <% end %>
128
+ """
129
+ }
130
+ end
131
+
132
+ Given /^I update my user view to include the attachment$/ do
133
+ steps %{
134
+ Given I overwrite "app/views/users/show.html.erb" with:
135
+ """
136
+ <p>Name: <%= @user.name %></p>
137
+ <p>Attachment: <%= image_tag @user.attachment.url %></p>
138
+ """
139
+ }
140
+ end
141
+
142
+ Given /^I add this snippet to the User model:$/ do |snippet|
143
+ file_name = "app/models/user.rb"
144
+ cd(".") do
145
+ content = File.read(file_name)
146
+ File.open(file_name, "w") { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
147
+ end
148
+ end
149
+
150
+ Given /^I add this snippet to config\/application.rb:$/ do |snippet|
151
+ file_name = "config/application.rb"
152
+ cd(".") do
153
+ content = File.read(file_name)
154
+ File.open(file_name, "w") do |f|
155
+ f << content.sub(/class Application < Rails::Application.*$/,
156
+ "class Application < Rails::Application\n#{snippet}\n")
157
+ end
158
+ end
159
+ end
160
+
161
+ Given /^I replace this snippet to app\/views\/layouts\/application.html.erb:$/ do |snippet|
162
+ file_name = "app/views/layouts/application.html.erb"
163
+ cd(".") do
164
+ content = File.read(file_name)
165
+ File.open(file_name, "w") do |f|
166
+ f << content.sub(/<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>$/,
167
+ "#{snippet}")
168
+ end
169
+ end
170
+ end
171
+
172
+ Given /^I start the rails application$/ do
173
+ cd(".") do
174
+ require "rails"
175
+ require "./config/environment"
176
+ require "capybara"
177
+ Capybara.app = Rails.application
178
+ end
179
+ end
180
+
181
+ Given /^I reload my application$/ do
182
+ Rails::Application.reload!
183
+ end
184
+
185
+ When /^I turn off class caching$/ do
186
+ cd(".") do
187
+ file = "config/environments/test.rb"
188
+ config = IO.read(file)
189
+ config.gsub!(%r{^\s*config.cache_classes.*$},
190
+ "config.cache_classes = false")
191
+ File.open(file, "w") { |f| f.write(config) }
192
+ end
193
+ end
194
+
195
+ Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
196
+ expected = IO.read(path)
197
+ actual = read_from_web(web_file)
198
+ expect(actual).to eq(expected)
199
+ end
200
+
201
+ When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
202
+ append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
203
+ steps %{And I successfully run `bundle install --local`}
204
+ end
205
+
206
+ When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
207
+ append_to_gemfile "gem '#{gem_name}'"
208
+ end
209
+
210
+ When /^I append gems from Appraisal Gemfile$/ do
211
+ File.read(ENV["BUNDLE_GEMFILE"]).split(/\n/).each do |line|
212
+ append_to_gemfile line.strip if line =~ /^gem "(?!rails|appraisal)/
213
+ end
214
+ end
215
+
216
+ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
217
+ comment_out_gem_in_gemfile gemname
218
+ end
219
+
220
+ Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
221
+ filename = "#{directory}/#{processor}.rb"
222
+ cd(".") do
223
+ FileUtils.mkdir_p directory
224
+ File.open(filename, "w") do |f|
225
+ f.write(<<-CLASS)
226
+ module Paperclip
227
+ class #{processor.capitalize} < Processor
228
+ def make
229
+ basename = File.basename(file.path, File.extname(file.path))
230
+ dst_format = options[:format] ? ".\#{options[:format]}" : ''
231
+
232
+ dst = Tempfile.new([basename, dst_format])
233
+ dst.binmode
234
+
235
+ convert(':src :dst',
236
+ src: File.expand_path(file.path),
237
+ dst: File.expand_path(dst.path)
238
+ )
239
+
240
+ dst
241
+ end
242
+ end
243
+ end
244
+ CLASS
245
+ end
246
+ end
247
+ end
248
+
249
+ def transform_file(filename)
250
+ if File.exist?(filename)
251
+ content = File.read(filename)
252
+ File.open(filename, "w") do |f|
253
+ content = yield(content)
254
+ f.write(content)
255
+ end
256
+ end
257
+ end