kt-paperclip 5.4.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- 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 +12 -12
- 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/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- 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 +3 -3
- 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 +9 -7
- 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 +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- 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 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- 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 +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- 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 +11 -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 +42 -26
- 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 +80 -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 +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -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 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- 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/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 +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
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,7 +17,7 @@ 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
23
|
# This method is a shortcut to validator classes that is in
|
@@ -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,12 @@ rescue LoadError
|
|
64
64
|
require "mime/types"
|
65
65
|
end
|
66
66
|
|
67
|
-
require
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require
|
67
|
+
require "mimemagic"
|
68
|
+
require "mimemagic/overlay"
|
69
|
+
require "logger"
|
70
|
+
require "terrapin"
|
71
71
|
|
72
|
-
require
|
72
|
+
require "paperclip/railtie" if defined?(Rails::Railtie)
|
73
73
|
|
74
74
|
# The base module that gets included in ActiveRecord::Base. See the
|
75
75
|
# documentation for Paperclip::ClassMethods for more useful information.
|
@@ -98,6 +98,7 @@ module Paperclip
|
|
98
98
|
swallow_stderr: true,
|
99
99
|
use_exif_orientation: true,
|
100
100
|
whiny: true,
|
101
|
+
is_windows: Gem.win_platform?
|
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"
|
@@ -7,48 +7,44 @@ 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/
|
10
|
+
s.homepage = "https://github.com/kreeti/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"
|
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
23
|
s.required_ruby_version = ">= 2.1.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("mimemagic", "~> 0.3.0")
|
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", "4.0.3") # TODO: investigate failures on 4.0.4
|
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
|
@@ -1,78 +1,77 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
|
-
describe
|
3
|
+
describe "Attachment Processing" do
|
5
4
|
before { rebuild_class }
|
6
5
|
|
7
|
-
context
|
8
|
-
it
|
6
|
+
context "using validates_attachment_content_type" do
|
7
|
+
it "processes attachments given a valid assignment" do
|
9
8
|
file = File.new(fixture_file("5k.png"))
|
10
9
|
Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
|
11
10
|
instance = Dummy.new
|
12
11
|
attachment = instance.avatar
|
13
|
-
attachment.
|
12
|
+
expect(attachment).to receive(:post_process_styles)
|
14
13
|
|
15
14
|
attachment.assign(file)
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
17
|
+
it "does not process attachments given an invalid assignment with :not" do
|
19
18
|
file = File.new(fixture_file("5k.png"))
|
20
19
|
Dummy.validates_attachment_content_type :avatar, not: "image/png"
|
21
20
|
instance = Dummy.new
|
22
21
|
attachment = instance.avatar
|
23
|
-
attachment.
|
22
|
+
expect(attachment).not_to receive(:post_process_styles)
|
24
23
|
|
25
24
|
attachment.assign(file)
|
26
25
|
end
|
27
26
|
|
28
|
-
it
|
27
|
+
it "does not process attachments given an invalid assignment with :content_type" do
|
29
28
|
file = File.new(fixture_file("5k.png"))
|
30
29
|
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff"
|
31
30
|
instance = Dummy.new
|
32
31
|
attachment = instance.avatar
|
33
|
-
attachment.
|
32
|
+
expect(attachment).not_to receive(:post_process_styles)
|
34
33
|
|
35
34
|
attachment.assign(file)
|
36
35
|
end
|
37
36
|
|
38
|
-
it
|
37
|
+
it "allows what would be an invalid assignment when validation :if clause returns false" do
|
39
38
|
invalid_assignment = File.new(fixture_file("5k.png"))
|
40
|
-
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda{false}
|
39
|
+
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda { false }
|
41
40
|
instance = Dummy.new
|
42
41
|
attachment = instance.avatar
|
43
|
-
attachment.
|
42
|
+
expect(attachment).to receive(:post_process_styles)
|
44
43
|
|
45
44
|
attachment.assign(invalid_assignment)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
context
|
50
|
-
it
|
48
|
+
context "using validates_attachment" do
|
49
|
+
it "processes attachments given a valid assignment" do
|
51
50
|
file = File.new(fixture_file("5k.png"))
|
52
|
-
Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"}
|
51
|
+
Dummy.validates_attachment :avatar, content_type: { content_type: "image/png" }
|
53
52
|
instance = Dummy.new
|
54
53
|
attachment = instance.avatar
|
55
|
-
attachment.
|
54
|
+
expect(attachment).to receive(:post_process_styles)
|
56
55
|
|
57
56
|
attachment.assign(file)
|
58
57
|
end
|
59
58
|
|
60
|
-
it
|
59
|
+
it "does not process attachments given an invalid assignment with :not" do
|
61
60
|
file = File.new(fixture_file("5k.png"))
|
62
|
-
Dummy.validates_attachment :avatar, content_type: {not: "image/png"}
|
61
|
+
Dummy.validates_attachment :avatar, content_type: { not: "image/png" }
|
63
62
|
instance = Dummy.new
|
64
63
|
attachment = instance.avatar
|
65
|
-
attachment.
|
64
|
+
expect(attachment).not_to receive(:post_process_styles)
|
66
65
|
|
67
66
|
attachment.assign(file)
|
68
67
|
end
|
69
68
|
|
70
|
-
it
|
69
|
+
it "does not process attachments given an invalid assignment with :content_type" do
|
71
70
|
file = File.new(fixture_file("5k.png"))
|
72
|
-
Dummy.validates_attachment :avatar, content_type: {content_type: "image/tiff"}
|
71
|
+
Dummy.validates_attachment :avatar, content_type: { content_type: "image/tiff" }
|
73
72
|
instance = Dummy.new
|
74
73
|
attachment = instance.avatar
|
75
|
-
attachment.
|
74
|
+
expect(attachment).not_to receive(:post_process_styles)
|
76
75
|
|
77
76
|
attachment.assign(file)
|
78
77
|
end
|