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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +3 -0
  3. data/.hound.yml +27 -32
  4. data/.travis.yml +23 -2
  5. data/Appraisals +17 -0
  6. data/Gemfile +9 -7
  7. data/NEWS +21 -0
  8. data/README.md +27 -37
  9. data/Rakefile +29 -21
  10. data/UPGRADING +3 -3
  11. data/features/basic_integration.feature +4 -0
  12. data/features/migration.feature +10 -51
  13. data/features/step_definitions/attachment_steps.rb +12 -12
  14. data/features/step_definitions/html_steps.rb +5 -5
  15. data/features/step_definitions/rails_steps.rb +29 -9
  16. data/features/step_definitions/s3_steps.rb +3 -3
  17. data/features/step_definitions/web_steps.rb +5 -6
  18. data/features/support/env.rb +4 -4
  19. data/features/support/fakeweb.rb +3 -5
  20. data/features/support/file_helpers.rb +2 -2
  21. data/features/support/paths.rb +4 -4
  22. data/features/support/rails.rb +7 -7
  23. data/features/support/selectors.rb +1 -1
  24. data/gemfiles/4.2.gemfile +7 -4
  25. data/gemfiles/5.0.gemfile +7 -4
  26. data/gemfiles/5.1.gemfile +20 -0
  27. data/gemfiles/5.2.gemfile +20 -0
  28. data/gemfiles/6.0.gemfile +20 -0
  29. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  30. data/lib/paperclip/attachment.rb +102 -104
  31. data/lib/paperclip/attachment_registry.rb +2 -2
  32. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  33. data/lib/paperclip/filename_cleaner.rb +0 -1
  34. data/lib/paperclip/geometry.rb +18 -19
  35. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  36. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  37. data/lib/paperclip/glue.rb +3 -3
  38. data/lib/paperclip/has_attached_file.rb +5 -4
  39. data/lib/paperclip/helpers.rb +3 -3
  40. data/lib/paperclip/interpolations.rb +42 -38
  41. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  42. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  43. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  44. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  45. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
  46. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  47. data/lib/paperclip/io_adapters/registry.rb +1 -1
  48. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  49. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  50. data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
  51. data/lib/paperclip/logger.rb +1 -1
  52. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  53. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  54. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  55. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  56. data/lib/paperclip/matchers.rb +4 -4
  57. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  58. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  59. data/lib/paperclip/processor.rb +13 -6
  60. data/lib/paperclip/processor_helpers.rb +3 -1
  61. data/lib/paperclip/rails_environment.rb +1 -5
  62. data/lib/paperclip/railtie.rb +5 -5
  63. data/lib/paperclip/schema.rb +18 -14
  64. data/lib/paperclip/storage/filesystem.rb +5 -7
  65. data/lib/paperclip/storage/fog.rb +36 -32
  66. data/lib/paperclip/storage/s3.rb +67 -75
  67. data/lib/paperclip/style.rb +3 -6
  68. data/lib/paperclip/tempfile.rb +4 -5
  69. data/lib/paperclip/tempfile_factory.rb +0 -1
  70. data/lib/paperclip/thumbnail.rb +11 -11
  71. data/lib/paperclip/url_generator.rb +5 -12
  72. data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
  73. data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
  74. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  75. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  76. data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
  77. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  78. data/lib/paperclip/validators.rb +12 -13
  79. data/lib/paperclip/version.rb +1 -3
  80. data/lib/paperclip.rb +49 -48
  81. data/lib/tasks/paperclip.rake +23 -24
  82. data/paperclip.gemspec +29 -33
  83. data/shoulda_macros/paperclip.rb +16 -16
  84. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  85. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  86. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  87. data/spec/paperclip/attachment_spec.rb +238 -196
  88. data/spec/paperclip/content_type_detector_spec.rb +11 -12
  89. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  90. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  91. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  92. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  93. data/spec/paperclip/geometry_spec.rb +24 -24
  94. data/spec/paperclip/glue_spec.rb +3 -5
  95. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  96. data/spec/paperclip/integration_spec.rb +111 -77
  97. data/spec/paperclip/interpolations_spec.rb +101 -93
  98. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  99. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  100. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  101. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  102. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  103. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
  104. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  105. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  106. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  107. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  108. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  109. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
  110. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  111. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  112. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  113. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  114. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  115. data/spec/paperclip/meta_class_spec.rb +3 -3
  116. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  117. data/spec/paperclip/paperclip_spec.rb +15 -11
  118. data/spec/paperclip/plural_cache_spec.rb +8 -8
  119. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  120. data/spec/paperclip/processor_spec.rb +8 -8
  121. data/spec/paperclip/rails_environment_spec.rb +7 -10
  122. data/spec/paperclip/rake_spec.rb +39 -39
  123. data/spec/paperclip/schema_spec.rb +57 -53
  124. data/spec/paperclip/storage/filesystem_spec.rb +6 -6
  125. data/spec/paperclip/storage/fog_spec.rb +76 -82
  126. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  127. data/spec/paperclip/storage/s3_spec.rb +585 -583
  128. data/spec/paperclip/style_spec.rb +67 -71
  129. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  130. data/spec/paperclip/thumbnail_spec.rb +68 -67
  131. data/spec/paperclip/url_generator_spec.rb +18 -29
  132. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
  133. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
  134. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  135. data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
  136. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  137. data/spec/paperclip/validators_spec.rb +40 -40
  138. data/spec/spec_helper.rb +21 -23
  139. data/spec/support/assertions.rb +8 -6
  140. data/spec/support/fake_model.rb +1 -2
  141. data/spec/support/fake_rails.rb +1 -1
  142. data/spec/support/matchers/exist.rb +1 -1
  143. data/spec/support/matchers/have_column.rb +1 -1
  144. data/spec/support/mock_url_generator_builder.rb +2 -3
  145. data/spec/support/model_reconstruction.rb +16 -12
  146. data/spec/support/reporting.rb +1 -1
  147. data/spec/support/test_data.rb +2 -2
  148. metadata +49 -105
  149. data/lib/kt-paperclip.rb +0 -1
  150. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,12 +1,12 @@
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'
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.has_key?(validator_kind)
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}_post_process", :if => if_clause, :unless => unless_clause) do |*args|
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
@@ -1,5 +1,3 @@
1
1
  module Paperclip
2
- unless defined?(Paperclip::VERSION)
3
- VERSION = "5.4.0".freeze
4
- end
2
+ VERSION = "6.2.0" unless defined?(Paperclip::VERSION)
5
3
  end
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 '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'
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 'mimemagic'
68
- require 'mimemagic/overlay'
69
- require 'logger'
70
- require 'terrapin'
67
+ require "mimemagic"
68
+ require "mimemagic/overlay"
69
+ require "logger"
70
+ require "terrapin"
71
71
 
72
- require 'paperclip/railtie' if defined?(Rails::Railtie)
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 'paperclip/io_adapters/registry'
204
- require 'paperclip/io_adapters/abstract_adapter'
205
- require 'paperclip/io_adapters/empty_string_adapter'
206
- require 'paperclip/io_adapters/identity_adapter'
207
- require 'paperclip/io_adapters/file_adapter'
208
- require 'paperclip/io_adapters/stringio_adapter'
209
- require 'paperclip/io_adapters/data_uri_adapter'
210
- require 'paperclip/io_adapters/nil_adapter'
211
- require 'paperclip/io_adapters/attachment_adapter'
212
- require 'paperclip/io_adapters/uploaded_file_adapter'
213
- require 'paperclip/io_adapters/uri_adapter'
214
- require 'paperclip/io_adapters/http_url_proxy_adapter'
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"
@@ -1,25 +1,24 @@
1
- require 'paperclip/attachment_registry'
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['CLASS'] || ENV['class']
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['ATTACHMENT'] || ENV['attachment']
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
- [ name ]
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 :refresh => ["paperclip:refresh:metadata", "paperclip:refresh:thumbnails"]
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 :thumbnails => :environment do
39
+ task thumbnails: :environment do
41
40
  klass = Paperclip::Task.obtain_class
42
41
  names = Paperclip::Task.obtain_attachments(klass)
43
- styles = (ENV['STYLES'] || ENV['styles'] || '').split(',').map(&:to_sym)
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 :metadata => :environment do
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(:validate => false)
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 :missing_styles => :environment do
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['CLASS'] = klass.to_s
87
- ENV['ATTACHMENT'] = attachment_name.to_s
88
- ENV['STYLES'] = missing_styles.join(',')
89
- Rake::Task['paperclip:refresh:thumbnails'].execute
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 :fingerprints => :environment do
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(:validate => false)
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 :clean => :environment do
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(:validate => false)
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 :find_broken_attachments => :environment do
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("../lib", __FILE__)
2
- require 'paperclip/version'
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/kt-paperclip"
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?('UPGRADING')
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('activemodel', '>= 4.2.0', '< 6.0')
28
- s.add_dependency('activesupport', '>= 4.2.0', '< 6.0')
29
- s.add_dependency('terrapin', '~> 0.6.0')
30
- s.add_dependency('mime-types')
31
- s.add_dependency('mimemagic', '~> 0.3.8')
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('activerecord', '>= 4.2.0', '< 6.0')
34
- s.add_development_dependency('shoulda')
35
- s.add_development_dependency('rspec', '~> 3.0')
36
- s.add_development_dependency('appraisal')
37
- s.add_development_dependency('mocha')
38
- s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
39
- s.add_development_dependency('bourne', '< 1.6')
40
- s.add_development_dependency('cucumber-rails')
41
- s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
42
- s.add_development_dependency('aruba', '~> 0.9.0')
43
- s.add_development_dependency('nokogiri')
44
- s.add_development_dependency('capybara')
45
- s.add_development_dependency('bundler')
46
- s.add_development_dependency('fog-aws')
47
- s.add_development_dependency('fog-local')
48
- s.add_development_dependency('launchy')
49
- s.add_development_dependency('rake')
50
- s.add_development_dependency('fakeweb')
51
- s.add_development_dependency('railties', '>= 4.2.0', '< 6.0')
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
@@ -1,4 +1,4 @@
1
- require 'paperclip/matchers'
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 name
17
- klass = self.name.gsub(/Test$/, '').constantize
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 name
26
- klass = self.name.gsub(/Test$/, '').constantize
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 name, options = {}
38
- klass = self.name.gsub(/Test$/, '').constantize
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 name, options = {}
54
- klass = self.name.gsub(/Test$/, '').constantize
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, extension)
68
+ def stub_paperclip_s3(model, attachment, _extension)
69
69
  definition = model.gsub(" ", "_").classify.constantize.
70
- attachment_definitions[attachment.to_sym]
70
+ attachment_definitions[attachment.to_sym]
71
71
 
72
72
  path = "http://s3.amazonaws.com/:id/#{definition[:path]}"
73
- path.gsub!(/:([^\/\.]+)/) do |match|
73
+ path.gsub!(/:([^\/\.]+)/) do |_match|
74
74
  "([^\/\.]+)"
75
75
  end
76
76
 
77
77
  begin
78
- FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
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 #:nodoc:
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 #:nodoc:
111
+ class ActionController::Integration::Session #:nodoc:
112
112
  include Paperclip::Shoulda
113
113
  end
114
114
  end
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe "Attachment Definitions" do
4
- it 'returns all of the attachments on the class' do
4
+ it "returns all of the attachments on the class" do
5
5
  reset_class "Dummy"
6
- Dummy.has_attached_file :avatar, {path: "abc"}
7
- Dummy.has_attached_file :other_attachment, {url: "123"}
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
- # encoding: utf-8
2
- require 'spec_helper'
1
+ require "spec_helper"
3
2
 
4
- describe 'Attachment Processing' do
3
+ describe "Attachment Processing" do
5
4
  before { rebuild_class }
6
5
 
7
- context 'using validates_attachment_content_type' do
8
- it 'processes attachments given a valid assignment' do
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.expects(:post_process_styles)
12
+ expect(attachment).to receive(:post_process_styles)
14
13
 
15
14
  attachment.assign(file)
16
15
  end
17
16
 
18
- it 'does not process attachments given an invalid assignment with :not' do
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.expects(:post_process_styles).never
22
+ expect(attachment).not_to receive(:post_process_styles)
24
23
 
25
24
  attachment.assign(file)
26
25
  end
27
26
 
28
- it 'does not process attachments given an invalid assignment with :content_type' do
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.expects(:post_process_styles).never
32
+ expect(attachment).not_to receive(:post_process_styles)
34
33
 
35
34
  attachment.assign(file)
36
35
  end
37
36
 
38
- it 'allows what would be an invalid assignment when validation :if clause returns false' do
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.expects(:post_process_styles)
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 'using validates_attachment' do
50
- it 'processes attachments given a valid assignment' do
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.expects(:post_process_styles)
54
+ expect(attachment).to receive(:post_process_styles)
56
55
 
57
56
  attachment.assign(file)
58
57
  end
59
58
 
60
- it 'does not process attachments given an invalid assignment with :not' do
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.expects(:post_process_styles).never
64
+ expect(attachment).not_to receive(:post_process_styles)
66
65
 
67
66
  attachment.assign(file)
68
67
  end
69
68
 
70
- it 'does not process attachments given an invalid assignment with :content_type' do
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.expects(:post_process_styles).never
74
+ expect(attachment).not_to receive(:post_process_styles)
76
75
 
77
76
  attachment.assign(file)
78
77
  end