kt-paperclip 6.2.0 → 6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/custom.md +10 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.hound.yml +364 -357
- data/.rubocop.yml +2 -0
- data/.travis.yml +7 -9
- data/Gemfile +3 -2
- data/README.md +38 -17
- data/lib/kt-paperclip.rb +1 -0
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
- data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
- data/lib/paperclip/schema.rb +2 -2
- data/lib/paperclip/storage/s3.rb +2 -2
- data/lib/paperclip/url_generator.rb +8 -1
- data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
- data/lib/paperclip/validators/attachment_file_name_validator.rb +9 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +18 -2
- data/lib/paperclip/validators.rb +4 -4
- data/lib/paperclip/version.rb +1 -1
- data/lib/paperclip.rb +2 -1
- data/paperclip.gemspec +3 -3
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
- data/spec/paperclip/storage/s3_spec.rb +54 -3
- data/spec/paperclip/url_generator_spec.rb +10 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
- data/spec/support/fixtures/aws_s3.yml +13 -0
- data/spec/support/model_reconstruction.rb +1 -1
- metadata +15 -10
- data/.github/issue_template.md +0 -3
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.1
|
5
4
|
- 2.2
|
6
5
|
- 2.3
|
7
6
|
- 2.4
|
8
7
|
- 2.5
|
9
8
|
- 2.6
|
9
|
+
- 2.7
|
10
10
|
|
11
11
|
script: "bundle exec rake clean spec cucumber"
|
12
12
|
|
@@ -29,19 +29,17 @@ gemfile:
|
|
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
32
|
- gemfile: gemfiles/5.2.gemfile
|
39
33
|
rvm: 2.2
|
40
|
-
- gemfile: gemfiles/6.0.gemfile
|
41
|
-
rvm: 2.1
|
42
34
|
- gemfile: gemfiles/6.0.gemfile
|
43
35
|
rvm: 2.2
|
44
36
|
- gemfile: gemfiles/6.0.gemfile
|
45
37
|
rvm: 2.3
|
46
38
|
- gemfile: gemfiles/6.0.gemfile
|
47
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/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
|
11
|
+
gem "bootsnap", require: false
|
12
12
|
gem "builder"
|
13
|
-
gem
|
13
|
+
gem "listen", "~> 3.0.8"
|
14
14
|
gem "mime-types"
|
15
15
|
gem "rspec"
|
16
16
|
gem "rubocop", require: false
|
17
|
+
gem "rubocop-rails"
|
17
18
|
gem "sprockets", "3.7.2"
|
18
19
|
end
|
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://
|
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.
|
93
|
+
Paperclip now requires Ruby version **>= 2.2** 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.
|
174
|
+
gem "kt-paperclip", "~> 6.3"
|
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
|
-
|
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](
|
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,15 +1057,15 @@ 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
|
-------
|
data/lib/kt-paperclip.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "paperclip"
|
@@ -9,8 +9,8 @@ module Paperclip
|
|
9
9
|
REGEXP = /\Ahttps?:\/\//.freeze
|
10
10
|
|
11
11
|
def initialize(target, options = {})
|
12
|
-
escaped =
|
13
|
-
super(URI(target ==
|
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
|
-
|
54
|
-
|
53
|
+
if RUBY_VERSION < '2.5'
|
54
|
+
def download_content
|
55
|
+
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
|
55
56
|
|
56
|
-
|
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)
|
data/lib/paperclip/schema.rb
CHANGED
@@ -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
|
data/lib/paperclip/storage/s3.rb
CHANGED
@@ -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
|
-
|
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?
|
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?
|
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
|
|
@@ -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
|
@@ -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
|
@@ -17,6 +17,18 @@ module Paperclip
|
|
17
17
|
def validate_each(record, attr_name, value)
|
18
18
|
base_attr_name = attr_name
|
19
19
|
attr_name = "#{attr_name}_file_size".to_sym
|
20
|
+
|
21
|
+
error_attrs = []
|
22
|
+
case options[:add_validation_errors_to]
|
23
|
+
when :base
|
24
|
+
error_attrs << base_attr_name
|
25
|
+
when :attribute
|
26
|
+
error_attrs << attr_name
|
27
|
+
else
|
28
|
+
error_attrs << base_attr_name
|
29
|
+
error_attrs << attr_name
|
30
|
+
end
|
31
|
+
|
20
32
|
value = record.send(:read_attribute_for_validation, attr_name)
|
21
33
|
|
22
34
|
unless value.blank?
|
@@ -26,8 +38,8 @@ module Paperclip
|
|
26
38
|
|
27
39
|
unless value.send(CHECKS[option], option_value)
|
28
40
|
error_message_key = options[:in] ? :in_between : option
|
29
|
-
|
30
|
-
record.errors.add(error_attr_name, error_message_key, filtered_options(value).merge(
|
41
|
+
error_attrs.each do |error_attr_name|
|
42
|
+
record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
|
31
43
|
min: min_value_in_human_size(record),
|
32
44
|
max: max_value_in_human_size(record),
|
33
45
|
count: human_size(option_value)
|
@@ -56,6 +68,10 @@ module Paperclip
|
|
56
68
|
options[:greater_than_or_equal_to] = range
|
57
69
|
end
|
58
70
|
end
|
71
|
+
|
72
|
+
unless options.key?(:add_validation_errors_to)
|
73
|
+
options[:add_validation_errors_to] = Paperclip.options[:add_validation_errors_to]
|
74
|
+
end
|
59
75
|
end
|
60
76
|
|
61
77
|
def extract_option_value(option, option_value)
|
data/lib/paperclip/validators.rb
CHANGED
@@ -20,10 +20,10 @@ module Paperclip
|
|
20
20
|
::Paperclip::REQUIRED_VALIDATORS = [AttachmentFileNameValidator, AttachmentContentTypeValidator, AttachmentFileTypeIgnoranceValidator].freeze
|
21
21
|
|
22
22
|
module ClassMethods
|
23
|
-
# This method is a shortcut to validator classes that
|
24
|
-
# "Attachment...Validator" format. It is almost the same
|
25
|
-
# +validates+ method that
|
26
|
-
#
|
23
|
+
# This method is a shortcut to the validator classes that are in
|
24
|
+
# "Attachment...Validator" format. It is almost the same as the
|
25
|
+
# +validates+ method that ships with Rails, but is customized for
|
26
|
+
# use with attachment validators. This is helpful when you're using
|
27
27
|
# multiple attachment validators on a single attachment.
|
28
28
|
#
|
29
29
|
# Example of using the validator:
|
data/lib/paperclip/version.rb
CHANGED
data/lib/paperclip.rb
CHANGED
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,7 +20,7 @@ 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.
|
23
|
+
s.required_ruby_version = ">= 2.2.0"
|
24
24
|
|
25
25
|
s.add_dependency("activemodel", ">= 4.2.0")
|
26
26
|
s.add_dependency("activesupport", ">= 4.2.0")
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.add_development_dependency("aws-sdk-s3")
|
35
35
|
s.add_development_dependency("bundler")
|
36
36
|
s.add_development_dependency("capybara")
|
37
|
-
s.add_development_dependency("cucumber-expressions"
|
37
|
+
s.add_development_dependency("cucumber-expressions")
|
38
38
|
s.add_development_dependency("cucumber-rails")
|
39
39
|
s.add_development_dependency("fakeweb")
|
40
40
|
s.add_development_dependency("fog-aws")
|
@@ -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
|
-
|
24
|
+
subject.close
|
24
25
|
end
|
25
26
|
|
26
27
|
it "returns a file name" do
|
27
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
48
|
-
|
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
|
-
|
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
|
-
|
57
|
+
expect(subject.read).to(eq("xxx"))
|
57
58
|
end
|
58
59
|
|
59
60
|
it "accepts a content_type" do
|
60
|
-
|
61
|
-
|
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
|
-
|
66
|
-
|
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
|
-
|
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(@
|
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(@
|
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
|