kt-paperclip 5.4.0 → 7.1.1
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 +3 -1055
- data/.rubocop.yml +1061 -1
- data/.travis.yml +23 -4
- data/Appraisals +23 -0
- data/CONTRIBUTING.md +4 -5
- data/Gemfile +10 -7
- data/NEWS +52 -0
- data/README.md +58 -46
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +23 -13
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/gemfiles/6.1.gemfile +21 -0
- data/gemfiles/7.0.gemfile +21 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +103 -105
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +10 -5
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +16 -12
- data/lib/paperclip/storage/filesystem.rb +6 -8
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +68 -76
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -5
- data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
- data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +16 -17
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +18 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +29 -6
- data/spec/paperclip/storage/fog_spec.rb +122 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +649 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -19
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +61 -46
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/fixtures/aws_s3.yml +13 -0
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +58 -106
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "active_model/validations/numericality"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
module Validators
|
5
5
|
class AttachmentSizeValidator < ActiveModel::Validations::NumericalityValidator
|
6
|
-
AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to]
|
6
|
+
AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to].freeze
|
7
7
|
|
8
8
|
def initialize(options)
|
9
9
|
extract_options(options)
|
@@ -17,21 +17,34 @@ 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?
|
23
35
|
options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
|
24
36
|
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
25
37
|
option_value = extract_option_value(option, option_value)
|
26
|
-
|
27
|
-
|
38
|
+
operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
|
39
|
+
|
40
|
+
unless value.send(operator, option_value)
|
28
41
|
error_message_key = options[:in] ? :in_between : option
|
29
|
-
|
30
|
-
record.errors.add(error_attr_name, error_message_key, filtered_options(value).merge(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
error_attrs.each do |error_attr_name|
|
43
|
+
record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
|
44
|
+
min: min_value_in_human_size(record),
|
45
|
+
max: max_value_in_human_size(record),
|
46
|
+
count: human_size(option_value)
|
47
|
+
))
|
35
48
|
end
|
36
49
|
end
|
37
50
|
end
|
@@ -39,7 +52,7 @@ module Paperclip
|
|
39
52
|
end
|
40
53
|
|
41
54
|
def check_validity!
|
42
|
-
unless (AVAILABLE_CHECKS + [:in]).any? { |argument| options.
|
55
|
+
unless (AVAILABLE_CHECKS + [:in]).any? { |argument| options.key?(argument) }
|
43
56
|
raise ArgumentError, "You must pass either :less_than, :greater_than, or :in to the validator"
|
44
57
|
end
|
45
58
|
end
|
@@ -56,6 +69,10 @@ module Paperclip
|
|
56
69
|
options[:greater_than_or_equal_to] = range
|
57
70
|
end
|
58
71
|
end
|
72
|
+
|
73
|
+
unless options.key?(:add_validation_errors_to)
|
74
|
+
options[:add_validation_errors_to] = Paperclip.options[:add_validation_errors_to]
|
75
|
+
end
|
59
76
|
end
|
60
77
|
|
61
78
|
def extract_option_value(option, option_value)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_model/validations/presence"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
module Validators
|
@@ -8,6 +8,8 @@ module Paperclip
|
|
8
8
|
if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename, value.content_type).spoofed?
|
9
9
|
record.errors.add(attribute, :spoofed_media_type)
|
10
10
|
end
|
11
|
+
|
12
|
+
adapter.tempfile.close(true) if adapter.tempfile
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
data/lib/paperclip/validators.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
require "active_model"
|
2
|
+
require "active_support/concern"
|
3
|
+
require "active_support/core_ext/array/wrap"
|
4
|
+
require "paperclip/validators/attachment_content_type_validator"
|
5
|
+
require "paperclip/validators/attachment_file_name_validator"
|
6
|
+
require "paperclip/validators/attachment_presence_validator"
|
7
|
+
require "paperclip/validators/attachment_size_validator"
|
8
|
+
require "paperclip/validators/media_type_spoof_detection_validator"
|
9
|
+
require "paperclip/validators/attachment_file_type_ignorance_validator"
|
10
10
|
|
11
11
|
module Paperclip
|
12
12
|
module Validators
|
@@ -17,13 +17,13 @@ module Paperclip
|
|
17
17
|
include HelperMethods
|
18
18
|
end
|
19
19
|
|
20
|
-
::Paperclip::REQUIRED_VALIDATORS = [AttachmentFileNameValidator, AttachmentContentTypeValidator, AttachmentFileTypeIgnoranceValidator]
|
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:
|
@@ -39,7 +39,7 @@ module Paperclip
|
|
39
39
|
if constant.to_s =~ /\AAttachment(.+)Validator\z/
|
40
40
|
validator_kind = $1.underscore.to_sym
|
41
41
|
|
42
|
-
if options.
|
42
|
+
if options.key?(validator_kind)
|
43
43
|
validator_options = options.delete(validator_kind)
|
44
44
|
validator_options = {} if validator_options == true
|
45
45
|
conditional_options = options.slice(:if, :unless)
|
@@ -64,11 +64,10 @@ module Paperclip
|
|
64
64
|
def create_validating_before_filter(attribute, validator_class, options)
|
65
65
|
if_clause = options.delete(:if)
|
66
66
|
unless_clause = options.delete(:unless)
|
67
|
-
send(:"before_#{attribute}
|
67
|
+
send(:"before_#{attribute}_validate", if: if_clause, unless: unless_clause) do |*_args|
|
68
68
|
validator_class.new(options.dup).validate(self)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|
data/lib/paperclip/version.rb
CHANGED
data/lib/paperclip.rb
CHANGED
@@ -25,37 +25,37 @@
|
|
25
25
|
#
|
26
26
|
# See the +has_attached_file+ documentation for more details.
|
27
27
|
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
28
|
+
require "erb"
|
29
|
+
require "digest"
|
30
|
+
require "tempfile"
|
31
|
+
require "paperclip/version"
|
32
|
+
require "paperclip/geometry_parser_factory"
|
33
|
+
require "paperclip/geometry_detector_factory"
|
34
|
+
require "paperclip/geometry"
|
35
|
+
require "paperclip/processor"
|
36
|
+
require "paperclip/processor_helpers"
|
37
|
+
require "paperclip/tempfile"
|
38
|
+
require "paperclip/thumbnail"
|
39
|
+
require "paperclip/interpolations/plural_cache"
|
40
|
+
require "paperclip/interpolations"
|
41
|
+
require "paperclip/tempfile_factory"
|
42
|
+
require "paperclip/style"
|
43
|
+
require "paperclip/attachment"
|
44
|
+
require "paperclip/storage"
|
45
|
+
require "paperclip/callbacks"
|
46
|
+
require "paperclip/file_command_content_type_detector"
|
47
|
+
require "paperclip/media_type_spoof_detector"
|
48
|
+
require "paperclip/content_type_detector"
|
49
|
+
require "paperclip/glue"
|
50
|
+
require "paperclip/errors"
|
51
|
+
require "paperclip/missing_attachment_styles"
|
52
|
+
require "paperclip/validators"
|
53
|
+
require "paperclip/logger"
|
54
|
+
require "paperclip/helpers"
|
55
|
+
require "paperclip/has_attached_file"
|
56
|
+
require "paperclip/attachment_registry"
|
57
|
+
require "paperclip/filename_cleaner"
|
58
|
+
require "paperclip/rails_environment"
|
59
59
|
|
60
60
|
begin
|
61
61
|
# Use mime/types/columnar if available, for reduced memory usage
|
@@ -64,12 +64,11 @@ rescue LoadError
|
|
64
64
|
require "mime/types"
|
65
65
|
end
|
66
66
|
|
67
|
-
require
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require 'terrapin'
|
67
|
+
require "marcel"
|
68
|
+
require "logger"
|
69
|
+
require "terrapin"
|
71
70
|
|
72
|
-
require
|
71
|
+
require "paperclip/railtie" if defined?(Rails::Railtie)
|
73
72
|
|
74
73
|
# The base module that gets included in ActiveRecord::Base. See the
|
75
74
|
# documentation for Paperclip::ClassMethods for more useful information.
|
@@ -98,6 +97,8 @@ module Paperclip
|
|
98
97
|
swallow_stderr: true,
|
99
98
|
use_exif_orientation: true,
|
100
99
|
whiny: true,
|
100
|
+
is_windows: Gem.win_platform?,
|
101
|
+
add_validation_errors_to: :both
|
101
102
|
}
|
102
103
|
end
|
103
104
|
|
@@ -200,15 +201,15 @@ module Paperclip
|
|
200
201
|
end
|
201
202
|
|
202
203
|
# This stuff needs to be run after Paperclip is defined.
|
203
|
-
require
|
204
|
-
require
|
205
|
-
require
|
206
|
-
require
|
207
|
-
require
|
208
|
-
require
|
209
|
-
require
|
210
|
-
require
|
211
|
-
require
|
212
|
-
require
|
213
|
-
require
|
214
|
-
require
|
204
|
+
require "paperclip/io_adapters/registry"
|
205
|
+
require "paperclip/io_adapters/abstract_adapter"
|
206
|
+
require "paperclip/io_adapters/empty_string_adapter"
|
207
|
+
require "paperclip/io_adapters/identity_adapter"
|
208
|
+
require "paperclip/io_adapters/file_adapter"
|
209
|
+
require "paperclip/io_adapters/stringio_adapter"
|
210
|
+
require "paperclip/io_adapters/data_uri_adapter"
|
211
|
+
require "paperclip/io_adapters/nil_adapter"
|
212
|
+
require "paperclip/io_adapters/attachment_adapter"
|
213
|
+
require "paperclip/io_adapters/uploaded_file_adapter"
|
214
|
+
require "paperclip/io_adapters/uri_adapter"
|
215
|
+
require "paperclip/io_adapters/http_url_proxy_adapter"
|
data/lib/tasks/paperclip.rake
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "paperclip/attachment_registry"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
module Task
|
5
5
|
def self.obtain_class
|
6
|
-
class_name = ENV[
|
6
|
+
class_name = ENV["CLASS"] || ENV["class"]
|
7
7
|
raise "Must specify CLASS" unless class_name
|
8
|
+
|
8
9
|
class_name
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.obtain_attachments(klass)
|
12
13
|
klass = Paperclip.class_for(klass.to_s)
|
13
|
-
name = ENV[
|
14
|
+
name = ENV["ATTACHMENT"] || ENV["attachment"]
|
14
15
|
|
15
16
|
attachment_names = Paperclip::AttachmentRegistry.names_for(klass)
|
16
17
|
|
17
|
-
if attachment_names.empty?
|
18
|
-
raise "Class #{klass.name} has no attachments specified"
|
19
|
-
end
|
18
|
+
raise "Class #{klass.name} has no attachments specified" if attachment_names.empty?
|
20
19
|
|
21
20
|
if name.present? && attachment_names.map(&:to_s).include?(name.to_s)
|
22
|
-
[
|
21
|
+
[name]
|
23
22
|
else
|
24
23
|
attachment_names
|
25
24
|
end
|
@@ -33,14 +32,14 @@ end
|
|
33
32
|
|
34
33
|
namespace :paperclip do
|
35
34
|
desc "Refreshes both metadata and thumbnails."
|
36
|
-
task :
|
35
|
+
task refresh: ["paperclip:refresh:metadata", "paperclip:refresh:thumbnails"]
|
37
36
|
|
38
37
|
namespace :refresh do
|
39
38
|
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma)."
|
40
|
-
task :
|
39
|
+
task thumbnails: :environment do
|
41
40
|
klass = Paperclip::Task.obtain_class
|
42
41
|
names = Paperclip::Task.obtain_attachments(klass)
|
43
|
-
styles = (ENV[
|
42
|
+
styles = (ENV["STYLES"] || ENV["styles"] || "").split(",").map(&:to_sym)
|
44
43
|
names.each do |name|
|
45
44
|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
46
45
|
attachment = instance.send(name)
|
@@ -59,7 +58,7 @@ namespace :paperclip do
|
|
59
58
|
end
|
60
59
|
|
61
60
|
desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
|
62
|
-
task :
|
61
|
+
task metadata: :environment do
|
63
62
|
klass = Paperclip::Task.obtain_class
|
64
63
|
names = Paperclip::Task.obtain_attachments(klass)
|
65
64
|
names.each do |name|
|
@@ -69,7 +68,7 @@ namespace :paperclip do
|
|
69
68
|
instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
|
70
69
|
instance.send("#{name}_content_type=", file.content_type.to_s.strip)
|
71
70
|
instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
|
72
|
-
instance.save(:
|
71
|
+
instance.save(validate: false)
|
73
72
|
else
|
74
73
|
true
|
75
74
|
end
|
@@ -78,45 +77,45 @@ namespace :paperclip do
|
|
78
77
|
end
|
79
78
|
|
80
79
|
desc "Regenerates missing thumbnail styles for all classes using Paperclip."
|
81
|
-
task :
|
80
|
+
task missing_styles: :environment do
|
82
81
|
Rails.application.eager_load!
|
83
82
|
Paperclip.missing_attachments_styles.each do |klass, attachment_definitions|
|
84
83
|
attachment_definitions.each do |attachment_name, missing_styles|
|
85
84
|
puts "Regenerating #{klass} -> #{attachment_name} -> #{missing_styles.inspect}"
|
86
|
-
ENV[
|
87
|
-
ENV[
|
88
|
-
ENV[
|
89
|
-
Rake::Task[
|
85
|
+
ENV["CLASS"] = klass.to_s
|
86
|
+
ENV["ATTACHMENT"] = attachment_name.to_s
|
87
|
+
ENV["STYLES"] = missing_styles.join(",")
|
88
|
+
Rake::Task["paperclip:refresh:thumbnails"].execute
|
90
89
|
end
|
91
90
|
end
|
92
91
|
Paperclip.save_current_attachments_styles!
|
93
92
|
end
|
94
93
|
|
95
94
|
desc "Regenerates fingerprints for a given CLASS (and optional ATTACHMENT). Useful when changing digest."
|
96
|
-
task :
|
95
|
+
task fingerprints: :environment do
|
97
96
|
klass = Paperclip::Task.obtain_class
|
98
97
|
names = Paperclip::Task.obtain_attachments(klass)
|
99
98
|
names.each do |name|
|
100
99
|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
101
100
|
attachment = instance.send(name)
|
102
101
|
attachment.assign(attachment)
|
103
|
-
instance.save(:
|
102
|
+
instance.save(validate: false)
|
104
103
|
end
|
105
104
|
end
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
108
|
desc "Cleans out invalid attachments. Useful after you've added new validations."
|
110
|
-
task :
|
109
|
+
task clean: :environment do
|
111
110
|
klass = Paperclip::Task.obtain_class
|
112
111
|
names = Paperclip::Task.obtain_attachments(klass)
|
113
112
|
names.each do |name|
|
114
113
|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
115
114
|
unless instance.valid?
|
116
|
-
attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
|
117
|
-
if attributes.any?{ |attribute| instance.errors[attribute].present? }
|
115
|
+
attributes = %w(file_size file_name content_type).map { |suffix| "#{name}_#{suffix}".to_sym }
|
116
|
+
if attributes.any? { |attribute| instance.errors[attribute].present? }
|
118
117
|
instance.send("#{name}=", nil)
|
119
|
-
instance.save(:
|
118
|
+
instance.save(validate: false)
|
120
119
|
end
|
121
120
|
end
|
122
121
|
end
|
@@ -124,7 +123,7 @@ namespace :paperclip do
|
|
124
123
|
end
|
125
124
|
|
126
125
|
desc "find missing attachments. Useful to know which attachments are broken"
|
127
|
-
task :
|
126
|
+
task find_broken_attachments: :environment do
|
128
127
|
klass = Paperclip::Task.obtain_class
|
129
128
|
names = Paperclip::Task.obtain_attachments(klass)
|
130
129
|
names.each do |name|
|
data/paperclip.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path("
|
2
|
-
require
|
1
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
|
+
require "paperclip/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "kt-paperclip"
|
@@ -14,41 +14,37 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
if File.exist?(
|
21
|
-
s.post_install_message = File.read("UPGRADING")
|
22
|
-
end
|
20
|
+
s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
|
23
21
|
|
24
22
|
s.requirements << "ImageMagick"
|
25
|
-
s.required_ruby_version = ">= 2.
|
23
|
+
s.required_ruby_version = ">= 2.3.0"
|
26
24
|
|
27
|
-
s.add_dependency(
|
28
|
-
s.add_dependency(
|
29
|
-
s.add_dependency(
|
30
|
-
s.add_dependency(
|
31
|
-
s.add_dependency(
|
25
|
+
s.add_dependency("activemodel", ">= 4.2.0")
|
26
|
+
s.add_dependency("activesupport", ">= 4.2.0")
|
27
|
+
s.add_dependency("mime-types")
|
28
|
+
s.add_dependency("marcel", "~> 1.0.1")
|
29
|
+
s.add_dependency("terrapin", "~> 0.6.0")
|
32
30
|
|
33
|
-
s.add_development_dependency(
|
34
|
-
s.add_development_dependency(
|
35
|
-
s.add_development_dependency(
|
36
|
-
s.add_development_dependency(
|
37
|
-
s.add_development_dependency(
|
38
|
-
s.add_development_dependency(
|
39
|
-
s.add_development_dependency(
|
40
|
-
s.add_development_dependency(
|
41
|
-
s.add_development_dependency(
|
42
|
-
s.add_development_dependency(
|
43
|
-
s.add_development_dependency(
|
44
|
-
s.add_development_dependency(
|
45
|
-
s.add_development_dependency(
|
46
|
-
s.add_development_dependency(
|
47
|
-
s.add_development_dependency(
|
48
|
-
s.add_development_dependency(
|
49
|
-
s.add_development_dependency(
|
50
|
-
s.add_development_dependency(
|
51
|
-
s.add_development_dependency(
|
52
|
-
s.add_development_dependency('generator_spec')
|
53
|
-
s.add_development_dependency('timecop')
|
31
|
+
s.add_development_dependency("activerecord", ">= 4.2.0")
|
32
|
+
s.add_development_dependency("appraisal")
|
33
|
+
s.add_development_dependency("aruba", "~> 0.9.0")
|
34
|
+
s.add_development_dependency("aws-sdk-s3")
|
35
|
+
s.add_development_dependency("bundler")
|
36
|
+
s.add_development_dependency("capybara")
|
37
|
+
s.add_development_dependency("cucumber-expressions")
|
38
|
+
s.add_development_dependency("cucumber-rails")
|
39
|
+
s.add_development_dependency("fakeweb")
|
40
|
+
s.add_development_dependency("fog-aws")
|
41
|
+
s.add_development_dependency("fog-local")
|
42
|
+
s.add_development_dependency("generator_spec")
|
43
|
+
s.add_development_dependency("launchy")
|
44
|
+
s.add_development_dependency("nokogiri")
|
45
|
+
s.add_development_dependency("railties")
|
46
|
+
s.add_development_dependency("rake")
|
47
|
+
s.add_development_dependency("rspec", "~> 3.0")
|
48
|
+
s.add_development_dependency("shoulda")
|
49
|
+
s.add_development_dependency("timecop")
|
54
50
|
end
|
data/shoulda_macros/paperclip.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "paperclip/matchers"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
# =Paperclip Shoulda Macros
|
@@ -13,8 +13,8 @@ module Paperclip
|
|
13
13
|
# This will test whether you have defined your attachment correctly by
|
14
14
|
# checking for all the required fields exist after the definition of the
|
15
15
|
# attachment.
|
16
|
-
def should_have_attached_file
|
17
|
-
klass = self.name.gsub(/Test$/,
|
16
|
+
def should_have_attached_file(name)
|
17
|
+
klass = self.name.gsub(/Test$/, "").constantize
|
18
18
|
matcher = have_attached_file name
|
19
19
|
should matcher.description do
|
20
20
|
assert_accepts(matcher, klass)
|
@@ -22,8 +22,8 @@ module Paperclip
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Tests for validations on the presence of the attachment.
|
25
|
-
def should_validate_attachment_presence
|
26
|
-
klass = self.name.gsub(/Test$/,
|
25
|
+
def should_validate_attachment_presence(name)
|
26
|
+
klass = self.name.gsub(/Test$/, "").constantize
|
27
27
|
matcher = validate_attachment_presence name
|
28
28
|
should matcher.description do
|
29
29
|
assert_accepts(matcher, klass)
|
@@ -34,8 +34,8 @@ module Paperclip
|
|
34
34
|
# options, :valid and :invalid. Both accept an array of strings. The
|
35
35
|
# strings should be a list of content types which will pass and fail
|
36
36
|
# validation, respectively.
|
37
|
-
def should_validate_attachment_content_type
|
38
|
-
klass = self.name.gsub(/Test$/,
|
37
|
+
def should_validate_attachment_content_type(name, options = {})
|
38
|
+
klass = self.name.gsub(/Test$/, "").constantize
|
39
39
|
valid = [options[:valid]].flatten
|
40
40
|
invalid = [options[:invalid]].flatten
|
41
41
|
matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
|
@@ -50,10 +50,10 @@ module Paperclip
|
|
50
50
|
# :less_than checks that a file is less than a certain size, :greater_than
|
51
51
|
# checks that a file is more than a certain size, and :in takes a Range or
|
52
52
|
# Array which specifies the lower and upper limits of the file size.
|
53
|
-
def should_validate_attachment_size
|
54
|
-
klass = self.name.gsub(/Test$/,
|
53
|
+
def should_validate_attachment_size(name, options = {})
|
54
|
+
klass = self.name.gsub(/Test$/, "").constantize
|
55
55
|
min = options[:greater_than] || (options[:in] && options[:in].first) || 0
|
56
|
-
max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
|
56
|
+
max = options[:less_than] || (options[:in] && options[:in].last) || (1.0 / 0)
|
57
57
|
range = (min..max)
|
58
58
|
matcher = validate_attachment_size(name).in(range)
|
59
59
|
should matcher.description do
|
@@ -65,17 +65,17 @@ module Paperclip
|
|
65
65
|
#
|
66
66
|
# @example
|
67
67
|
# stub_paperclip_s3('user', 'avatar', 'png')
|
68
|
-
def stub_paperclip_s3(model, attachment,
|
68
|
+
def stub_paperclip_s3(model, attachment, _extension)
|
69
69
|
definition = model.gsub(" ", "_").classify.constantize.
|
70
|
-
|
70
|
+
attachment_definitions[attachment.to_sym]
|
71
71
|
|
72
72
|
path = "http://s3.amazonaws.com/:id/#{definition[:path]}"
|
73
|
-
path.gsub!(/:([^\/\.]+)/) do |
|
73
|
+
path.gsub!(/:([^\/\.]+)/) do |_match|
|
74
74
|
"([^\/\.]+)"
|
75
75
|
end
|
76
76
|
|
77
77
|
begin
|
78
|
-
FakeWeb.register_uri(:put, Regexp.new(path), :
|
78
|
+
FakeWeb.register_uri(:put, Regexp.new(path), body: "OK")
|
79
79
|
rescue NameError
|
80
80
|
raise NameError, "the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
|
81
81
|
end
|
@@ -104,11 +104,11 @@ module Paperclip
|
|
104
104
|
end
|
105
105
|
|
106
106
|
if defined?(ActionDispatch::Integration::Session)
|
107
|
-
class ActionDispatch::IntegrationTest::Session
|
107
|
+
class ActionDispatch::IntegrationTest::Session #:nodoc:
|
108
108
|
include Paperclip::Shoulda
|
109
109
|
end
|
110
110
|
elsif defined?(ActionController::Integration::Session)
|
111
|
-
class ActionController::Integration::Session
|
111
|
+
class ActionController::Integration::Session #:nodoc:
|
112
112
|
include Paperclip::Shoulda
|
113
113
|
end
|
114
114
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Attachment Definitions" do
|
4
|
-
it
|
4
|
+
it "returns all of the attachments on the class" do
|
5
5
|
reset_class "Dummy"
|
6
|
-
Dummy.has_attached_file :avatar,
|
7
|
-
Dummy.has_attached_file :other_attachment,
|
6
|
+
Dummy.has_attached_file :avatar, path: "abc"
|
7
|
+
Dummy.has_attached_file :other_attachment, url: "123"
|
8
8
|
Dummy.do_not_validate_attachment_file_type :avatar
|
9
|
-
expected = {avatar: {path: "abc"}, other_attachment: {url: "123"}}
|
9
|
+
expected = { avatar: { path: "abc" }, other_attachment: { url: "123" } }
|
10
10
|
|
11
11
|
expect(Dummy.attachment_definitions).to eq expected
|
12
12
|
end
|