kt-paperclip 6.2.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1050
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +12 -14
  9. data/Appraisals +6 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +5 -4
  12. data/NEWS +31 -0
  13. data/README.md +41 -19
  14. data/features/step_definitions/attachment_steps.rb +11 -1
  15. data/gemfiles/4.2.gemfile +1 -1
  16. data/gemfiles/5.0.gemfile +1 -1
  17. data/gemfiles/5.1.gemfile +1 -1
  18. data/gemfiles/5.2.gemfile +1 -1
  19. data/gemfiles/6.0.gemfile +1 -1
  20. data/gemfiles/6.1.gemfile +21 -0
  21. data/gemfiles/7.0.gemfile +21 -0
  22. data/lib/kt-paperclip.rb +1 -0
  23. data/lib/paperclip/attachment.rb +1 -1
  24. data/lib/paperclip/content_type_detector.rb +10 -5
  25. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
  26. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  27. data/lib/paperclip/schema.rb +2 -2
  28. data/lib/paperclip/storage/filesystem.rb +1 -1
  29. data/lib/paperclip/storage/fog.rb +1 -1
  30. data/lib/paperclip/storage/s3.rb +3 -3
  31. data/lib/paperclip/url_generator.rb +8 -1
  32. data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
  33. data/lib/paperclip/validators/attachment_file_name_validator.rb +10 -3
  34. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  35. data/lib/paperclip/validators/attachment_size_validator.rb +21 -4
  36. data/lib/paperclip/validators.rb +4 -4
  37. data/lib/paperclip/version.rb +1 -1
  38. data/lib/paperclip.rb +3 -3
  39. data/paperclip.gemspec +4 -4
  40. data/spec/paperclip/content_type_detector_spec.rb +7 -0
  41. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  42. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  43. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
  44. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  45. data/spec/paperclip/storage/filesystem_spec.rb +23 -0
  46. data/spec/paperclip/storage/fog_spec.rb +46 -0
  47. data/spec/paperclip/storage/s3_spec.rb +67 -3
  48. data/spec/paperclip/url_generator_spec.rb +10 -0
  49. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
  50. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
  51. data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
  52. data/spec/paperclip/validators_spec.rb +21 -6
  53. data/spec/support/fixtures/aws_s3.yml +13 -0
  54. data/spec/support/fixtures/sample.xlsm +0 -0
  55. data/spec/support/model_reconstruction.rb +1 -1
  56. metadata +20 -12
  57. data/.github/issue_template.md +0 -3
data/.travis.yml CHANGED
@@ -1,12 +1,11 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1
5
- - 2.2
6
4
  - 2.3
7
5
  - 2.4
8
6
  - 2.5
9
7
  - 2.6
8
+ - 2.7
10
9
 
11
10
  script: "bundle exec rake clean spec cucumber"
12
11
 
@@ -25,23 +24,22 @@ gemfile:
25
24
  - gemfiles/5.1.gemfile
26
25
  - gemfiles/5.2.gemfile
27
26
  - gemfiles/6.0.gemfile
27
+ - gemfiles/6.1.gemfile
28
28
 
29
29
  matrix:
30
30
  fast_finish: true
31
31
  exclude:
32
- - gemfile: gemfiles/5.0.gemfile
33
- rvm: 2.1
34
- - gemfile: gemfiles/5.1.gemfile
35
- rvm: 2.1
36
- - gemfile: gemfiles/5.2.gemfile
37
- rvm: 2.1
38
- - gemfile: gemfiles/5.2.gemfile
39
- rvm: 2.2
40
- - gemfile: gemfiles/6.0.gemfile
41
- rvm: 2.1
42
- - gemfile: gemfiles/6.0.gemfile
43
- rvm: 2.2
44
32
  - gemfile: gemfiles/6.0.gemfile
45
33
  rvm: 2.3
46
34
  - gemfile: gemfiles/6.0.gemfile
47
35
  rvm: 2.4
36
+ - gemfile: gemfiles/6.1.gemfile
37
+ rvm: 2.3
38
+ - gemfile: gemfiles/6.1.gemfile
39
+ rvm: 2.4
40
+ - gemfile: gemfiles/4.2.gemfile
41
+ rvm: 2.7
42
+ - gemfile: gemfiles/5.0.gemfile
43
+ rvm: 2.7
44
+ - gemfile: gemfiles/5.1.gemfile
45
+ rvm: 2.7
data/Appraisals CHANGED
@@ -22,3 +22,9 @@ appraise "6.0" do
22
22
  gem "sqlite3", "~> 1.4", platforms: :ruby
23
23
  gem "rails", "~> 6.0.0"
24
24
  end
25
+
26
+ appraise "6.1" do
27
+ gem "sqlite3", "~> 1.4", platforms: :ruby
28
+ gem "aruba", "~> 1.0", ">= 1.0.4"
29
+ gem "rails", "~> 6.1", ">= 6.1.1"
30
+ end
data/CONTRIBUTING.md CHANGED
@@ -10,8 +10,7 @@ Here's a quick guide for contributing:
10
10
 
11
11
  1. Fork the repo.
12
12
 
13
- 1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
14
- (./README.md#image-processor) of the README.
13
+ 1. Make sure you have ImageMagick and Ghostscript installed. See [this section](./README.md#image-processor) of the README.
15
14
 
16
15
  1. Run the tests. We only take pull requests with passing tests, and it's great
17
16
  to know that you have a clean slate: `bundle && bundle exec rake`
@@ -78,9 +77,9 @@ Syntax
78
77
 
79
78
  * Two spaces, no tabs.
80
79
  * No trailing whitespace. Blank lines should not have any space.
81
- * Prefer &&/|| over and/or.
82
- * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
83
- * a = b and not a=b.
80
+ * Prefer `&&` instead of `and` ; prefer `||` instead of `or`.
81
+ * Use `MyClass.my_method(my_arg)` instead of `MyClass.my_method( my_arg )` or `MyClass.my_method my_arg`.
82
+ * `a = b` rather than `a=b` .
84
83
  * Follow the conventions you see used in the source already.
85
84
 
86
85
  And in case we didn't emphasize it enough: we love tests!
data/Gemfile CHANGED
@@ -8,11 +8,12 @@ gem "pry"
8
8
  # Prevents bundler from taking a long-time to resolve
9
9
  group :development, :test do
10
10
  gem "activerecord-import"
11
- gem 'bootsnap', require: false
11
+ gem "bootsnap", require: false
12
12
  gem "builder"
13
- gem 'listen', '~> 3.0.8'
14
- gem "mime-types"
13
+ gem "listen", "~> 3.0.8"
15
14
  gem "rspec"
16
- gem "rubocop", require: false
15
+ # Hound only supports certain versions of Rubocop -- 1.22.1 is currently the most recent one supported.
16
+ gem "rubocop", "1.22.1", require: false
17
+ gem "rubocop-rails"
17
18
  gem "sprockets", "3.7.2"
18
19
  end
data/NEWS CHANGED
@@ -1,3 +1,34 @@
1
+ [UNRELEASED]
2
+ Issue file delete only once per unique style when nullifying attachment or destroying an object. Avoids triggering a rate limit error on Google Cloud Storage.
3
+
4
+ 7.0.0 (2021-05-28)
5
+ * Replace `mimemagic` gem with `marcel` due to licensing issues. See https://github.com/kreeti/kt-paperclip/pull/54 for details and limitations
6
+
7
+ 6.4.1 (2021-01-30)
8
+ * Improvement: Use URI.open in ruby > 2.5 (PR #45)
9
+
10
+ 6.4.0 (2020-12-14)
11
+ * Improvement: Fix Ruby 2.7 method & syntax deprecation warnings (#38)
12
+
13
+ 6.3.0 (2020-08-10)
14
+ * Feature: Add validation_errors_to option - customize copying of errors (#26)
15
+ * Stability: Dropped support for ruby 2.1
16
+
17
+ 6.2.2 (2020-02-18)
18
+ * Bugfix: Add support for Aliases in S3 credentials YAML (accidentally removed during 6.2.0 upgrade).
19
+
20
+ 6.2.1 (2020-01-30)
21
+
22
+ * Bugfix: Auto-loading of the gem code (necessitated due to change in gem name).
23
+
24
+ 6.2.0 (2020-01-23):
25
+
26
+ * Bugfix: Don't do post-processing on invalid attachments (#16).
27
+ * Improvement: Use AWS::S3 built in download_file method (#9).
28
+ * Stability: Rubocop recommended syntax updates (#10, #11, #13, #14).
29
+ * Stability: Testing - replace mocha and bourne with rspec mocks (#6).
30
+ * Stability: Fix test suite to run with Rails 5 and Rails 6 (#19, #20, #7).
31
+
1
32
  6.1.0 (2018-07-27):
2
33
 
3
34
  * BUGFIX: Don't double-encode URLs (Roderick Monje).
data/README.md CHANGED
@@ -10,12 +10,11 @@ Please feel free to contribute Issues and pull requests.
10
10
  ## Documentation valid for `master` branch
11
11
 
12
12
  Please check the documentation for the paperclip version you are using:
13
- https://github.com/kreeti/paperclip/releases
13
+ https://github.com/kreeti/kt-paperclip/releases
14
14
 
15
15
  ---
16
16
 
17
- [![Build Status](https://secure.travis-ci.org/kreeti/paperclip.svg?branch=master)](http://travis-ci.org/kreeti/paperclip)
18
- [![Dependency Status](https://gemnasium.com/kreeti/paperclip.svg?travis)](https://gemnasium.com/kreeti/paperclip)
17
+ [![Build Status](https://travis-ci.com/kreeti/kt-paperclip.svg?branch=master)](https://travis-ci.com/kreeti/kt-paperclip)
19
18
  [![Code Climate](https://codeclimate.com/github/kreeti/paperclip.svg)](https://codeclimate.com/github/kreeti/paperclip)
20
19
  [![Inline docs](http://inch-ci.org/github/kreeti/paperclip.svg)](http://inch-ci.org/github/kreeti/paperclip)
21
20
  [![Security](https://hakiri.io/github/kreeti/paperclip/master.svg)](https://hakiri.io/github/kreeti/paperclip/master)
@@ -79,10 +78,10 @@ packages). Attached files are saved to the filesystem and referenced in the
79
78
  browser by an easily understandable specification, which has sensible and
80
79
  useful defaults.
81
80
 
82
- See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
81
+ See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/ClassMethods) for
83
82
  more detailed options.
84
83
 
85
- The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
84
+ The complete [RDoc](http://www.rubydoc.info/gems/kt-paperclip) is online.
86
85
 
87
86
  ---
88
87
 
@@ -91,7 +90,7 @@ Requirements
91
90
 
92
91
  ### Ruby and Rails
93
92
 
94
- Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2**
93
+ Paperclip now requires Ruby version **>= 2.3** and Rails version **>= 4.2**
95
94
  (only if you're going to use Paperclip with Ruby on Rails).
96
95
 
97
96
  ### Image Processor
@@ -172,13 +171,13 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
172
171
  Include the gem in your Gemfile:
173
172
 
174
173
  ```ruby
175
- gem "kt-paperclip", "~> 6.0.0"
174
+ gem "kt-paperclip", "~> 6.4", ">= 6.4.1"
176
175
  ```
177
176
 
178
177
  Or, if you want to get the latest, you can get master from the main paperclip repository:
179
178
 
180
179
  ```ruby
181
- gem "paperclip", git: "git://github.com/kreeti/paperclip.git"
180
+ gem "kt-paperclip", git: "git://github.com/kreeti/kt-paperclip.git"
182
181
  ```
183
182
 
184
183
  If you're trying to use features that don't seem to be in the latest released gem, but are
@@ -310,7 +309,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
310
309
  validation.
311
310
 
312
311
  More information about the options passed to `has_attached_file` is available in the
313
- documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
312
+ documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/ClassMethods).
314
313
 
315
314
  Validations
316
315
  -----------
@@ -342,7 +341,7 @@ Example Usage:
342
341
  validates_attachment_presence :avatar
343
342
  ```
344
343
 
345
- Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
344
+ You can also define multiple validations on a single attachment using `validates_attachment`:
346
345
 
347
346
  ```ruby
348
347
  validates_attachment :avatar, presence: true,
@@ -411,6 +410,28 @@ validates_attachment :avatar,
411
410
  `Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
412
411
  inferred content_type, regardless of the actual contents of the file.
413
412
 
413
+ ### Duplicate error messages
414
+
415
+ By default Paperclip will copy validation errors from the attribute to the base
416
+ of your model. Depending on how you display your validation errors, this can lead
417
+ to confusing duplicate errors (one on the attribute and another referring to the
418
+ base model).
419
+
420
+ You can override this behaviour with the `add_validation_errors_to` option. By
421
+ default this is set to `:both` but can be set to either `:attribute` or `:base`.
422
+
423
+ * `:both` creates errors on both the attribute and base model.
424
+ * `:attribute` only creates an error on the attribute of the model.
425
+ * `:base` only creates an error on the base model.
426
+
427
+ You can set this option globally:
428
+
429
+ `Paperclip.options[:add_validation_errors_to] = :attribute`
430
+
431
+ or pass it in to an individual validation declaration:
432
+
433
+ `validates_attachment :document, content_type: { content_type: "application/pdf" }, add_validation_errors_to: :attribute`
434
+
414
435
  ---
415
436
 
416
437
  Internationalization (I18n)
@@ -606,7 +627,7 @@ gem 'aws-sdk-s3'
606
627
 
607
628
  And then you can specify using S3 from `has_attached_file`.
608
629
  You can find more information about configuring and using S3 storage in
609
- [the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
630
+ [the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/Storage/S3).
610
631
 
611
632
  Files on the local filesystem (and in the Rails app's public directory) will be
612
633
  available to the internet at large. If you require access control, it's
@@ -689,7 +710,7 @@ Custom Attachment Processors
689
710
  You can write your own custom attachment processors to carry out tasks like
690
711
  adding watermarks, compressing images, or encrypting files. Custom processors
691
712
  must be defined within the `Paperclip` module, inherit from
692
- `Paperclip::Processor` (see [`lib/paperclip/processor.rb`](https://github.com/kreeti/paperclip/blob/master/lib/paperclip/processor.rb)),
713
+ `Paperclip::Processor` (see [`lib/paperclip/processor.rb`](https://github.com/kreeti/kt-paperclip/blob/master/lib/paperclip/processor.rb)),
693
714
  and implement a `make` method that returns a `File`. All files in your Rails
694
715
  app's `lib/paperclip` and `lib/paperclip_processors` directories will be
695
716
  automatically loaded by Paperclip. Processors are specified using the
@@ -892,7 +913,7 @@ Your::Application.configure do
892
913
  end
893
914
  ```
894
915
 
895
- More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip.options)
916
+ More information in the [rdocs](https://www.rubydoc.info/gems/kt-paperclip/Paperclip.options)
896
917
 
897
918
  ---
898
919
 
@@ -976,7 +997,7 @@ Testing
976
997
  -------
977
998
 
978
999
  Paperclip provides rspec-compatible matchers for testing attachments. See the
979
- documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
1000
+ documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/kt-paperclip/Paperclip/Shoulda/Matchers)
980
1001
  for more information.
981
1002
 
982
1003
  **Parallel Tests**
@@ -1036,18 +1057,19 @@ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
1036
1057
  fix/feature has a high chance of being included, please read the following
1037
1058
  guidelines:
1038
1059
 
1039
- 1. Post a [pull request](https://github.com/kreeti/paperclip/compare/).
1060
+ 1. Post a [pull request](https://github.com/kreeti/kt-paperclip/compare/).
1040
1061
  2. Make sure there are tests! We will not accept any patch that is not tested.
1041
1062
  It's a rare time when explicit tests aren't needed. If you have questions
1042
1063
  about writing tests for paperclip, please open a
1043
- [GitHub issue](https://github.com/kreeti/paperclip/issues/new).
1064
+ [GitHub issue](https://github.com/kreeti/kt-paperclip/issues/new).
1044
1065
 
1045
1066
  Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
1046
1067
 
1047
- Thank you to all [the contributors](https://github.com/kreeti/paperclip/graphs/contributors)!
1068
+ Thank you to all [the contributors](https://github.com/kreeti/kt-paperclip/graphs/contributors)!
1048
1069
 
1049
1070
  License
1050
1071
  -------
1051
1072
 
1052
- Paperclip is Copyright &copy; 2008-2017 thoughtbot, inc. It is free software, and may be
1053
- redistributed under the terms specified in the MIT-LICENSE file.
1073
+ Copyright &copy; 2020-2021 Kreeti Technologies Pvt. Ltd.
1074
+ Copyright &copy; 2008-2017 thoughtbot, inc.
1075
+ It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -23,7 +23,7 @@ When /^I modify my attachment definition to:$/ do |definition|
23
23
  end
24
24
 
25
25
  When /^I upload the fixture "([^"]*)"$/ do |filename|
26
- run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
26
+ aruba_run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
27
27
  end
28
28
 
29
29
  Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
@@ -108,3 +108,13 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
108
108
  expect(columns).not_to include(*expect_columns)
109
109
  end
110
110
  end
111
+
112
+ # we have to support different versions of aruba, and this method was renamed for 1.0
113
+ # https://github.com/cucumber/aruba/pull/438
114
+ def aruba_run_simple(*args)
115
+ if respond_to?(:run_simple)
116
+ run_simple(*args)
117
+ elsif respond_to?(:run_command_and_stop)
118
+ run_command_and_stop(*args)
119
+ end
120
+ end
data/gemfiles/4.2.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.0.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.1.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/5.2.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
data/gemfiles/6.0.gemfile CHANGED
@@ -11,9 +11,9 @@ group :development, :test do
11
11
  gem "bootsnap", require: false
12
12
  gem "builder"
13
13
  gem "listen", "~> 3.0.8"
14
- gem "mime-types"
15
14
  gem "rspec"
16
15
  gem "rubocop", require: false
16
+ gem "rubocop-rails"
17
17
  gem "sprockets", "3.7.2"
18
18
  end
19
19
 
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "sqlite3", "~> 1.4", platforms: :ruby
7
+ gem "aruba", "~> 1.0", ">= 1.0.4"
8
+ gem "rails", "~> 6.1", ">= 6.1.1"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "bootsnap", require: false
13
+ gem "builder"
14
+ gem "listen", "~> 3.0.8"
15
+ gem "rspec"
16
+ gem "rubocop", require: false
17
+ gem "rubocop-rails"
18
+ gem "sprockets", "3.7.2"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "sqlite3", "~> 1.4", platforms: :ruby
7
+ gem "aruba", "~> 1.0", ">= 1.0.4"
8
+ gem "rails", "~> 7.0.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "bootsnap", require: false
13
+ gem "builder"
14
+ gem "listen", "~> 3.0.8"
15
+ gem "rspec"
16
+ gem "rubocop", require: false
17
+ gem "rubocop-rails"
18
+ gem "sprockets", "3.7.2"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1 @@
1
+ require "paperclip"
@@ -38,7 +38,7 @@ module Paperclip
38
38
  end
39
39
 
40
40
  attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny,
41
- :options, :interpolator, :source_file_options
41
+ :options, :interpolator, :source_file_options, :queued_for_delete
42
42
  attr_accessor :post_processing
43
43
 
44
44
  # Creates an Attachment object. +name+ is the name of the attachment,
@@ -60,16 +60,21 @@ module Paperclip
60
60
  end
61
61
 
62
62
  def type_from_file_contents
63
- type_from_mime_magic || type_from_file_command
63
+ type_from_marcel || type_from_file_command
64
64
  rescue Errno::ENOENT => e
65
65
  Paperclip.log("Error while determining content type: #{e}")
66
66
  SENSIBLE_DEFAULT
67
67
  end
68
68
 
69
- def type_from_mime_magic
70
- @type_from_mime_magic ||= File.open(@filepath) do |file|
71
- MimeMagic.by_magic(file).try(:type)
72
- end
69
+ def type_from_marcel
70
+ return @type_from_marcel if defined? @type_from_marcel
71
+
72
+ @type_from_marcel = Marcel::MimeType.for Pathname.new(@filepath),
73
+ name: @filepath
74
+ # Marcel::MineType returns 'application/octet-stream' if it can't find
75
+ # a valid type.
76
+ @type_from_marcel = nil if @type_from_marcel == SENSIBLE_DEFAULT
77
+ @type_from_marcel
73
78
  end
74
79
 
75
80
  def type_from_file_command
@@ -9,8 +9,8 @@ module Paperclip
9
9
  REGEXP = /\Ahttps?:\/\//.freeze
10
10
 
11
11
  def initialize(target, options = {})
12
- escaped = URI.escape(target)
13
- super(URI(target == URI.unescape(target) ? escaped : target), options)
12
+ escaped = Paperclip::UrlGenerator.escape(target)
13
+ super(URI(target == Paperclip::UrlGenerator.unescape(target) ? escaped : target), options)
14
14
  end
15
15
  end
16
16
  end
@@ -50,10 +50,20 @@ module Paperclip
50
50
  "index.html"
51
51
  end
52
52
 
53
- def download_content
54
- options = { read_timeout: Paperclip.options[:read_timeout] }.compact
53
+ if RUBY_VERSION < '2.5'
54
+ def download_content
55
+ options = { read_timeout: Paperclip.options[:read_timeout] }.compact
55
56
 
56
- open(@target, **options)
57
+ # rubocop:disable Security/Open
58
+ open(@target, options)
59
+ # rubocop:enable Security/Open
60
+ end
61
+ else
62
+ def download_content
63
+ options = { read_timeout: Paperclip.options[:read_timeout] }.compact
64
+
65
+ URI.open(@target, options)
66
+ end
57
67
  end
58
68
 
59
69
  def copy_to_tempfile(src)
@@ -26,7 +26,7 @@ module Paperclip
26
26
  attachment_names.each do |attachment_name|
27
27
  COLUMNS.each_pair do |column_name, column_type|
28
28
  column_options = options.merge(options[column_name.to_sym] || {})
29
- add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
29
+ add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options)
30
30
  end
31
31
  end
32
32
  end
@@ -55,7 +55,7 @@ module Paperclip
55
55
  attachment_names.each do |attachment_name|
56
56
  COLUMNS.each_pair do |column_name, column_type|
57
57
  column_options = options.merge(options[column_name.to_sym] || {})
58
- column("#{attachment_name}_#{column_name}", column_type, column_options)
58
+ column("#{attachment_name}_#{column_name}", column_type, **column_options)
59
59
  end
60
60
  end
61
61
  end
@@ -57,7 +57,7 @@ module Paperclip
57
57
  end
58
58
 
59
59
  def flush_deletes #:nodoc:
60
- @queued_for_delete.each do |path|
60
+ @queued_for_delete.uniq.each do |path|
61
61
  begin
62
62
  log("deleting #{path}")
63
63
  FileUtils.rm(path) if File.exist?(path)
@@ -135,7 +135,7 @@ module Paperclip
135
135
  end
136
136
 
137
137
  def flush_deletes
138
- @queued_for_delete.each do |path|
138
+ @queued_for_delete.uniq.each do |path|
139
139
  log("deleting #{path}")
140
140
  directory.files.new(key: path).destroy
141
141
  end
@@ -403,7 +403,7 @@ module Paperclip
403
403
  end
404
404
 
405
405
  def flush_deletes #:nodoc:
406
- @queued_for_delete.each do |path|
406
+ @queued_for_delete.uniq.each do |path|
407
407
  begin
408
408
  log("deleting #{path}")
409
409
  s3_bucket.object(path.sub(%r{\A/}, "")).delete
@@ -427,9 +427,9 @@ module Paperclip
427
427
  def find_credentials(creds)
428
428
  case creds
429
429
  when File
430
- YAML::safe_load(ERB.new(File.read(creds.path)).result)
430
+ YAML::safe_load(ERB.new(File.read(creds.path)).result, [], [], true)
431
431
  when String, Pathname
432
- YAML::safe_load(ERB.new(File.read(creds)).result)
432
+ YAML::safe_load(ERB.new(File.read(creds)).result, [], [], true)
433
433
  when Hash
434
434
  creds
435
435
  when NilClass
@@ -3,6 +3,13 @@ require "active_support/core_ext/module/delegation"
3
3
 
4
4
  module Paperclip
5
5
  class UrlGenerator
6
+ class << self
7
+ def encoder
8
+ @encoder ||= URI::RFC2396_Parser.new
9
+ end
10
+ delegate :escape, :unescape, to: :encoder
11
+ end
12
+
6
13
  def initialize(attachment)
7
14
  @attachment = attachment
8
15
  end
@@ -65,7 +72,7 @@ module Paperclip
65
72
  if url.respond_to?(:escape)
66
73
  url.escape
67
74
  else
68
- URI.escape(url).gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" }
75
+ self.class.escape(url).gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" }
69
76
  end
70
77
  end
71
78
 
@@ -3,6 +3,9 @@ module Paperclip
3
3
  class AttachmentContentTypeValidator < ActiveModel::EachValidator
4
4
  def initialize(options)
5
5
  options[:allow_nil] = true unless options.key?(:allow_nil)
6
+ unless options.key?(:add_validation_errors_to)
7
+ options[:add_validation_errors_to] = Paperclip.options[:add_validation_errors_to]
8
+ end
6
9
  super
7
10
  end
8
11
 
@@ -20,10 +23,14 @@ module Paperclip
20
23
  validate_whitelist(record, attribute, value)
21
24
  validate_blacklist(record, attribute, value)
22
25
 
23
- if record.errors.include? attribute
26
+ if record.errors.include?(attribute) &&
27
+ [:both, :base].include?(options[:add_validation_errors_to])
28
+
24
29
  record.errors[attribute].each do |error|
25
30
  record.errors.add base_attribute, error
26
31
  end
32
+
33
+ record.errors.delete(attribute) if options[:add_validation_errors_to] == :base
27
34
  end
28
35
  end
29
36
 
@@ -40,7 +47,7 @@ module Paperclip
40
47
  end
41
48
 
42
49
  def mark_invalid(record, attribute, types)
43
- record.errors.add attribute, :invalid, options.merge(types: types.join(", "))
50
+ record.errors.add attribute, :invalid, **options.merge(types: types.join(", "))
44
51
  end
45
52
 
46
53
  def allowed_types
@@ -3,6 +3,9 @@ module Paperclip
3
3
  class AttachmentFileNameValidator < ActiveModel::EachValidator
4
4
  def initialize(options)
5
5
  options[:allow_nil] = true unless options.key?(:allow_nil)
6
+ unless options.key?(:add_validation_errors_to)
7
+ options[:add_validation_errors_to] = Paperclip.options[:add_validation_errors_to]
8
+ end
6
9
  super
7
10
  end
8
11
 
@@ -20,10 +23,14 @@ module Paperclip
20
23
  validate_whitelist(record, attribute, value)
21
24
  validate_blacklist(record, attribute, value)
22
25
 
23
- if record.errors.include? attribute
26
+ if record.errors.include?(attribute) &&
27
+ [:both, :base].include?(options[:add_validation_errors_to])
28
+
24
29
  record.errors[attribute].each do |error|
25
- record.errors.add base_attribute, error
30
+ record.errors.add(base_attribute, error)
26
31
  end
32
+
33
+ record.errors.delete(attribute) if options[:add_validation_errors_to] == :base
27
34
  end
28
35
  end
29
36
 
@@ -36,7 +43,7 @@ module Paperclip
36
43
  end
37
44
 
38
45
  def mark_invalid(record, attribute, patterns)
39
- record.errors.add attribute, :invalid, options.merge(names: patterns.join(", "))
46
+ record.errors.add attribute, :invalid, **options.merge(names: patterns.join(", "))
40
47
  end
41
48
 
42
49
  def allowed