kt-paperclip 6.3.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.hound.yml +1 -1
  4. data/.travis.yml +12 -5
  5. data/Appraisals +6 -0
  6. data/CONTRIBUTING.md +4 -5
  7. data/Gemfile +0 -1
  8. data/NEWS +31 -0
  9. data/README.md +5 -4
  10. data/features/step_definitions/attachment_steps.rb +11 -1
  11. data/gemfiles/4.2.gemfile +1 -1
  12. data/gemfiles/5.0.gemfile +1 -1
  13. data/gemfiles/5.1.gemfile +1 -1
  14. data/gemfiles/5.2.gemfile +1 -1
  15. data/gemfiles/6.0.gemfile +1 -1
  16. data/gemfiles/6.1.gemfile +21 -0
  17. data/lib/paperclip/attachment.rb +1 -1
  18. data/lib/paperclip/content_type_detector.rb +4 -4
  19. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
  20. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  21. data/lib/paperclip/schema.rb +2 -2
  22. data/lib/paperclip/storage/filesystem.rb +1 -1
  23. data/lib/paperclip/storage/fog.rb +1 -1
  24. data/lib/paperclip/storage/s3.rb +1 -1
  25. data/lib/paperclip/url_generator.rb +8 -1
  26. data/lib/paperclip/validators/attachment_content_type_validator.rb +1 -1
  27. data/lib/paperclip/validators/attachment_file_name_validator.rb +2 -2
  28. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  29. data/lib/paperclip/validators/attachment_size_validator.rb +1 -1
  30. data/lib/paperclip/version.rb +1 -1
  31. data/lib/paperclip.rb +1 -2
  32. data/paperclip.gemspec +3 -3
  33. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  34. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  35. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
  36. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  37. data/spec/paperclip/storage/filesystem_spec.rb +23 -0
  38. data/spec/paperclip/storage/fog_spec.rb +46 -0
  39. data/spec/paperclip/storage/s3_spec.rb +14 -3
  40. data/spec/paperclip/url_generator_spec.rb +10 -0
  41. data/spec/paperclip/validators_spec.rb +21 -6
  42. data/spec/support/model_reconstruction.rb +1 -1
  43. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0c273bab6a78348400356b49b6a713a1119b599d79bfa87c0eefa5660636fd0
4
- data.tar.gz: 46d706576d7f48a94e68c6cfbb6eedd7456df6f18a7f3e68b938649acbe69c6e
3
+ metadata.gz: d75e4f51d12950eb66e358408303a9640cc7d33b06a3fc8c6bcc66d1271cd7f8
4
+ data.tar.gz: dbbd1c7ee77e6755bcc2d6e321e29b948782f20b431035f9f21f9fe6f55fd87a
5
5
  SHA512:
6
- metadata.gz: 924cf86607996af398c917feb50929ca1398a4749cb97dc707605f9d7f59773d407b3e7aafc05e590769df670ab7c555e2c0f5fc082c79dbecb6532b3280ac9e
7
- data.tar.gz: 220f2c1f42cbf52e54c033da40e4f034d4771fb021b56eba3a8c5619e7ba41c01034ed3d8b84bcefd8339b936f9e5cf6f177e99788d02fe1cda3bedc74798ab7
6
+ metadata.gz: 1a594dabed3a1227fdaac88a48cde395d86cbe2401f86cedd21331219a25b32106c4f447099f0486023e251c78edb84c38d509c6c9742a026dd9860f41685f3f
7
+ data.tar.gz: 81ddf5f9db9ebdd21ababce60620d2575391e04f4e11643ac0ad64e6a865b4f4931ae88f81eeb7d36cbea7ff9a7307e21842794b5f97dc78efbaf8d19fbe63ea
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [ssinghi, sbhawsingka]
data/.hound.yml CHANGED
@@ -1040,7 +1040,7 @@ Lint/UselessAssignment:
1040
1040
  Description: Checks for useless assignment to a local variable.
1041
1041
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars
1042
1042
  Enabled: true
1043
- Lint/UselessComparison:
1043
+ Lint/BinaryOperatorWithIdenticalOperands:
1044
1044
  Description: Checks for comparison of something with itself.
1045
1045
  Enabled: true
1046
1046
  Lint/UselessElseWithoutRescue:
data/.travis.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.2
5
4
  - 2.3
6
5
  - 2.4
7
6
  - 2.5
8
7
  - 2.6
8
+ - 2.7
9
9
 
10
10
  script: "bundle exec rake clean spec cucumber"
11
11
 
@@ -24,15 +24,22 @@ gemfile:
24
24
  - gemfiles/5.1.gemfile
25
25
  - gemfiles/5.2.gemfile
26
26
  - gemfiles/6.0.gemfile
27
+ - gemfiles/6.1.gemfile
27
28
 
28
29
  matrix:
29
30
  fast_finish: true
30
31
  exclude:
31
- - gemfile: gemfiles/5.2.gemfile
32
- rvm: 2.2
33
- - gemfile: gemfiles/6.0.gemfile
34
- rvm: 2.2
35
32
  - gemfile: gemfiles/6.0.gemfile
36
33
  rvm: 2.3
37
34
  - gemfile: gemfiles/6.0.gemfile
38
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
@@ -11,7 +11,6 @@ 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
17
16
  gem "rubocop-rails"
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
@@ -90,7 +90,7 @@ Requirements
90
90
 
91
91
  ### Ruby and Rails
92
92
 
93
- Paperclip now requires Ruby version **>= 2.2** and Rails version **>= 4.2**
93
+ Paperclip now requires Ruby version **>= 2.3** and Rails version **>= 4.2**
94
94
  (only if you're going to use Paperclip with Ruby on Rails).
95
95
 
96
96
  ### Image Processor
@@ -171,7 +171,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
171
171
  Include the gem in your Gemfile:
172
172
 
173
173
  ```ruby
174
- gem "kt-paperclip", "~> 6.2.0"
174
+ gem "kt-paperclip", "~> 6.4", ">= 6.4.1"
175
175
  ```
176
176
 
177
177
  Or, if you want to get the latest, you can get master from the main paperclip repository:
@@ -1070,5 +1070,6 @@ Thank you to all [the contributors](https://github.com/kreeti/kt-paperclip/graph
1070
1070
  License
1071
1071
  -------
1072
1072
 
1073
- Paperclip is Copyright © 2008-2017 thoughtbot, inc. It is free software, and may be
1074
- redistributed under the terms specified in the MIT-LICENSE file.
1073
+ Copyright © 2020-2021 Kreeti Technologies Pvt. Ltd.
1074
+ Copyright © 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: "../"
@@ -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,15 +60,15 @@ 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)
69
+ def type_from_marcel
70
+ @type_from_marcel ||= File.open(@filepath) do |file|
71
+ Marcel::Magic.by_magic(file).try(:type)
72
72
  end
73
73
  end
74
74
 
@@ -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
@@ -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
 
@@ -47,7 +47,7 @@ module Paperclip
47
47
  end
48
48
 
49
49
  def mark_invalid(record, attribute, types)
50
- record.errors.add attribute, :invalid, options.merge(types: types.join(", "))
50
+ record.errors.add attribute, :invalid, **options.merge(types: types.join(", "))
51
51
  end
52
52
 
53
53
  def allowed_types
@@ -27,7 +27,7 @@ module Paperclip
27
27
  [:both, :base].include?(options[:add_validation_errors_to])
28
28
 
29
29
  record.errors[attribute].each do |error|
30
- record.errors.add base_attribute, error
30
+ record.errors.add(base_attribute, error)
31
31
  end
32
32
 
33
33
  record.errors.delete(attribute) if options[:add_validation_errors_to] == :base
@@ -43,7 +43,7 @@ module Paperclip
43
43
  end
44
44
 
45
45
  def mark_invalid(record, attribute, patterns)
46
- record.errors.add attribute, :invalid, options.merge(names: patterns.join(", "))
46
+ record.errors.add attribute, :invalid, **options.merge(names: patterns.join(", "))
47
47
  end
48
48
 
49
49
  def allowed
@@ -4,7 +4,7 @@ module Paperclip
4
4
  module Validators
5
5
  class AttachmentPresenceValidator < ActiveModel::EachValidator
6
6
  def validate_each(record, attribute, _value)
7
- record.errors.add(attribute, :blank, options) if record.send("#{attribute}_file_name").blank?
7
+ record.errors.add(attribute, :blank, **options) if record.send("#{attribute}_file_name").blank?
8
8
  end
9
9
 
10
10
  def self.helper_method_name
@@ -39,7 +39,7 @@ module Paperclip
39
39
  unless value.send(CHECKS[option], option_value)
40
40
  error_message_key = options[:in] ? :in_between : option
41
41
  error_attrs.each do |error_attr_name|
42
- record.errors.add(error_attr_name, error_message_key, filtered_options(value).merge(
42
+ record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
43
43
  min: min_value_in_human_size(record),
44
44
  max: max_value_in_human_size(record),
45
45
  count: human_size(option_value)
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "6.3.0" unless defined?(Paperclip::VERSION)
2
+ VERSION = "7.0.1" unless defined?(Paperclip::VERSION)
3
3
  end
data/lib/paperclip.rb CHANGED
@@ -64,8 +64,7 @@ rescue LoadError
64
64
  require "mime/types"
65
65
  end
66
66
 
67
- require "mimemagic"
68
- require "mimemagic/overlay"
67
+ require "marcel"
69
68
  require "logger"
70
69
  require "terrapin"
71
70
 
data/paperclip.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.author = "Surendra Singhi"
9
9
  s.email = ["ssinghi@kreeti.com"]
10
- s.homepage = "https://github.com/kreeti/paperclip"
10
+ s.homepage = "https://github.com/kreeti/kt-paperclip"
11
11
  s.summary = "File attachments as attributes for ActiveRecord"
12
12
  s.description = "Easy upload management for ActiveRecord"
13
13
  s.license = "MIT"
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
21
21
 
22
22
  s.requirements << "ImageMagick"
23
- s.required_ruby_version = ">= 2.2.0"
23
+ s.required_ruby_version = ">= 2.3.0"
24
24
 
25
25
  s.add_dependency("activemodel", ">= 4.2.0")
26
26
  s.add_dependency("activesupport", ">= 4.2.0")
27
27
  s.add_dependency("mime-types")
28
- s.add_dependency("mimemagic", "~> 0.3.0")
28
+ s.add_dependency("marcel", "~> 1.0.1")
29
29
  s.add_dependency("terrapin", "~> 0.6.0")
30
30
 
31
31
  s.add_development_dependency("activerecord", ">= 4.2.0")
@@ -15,7 +15,7 @@ describe Paperclip::AbstractAdapter do
15
15
  before do
16
16
  allow(subject).to receive(:path).and_return("image.png")
17
17
  allow(Paperclip).to receive(:run).and_return("image/png\n")
18
- allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_mime_magic).and_return("image/png")
18
+ allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_marcel).and_return("image/png")
19
19
  end
20
20
 
21
21
  it "returns the content type without newline" do
@@ -78,7 +78,7 @@ describe Paperclip::FileAdapter do
78
78
  allow(MIME::Types).to receive(:type_for).and_return([])
79
79
  allow(Paperclip).to receive(:run).and_return("application/vnd.ms-office\n")
80
80
  allow_any_instance_of(Paperclip::ContentTypeDetector).
81
- to receive(:type_from_mime_magic).and_return("application/vnd.ms-office")
81
+ to receive(:type_from_marcel).and_return("application/vnd.ms-office")
82
82
 
83
83
  @subject = Paperclip.io_adapters.for(@file)
84
84
  end
@@ -16,54 +16,59 @@ describe Paperclip::HttpUrlProxyAdapter do
16
16
  context "a new instance" do
17
17
  before do
18
18
  @url = "http://thoughtbot.com/images/thoughtbot-logo.png"
19
- @subject = Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5)
20
19
  end
21
20
 
21
+ subject { Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5) }
22
+
22
23
  after do
23
- @subject.close
24
+ subject.close
24
25
  end
25
26
 
26
27
  it "returns a file name" do
27
- assert_equal "thoughtbot-logo.png", @subject.original_filename
28
+ expect(subject.original_filename).to(eq("thoughtbot-logo.png"))
28
29
  end
29
30
 
30
31
  it "closes open handle after reading" do
31
- assert_equal true, @open_return.closed?
32
+ expect { subject }.to(change { @open_return.closed? }.from(false).to(true))
32
33
  end
33
34
 
34
35
  it "returns a content type" do
35
- assert_equal "image/png", @subject.content_type
36
+ expect(subject.content_type).to(eq("image/png"))
36
37
  end
37
38
 
38
39
  it "returns the size of the data" do
39
- assert_equal @open_return.size, @subject.size
40
+ expect(subject.size).to(eq(@open_return.size))
40
41
  end
41
42
 
42
43
  it "generates an MD5 hash of the contents" do
43
- assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint
44
+ expect(subject.fingerprint).to(eq(Digest::MD5.hexdigest("xxx")))
44
45
  end
45
46
 
46
47
  it "generates correct fingerprint after read" do
47
- fingerprint = Digest::MD5.hexdigest(@subject.read)
48
- assert_equal fingerprint, @subject.fingerprint
48
+ fingerprint = Digest::MD5.hexdigest(subject.read)
49
+ expect(subject.fingerprint).to(eq(fingerprint))
49
50
  end
50
51
 
51
52
  it "generates same fingerprint" do
52
- assert_equal @subject.fingerprint, @subject.fingerprint
53
+ expect(subject.fingerprint).to(eq(subject.fingerprint))
53
54
  end
54
55
 
55
56
  it "returns the data contained in the StringIO" do
56
- assert_equal "xxx", @subject.read
57
+ expect(subject.read).to(eq("xxx"))
57
58
  end
58
59
 
59
60
  it "accepts a content_type" do
60
- @subject.content_type = "image/png"
61
- assert_equal "image/png", @subject.content_type
61
+ subject.content_type = "image/png"
62
+ expect(subject.content_type).to(eq("image/png"))
62
63
  end
63
64
 
64
65
  it "accepts an original_filename" do
65
- @subject.original_filename = "image.png"
66
- assert_equal "image.png", @subject.original_filename
66
+ subject.original_filename = "image.png"
67
+ expect(subject.original_filename).to(eq("image.png"))
68
+ end
69
+
70
+ it "doesn't emit deprecation warnings" do
71
+ expect { subject }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
67
72
  end
68
73
  end
69
74
 
@@ -193,9 +193,18 @@ describe Paperclip::UriAdapter do
193
193
 
194
194
  describe "#download_content" do
195
195
  before do
196
- allow_any_instance_of(Paperclip::UriAdapter).to receive(:open).and_return(@open_return)
196
+ allowed_mock =
197
+ if RUBY_VERSION < '2.5'
198
+ allow_any_instance_of(Paperclip::UriAdapter)
199
+ else
200
+ allow(URI)
201
+ end
202
+
203
+ allowed_mock.to receive(:open).and_return(@open_return)
204
+
197
205
  @uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
198
206
  @subject = Paperclip.io_adapters.for(@uri)
207
+ @uri_opener = RUBY_VERSION < '2.5' ? @subject : URI
199
208
  end
200
209
 
201
210
  after do
@@ -204,7 +213,7 @@ describe Paperclip::UriAdapter do
204
213
 
205
214
  context "with default read_timeout" do
206
215
  it "calls open without options" do
207
- expect(@subject).to receive(:open).with(@uri, {}).at_least(1).times
216
+ expect(@uri_opener).to receive(:open).with(@uri, {}).at_least(1).times
208
217
  end
209
218
  end
210
219
 
@@ -214,7 +223,8 @@ describe Paperclip::UriAdapter do
214
223
  end
215
224
 
216
225
  it "calls open with read_timeout option" do
217
- expect(@subject).to receive(:open).with(@uri, read_timeout: 120).at_least(1).times
226
+ expect(@uri_opener)
227
+ .to receive(:open).with(@uri, read_timeout: 120).at_least(1).times
218
228
  end
219
229
  end
220
230
  end
@@ -49,6 +49,29 @@ describe Paperclip::Storage::Filesystem do
49
49
  assert_equal @file.read, tempfile.read
50
50
  tempfile.close
51
51
  end
52
+
53
+ it "only issues a delete call once for each unique attachment style when nullifying attachment" do
54
+ @dummy.save
55
+ @dummy.avatar.clear(:thumbnail)
56
+ @dummy.avatar = nil
57
+ assert_equal 3, @dummy.avatar.queued_for_delete.size
58
+
59
+ expect(FileUtils).to receive(:rm).twice
60
+ @dummy.save
61
+
62
+ FileUtils.rm_rf("tmp")
63
+ end
64
+
65
+ it "only issues a delete call once for each unique attachment style when destroying model" do
66
+ @dummy.save
67
+ @dummy.avatar.clear(:thumbnail)
68
+ assert_equal 1, @dummy.avatar.queued_for_delete.size
69
+
70
+ expect(FileUtils).to receive(:rm).twice
71
+ @dummy.destroy
72
+
73
+ FileUtils.rm_rf("tmp")
74
+ end
52
75
  end
53
76
 
54
77
  context "with file that has space in file name" do
@@ -7,6 +7,52 @@ describe Paperclip::Storage::Fog do
7
7
  context "" do
8
8
  before { Fog.mock! }
9
9
 
10
+ context "deleting attachment styles" do
11
+ before do
12
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
13
+ storage: :fog,
14
+ url: "/:attachment/:style/:filename",
15
+ fog_directory: "paperclip",
16
+ fog_credentials: fixture_file("fog.yml")
17
+ @file = File.open(fixture_file("5k.png"))
18
+ @dummy = Dummy.new
19
+ @dummy.avatar = @file
20
+ @dummy.save
21
+ end
22
+
23
+ after do
24
+ @file.close
25
+ FileUtils.rm_rf("tmp")
26
+ end
27
+
28
+ it "only issues a delete call once for each unique attachment style when nullifying attachment" do
29
+ @dummy.avatar.clear(:thumb)
30
+ @dummy.avatar = nil
31
+ assert_equal 4, @dummy.avatar.queued_for_delete.size
32
+
33
+ original = double("original")
34
+ medium = double("medium")
35
+ thumb = double("thumb")
36
+
37
+ allow(Fog::AWS::Storage::File).to receive(:new).and_return(original, medium, thumb)
38
+
39
+ expect(original).to receive(:destroy).once
40
+ expect(medium).to receive(:destroy).once
41
+ expect(thumb).to receive(:destroy).once
42
+ @dummy.save
43
+ end
44
+
45
+ it "only issues a delete call once for each unique attachment style when destroying model" do
46
+ @dummy.avatar.clear(:thumb)
47
+ assert_equal 1, @dummy.avatar.queued_for_delete.size
48
+
49
+ file = double("file")
50
+ allow(Fog::AWS::Storage::File).to receive(:new).and_return(file)
51
+ expect(file).to receive(:destroy).exactly(3).times
52
+ @dummy.destroy
53
+ end
54
+ end
55
+
10
56
  context "with credentials provided in a path string" do
11
57
  before do
12
58
  rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
@@ -805,9 +805,7 @@ describe Paperclip::Storage::S3 do
805
805
  s3_region: "ap-northeast-1",
806
806
  s3_host_name: "s3-ap-northeast-1.amazonaws.com"
807
807
  },
808
- test: {
809
- s3_region: ""
810
- }
808
+ test: {}
811
809
  }
812
810
  @dummy = Dummy.new
813
811
  end
@@ -942,6 +940,19 @@ describe Paperclip::Storage::S3 do
942
940
  end
943
941
  end
944
942
 
943
+ context "and remove, calling S3 Object destroy once per unique style" do
944
+ before do
945
+ allow_any_instance_of(Aws::S3::Object).to receive(:exists?).and_return(true)
946
+ expect_any_instance_of(Aws::S3::Object).to receive(:delete).once
947
+ @dummy.avatar.clear(:original)
948
+ @dummy.destroy
949
+ end
950
+
951
+ it "succeeds" do
952
+ assert true
953
+ end
954
+ end
955
+
945
956
  context "that the file were missing" do
946
957
  before do
947
958
  allow_any_instance_of(Aws::S3::Object).to receive(:exists?).
@@ -194,6 +194,16 @@ describe Paperclip::UrlGenerator do
194
194
  "expected the interpolator to be passed #{expected.inspect} but it wasn't"
195
195
  end
196
196
 
197
+ it "doesn't emit deprecation warnings" do
198
+ expected = "the expected result"
199
+ mock_interpolator = MockInterpolator.new(result: expected)
200
+ options = { interpolator: mock_interpolator }
201
+ mock_attachment = MockAttachment.new(options)
202
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
203
+
204
+ expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
205
+ end
206
+
197
207
  describe "should be able to escape (, ), [, and ]." do
198
208
  def generate(expected, updated_at = nil)
199
209
  mock_interpolator = MockInterpolator.new(result: expected)
@@ -1,6 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Paperclip::Validators do
4
+ # required to support a range of rubies
5
+ def error_attribute_names(error)
6
+ error.try(:attribute_names) || error.keys
7
+ end
8
+
4
9
  context "using the helper" do
5
10
  before do
6
11
  rebuild_class
@@ -22,7 +27,9 @@ describe Paperclip::Validators do
22
27
  it "prevents you from attaching a file that violates that validation" do
23
28
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
24
29
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
25
- expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
30
+ expect(error_attribute_names(dummy.errors)).to match_array(
31
+ %i[avatar_content_type avatar avatar_file_size]
32
+ )
26
33
  assert_raises(RuntimeError) { dummy.valid? }
27
34
  end
28
35
  end
@@ -47,21 +54,27 @@ describe Paperclip::Validators do
47
54
  it "prevents you from attaching a file that violates all of these validations" do
48
55
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
49
56
  dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.png")))
50
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
57
+ expect(error_attribute_names(dummy.errors)).to match_array(
58
+ %i[avatar avatar_file_name]
59
+ )
51
60
  assert_raises(RuntimeError) { dummy.valid? }
52
61
  end
53
62
 
54
63
  it "prevents you from attaching a file that violates only first of these validations" do
55
64
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
56
65
  dummy = Dummy.new(avatar: File.new(fixture_file("5k.png")))
57
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
66
+ expect(error_attribute_names(dummy.errors)).to match_array(
67
+ %i[avatar avatar_file_name]
68
+ )
58
69
  assert_raises(RuntimeError) { dummy.valid? }
59
70
  end
60
71
 
61
72
  it "prevents you from attaching a file that violates only second of these validations" do
62
73
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
63
74
  dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.jpg")))
64
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
75
+ expect(error_attribute_names(dummy.errors)).to match_array(
76
+ %i[avatar avatar_file_name]
77
+ )
65
78
  assert_raises(RuntimeError) { dummy.valid? }
66
79
  end
67
80
 
@@ -88,7 +101,9 @@ describe Paperclip::Validators do
88
101
  end
89
102
  end
90
103
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
91
- expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
104
+ expect(error_attribute_names(dummy.errors)).to match_array(
105
+ %i[avatar_content_type avatar avatar_file_size]
106
+ )
92
107
  end
93
108
 
94
109
  it "does not validate attachment if title is not present" do
@@ -98,7 +113,7 @@ describe Paperclip::Validators do
98
113
  end
99
114
  end
100
115
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
101
- assert_equal [], dummy.errors.keys
116
+ assert_equal [], error_attribute_names(dummy.errors)
102
117
  end
103
118
  end
104
119
 
@@ -28,7 +28,7 @@ module ModelReconstruction
28
28
 
29
29
  def reset_table(_table_name, &block)
30
30
  block ||= lambda { |_table| true }
31
- ActiveRecord::Base.connection.create_table :dummies, { force: true }, &block
31
+ ActiveRecord::Base.connection.create_table :dummies, **{ force: true }, &block
32
32
  end
33
33
 
34
34
  def modify_table(&block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kt-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surendra Singhi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mimemagic
56
+ name: marcel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.0
61
+ version: 1.0.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.3.0
68
+ version: 1.0.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: terrapin
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -354,6 +354,7 @@ extensions: []
354
354
  extra_rdoc_files: []
355
355
  files:
356
356
  - ".codeclimate.yml"
357
+ - ".github/FUNDING.yml"
357
358
  - ".github/ISSUE_TEMPLATE/bug_report.md"
358
359
  - ".github/ISSUE_TEMPLATE/custom.md"
359
360
  - ".github/ISSUE_TEMPLATE/feature_request.md"
@@ -392,6 +393,7 @@ files:
392
393
  - gemfiles/5.1.gemfile
393
394
  - gemfiles/5.2.gemfile
394
395
  - gemfiles/6.0.gemfile
396
+ - gemfiles/6.1.gemfile
395
397
  - lib/generators/paperclip/USAGE
396
398
  - lib/generators/paperclip/paperclip_generator.rb
397
399
  - lib/generators/paperclip/templates/paperclip_migration.rb.erb
@@ -546,7 +548,7 @@ files:
546
548
  - spec/support/reporting.rb
547
549
  - spec/support/test_data.rb
548
550
  - spec/support/version_helper.rb
549
- homepage: https://github.com/kreeti/paperclip
551
+ homepage: https://github.com/kreeti/kt-paperclip
550
552
  licenses:
551
553
  - MIT
552
554
  metadata: {}
@@ -575,7 +577,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
575
577
  requirements:
576
578
  - - ">="
577
579
  - !ruby/object:Gem::Version
578
- version: 2.2.0
580
+ version: 2.3.0
579
581
  required_rubygems_version: !ruby/object:Gem::Requirement
580
582
  requirements:
581
583
  - - ">="
@@ -583,8 +585,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
583
585
  version: '0'
584
586
  requirements:
585
587
  - ImageMagick
586
- rubyforge_project:
587
- rubygems_version: 2.7.9
588
+ rubygems_version: 3.0.1
588
589
  signing_key:
589
590
  specification_version: 4
590
591
  summary: File attachments as attributes for ActiveRecord