paperclip 4.3.7 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -9
  3. data/Appraisals +22 -6
  4. data/CONTRIBUTING.md +16 -5
  5. data/Gemfile +2 -8
  6. data/LICENSE +1 -1
  7. data/NEWS +39 -27
  8. data/README.md +123 -101
  9. data/UPGRADING +12 -9
  10. data/features/basic_integration.feature +1 -0
  11. data/features/migration.feature +0 -24
  12. data/features/step_definitions/rails_steps.rb +0 -6
  13. data/features/step_definitions/s3_steps.rb +2 -2
  14. data/gemfiles/{4.1.gemfile → 4.2.awsv2.0.gemfile} +4 -6
  15. data/gemfiles/4.2.awsv2.1.gemfile +17 -0
  16. data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -0
  17. data/gemfiles/5.0.awsv2.0.gemfile +17 -0
  18. data/gemfiles/5.0.awsv2.1.gemfile +17 -0
  19. data/gemfiles/{3.2.gemfile → 5.0.awsv2.gemfile} +2 -1
  20. data/lib/paperclip.rb +2 -3
  21. data/lib/paperclip/attachment.rb +12 -10
  22. data/lib/paperclip/attachment_registry.rb +2 -1
  23. data/lib/paperclip/callbacks.rb +8 -6
  24. data/lib/paperclip/content_type_detector.rb +3 -2
  25. data/lib/paperclip/errors.rb +3 -1
  26. data/lib/paperclip/glue.rb +1 -1
  27. data/lib/paperclip/has_attached_file.rb +7 -1
  28. data/lib/paperclip/helpers.rb +14 -10
  29. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  30. data/lib/paperclip/io_adapters/uri_adapter.rb +12 -29
  31. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  32. data/lib/paperclip/schema.rb +2 -8
  33. data/lib/paperclip/storage/fog.rb +9 -6
  34. data/lib/paperclip/storage/s3.rb +42 -40
  35. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  36. data/lib/paperclip/version.rb +3 -1
  37. data/lib/tasks/paperclip.rake +1 -1
  38. data/paperclip.gemspec +11 -8
  39. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  40. data/spec/paperclip/attachment_registry_spec.rb +28 -0
  41. data/spec/paperclip/attachment_spec.rb +33 -10
  42. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  43. data/spec/paperclip/integration_spec.rb +4 -3
  44. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +17 -8
  45. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +32 -30
  46. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  47. data/spec/paperclip/paperclip_spec.rb +3 -33
  48. data/spec/paperclip/storage/fog_spec.rb +10 -0
  49. data/spec/paperclip/storage/s3_live_spec.rb +8 -4
  50. data/spec/paperclip/storage/s3_spec.rb +213 -156
  51. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  52. data/spec/paperclip/validators_spec.rb +3 -3
  53. data/spec/spec_helper.rb +3 -1
  54. data/spec/support/assertions.rb +7 -0
  55. data/spec/support/model_reconstruction.rb +9 -1
  56. data/spec/support/reporting.rb +11 -0
  57. metadata +44 -37
  58. data/cucumber/paperclip_steps.rb +0 -6
  59. data/lib/paperclip/deprecations.rb +0 -42
  60. data/lib/paperclip/locales/de.yml +0 -18
  61. data/lib/paperclip/locales/es.yml +0 -18
  62. data/lib/paperclip/locales/ja.yml +0 -18
  63. data/lib/paperclip/locales/pt-BR.yml +0 -18
  64. data/lib/paperclip/locales/zh-CN.yml +0 -18
  65. data/lib/paperclip/locales/zh-HK.yml +0 -18
  66. data/lib/paperclip/locales/zh-TW.yml +0 -18
  67. data/spec/paperclip/deprecations_spec.rb +0 -65
  68. data/spec/support/deprecations.rb +0 -9
  69. data/spec/support/rails_helpers.rb +0 -7
data/UPGRADING CHANGED
@@ -1,14 +1,17 @@
1
1
  ##################################################
2
- # NOTE FOR UPGRADING FROM PRE-3.0 VERSION #
2
+ # NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
3
3
  ##################################################
4
4
 
5
- Paperclip 3.0 introduces a non-backward compatible change in your attachment
6
- path. This will help to prevent attachment name clashes when you have
7
- multiple attachments with the same name. If you didn't alter your
8
- attachment's path and are using Paperclip's default, you'll have to add
9
- `:path` and `:url` to your `has_attached_file` definition. For example:
5
+ Paperclip is now compatible with aws-sdk >= 2.0.0.
10
6
 
11
- has_attached_file :avatar,
12
- :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
13
- :url => "/system/:attachment/:id/:style/:filename"
7
+ If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
8
+ changes:
14
9
 
10
+ * You must set the `s3_region`
11
+ * If you are explicitly setting permissions anywhere, such as in an initializer,
12
+ note that the format of the permissions changed from using an underscore to
13
+ using a hyphen. For example, `:public_read` needs to be changed to
14
+ `public-read`.
15
+
16
+ For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
17
+ http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
@@ -69,6 +69,7 @@ Feature: Rails integration
69
69
  bucket: paperclip
70
70
  access_key_id: access_key
71
71
  secret_access_key: secret_key
72
+ s3_region: us-west-2
72
73
  """
73
74
  And I start the rails application
74
75
  When I go to the new user page
@@ -68,27 +68,3 @@ Feature: Migration
68
68
 
69
69
  When I rollback a migration
70
70
  Then I should not have attachment columns for "avatar"
71
-
72
- Scenario: Rails 3.2 change method
73
- Given I am using Rails newer than 3.1
74
- When I write to "db/migrate/01_create_users.rb" with:
75
- """
76
- class CreateUsers < ActiveRecord::Migration
77
- def self.up
78
- create_table :users
79
- end
80
- end
81
- """
82
- When I write to "db/migrate/02_add_attachment_to_users.rb" with:
83
- """
84
- class AddAttachmentToUsers < ActiveRecord::Migration
85
- def change
86
- add_attachment :users, :avatar
87
- end
88
- end
89
- """
90
- And I run a migration
91
- Then I should have attachment columns for "avatar"
92
-
93
- When I rollback a migration
94
- Then I should not have attachment columns for "avatar"
@@ -190,12 +190,6 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
190
190
  comment_out_gem_in_gemfile gemname
191
191
  end
192
192
 
193
- Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
194
- if framework_version < version
195
- pending "Not supported in Rails < #{version}"
196
- end
197
- end
198
-
199
193
  Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
200
194
  filename = "#{directory}/#{processor}.rb"
201
195
  cd(".") do
@@ -1,11 +1,11 @@
1
1
  When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
2
2
  definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
3
- path = "https://paperclip.s3.amazonaws.com#{definition[:path]}"
3
+ path = "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
4
4
  path.gsub!(':filename', File.basename(file_path))
5
5
  path.gsub!(/:([^\/\.]+)/) do |match|
6
6
  "([^\/\.]+)"
7
7
  end
8
- FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
8
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "<xml></xml>")
9
9
  step "I attach the file \"#{file_path}\" to \"#{field}\""
10
10
  end
11
11
 
@@ -3,15 +3,13 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
- gem "jruby-openssl", :platforms => :jruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "rubysl", :platforms => :rbx
9
- gem "racc", :platforms => :rbx
10
6
  gem "pry"
11
- gem "rails", "~> 4.1.0"
7
+ gem "rails", "~> 4.2.0"
8
+ gem "aws-sdk", "~> 2.0.0"
12
9
 
13
10
  group :development, :test do
14
- gem "mime-types", "~> 1.16"
11
+ gem "activerecord-import"
12
+ gem "mime-types"
15
13
  gem "builder"
16
14
  gem "rubocop", :require => false
17
15
  end
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "~> 4.2.0"
8
+ gem "aws-sdk", "~> 2.1.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types", ">= 1.16", "< 4"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -9,6 +9,7 @@ gem "rubysl", :platforms => :rbx
9
9
  gem "racc", :platforms => :rbx
10
10
  gem "pry"
11
11
  gem "rails", "~> 4.2.0"
12
+ gem "aws-sdk", "~> 2.0"
12
13
 
13
14
  group :development, :test do
14
15
  gem "mime-types", "~> 1.16"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "5.0.0"
8
+ gem "aws-sdk", "~> 2.0.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types", ">= 1.16", "< 4"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "5.0.0"
8
+ gem "aws-sdk", "~> 2.1.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -8,7 +8,8 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
8
  gem "rubysl", :platforms => :rbx
9
9
  gem "racc", :platforms => :rbx
10
10
  gem "pry"
11
- gem "rails", "~> 3.2.0"
11
+ gem "rails", "~> 5.0.0"
12
+ gem "aws-sdk", "~> 2.0"
12
13
 
13
14
  group :development, :test do
14
15
  gem "mime-types", "~> 1.16"
data/lib/paperclip.rb CHANGED
@@ -56,7 +56,6 @@ require 'paperclip/has_attached_file'
56
56
  require 'paperclip/attachment_registry'
57
57
  require 'paperclip/filename_cleaner'
58
58
  require 'paperclip/rails_environment'
59
- require "paperclip/deprecations"
60
59
 
61
60
  begin
62
61
  # Use mime/types/columnar if available, for reduced memory usage
@@ -98,7 +97,8 @@ module Paperclip
98
97
  :log_command => true,
99
98
  :swallow_stderr => true,
100
99
  :content_type_mappings => {},
101
- :use_exif_orientation => true
100
+ :use_exif_orientation => true,
101
+ :read_timeout => nil
102
102
  }
103
103
  end
104
104
 
@@ -192,7 +192,6 @@ module Paperclip
192
192
  # end
193
193
  # end
194
194
  def has_attached_file(name, options = {})
195
- Paperclip::Deprecations.check
196
195
  HasAttachedFile.define_on(self, name, options)
197
196
  end
198
197
  end
@@ -2,6 +2,7 @@
2
2
  require 'uri'
3
3
  require 'paperclip/url_generator'
4
4
  require 'active_support/deprecation'
5
+ require 'active_support/core_ext/string/inflections'
5
6
 
6
7
  module Paperclip
7
8
  # The Attachment class manages the files for a given attachment. It saves
@@ -49,7 +50,8 @@ module Paperclip
49
50
  # +url+ - a relative URL of the attachment. This is interpolated using +interpolator+
50
51
  # +path+ - where on the filesystem to store the attachment. This is interpolated using +interpolator+
51
52
  # +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
52
- # +only_process+ - style args to be run through the post-processor. This defaults to the empty list
53
+ # +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
54
+ # a special case that indicates all styles should be processed)
53
55
  # +default_url+ - a URL for the missing image
54
56
  # +default_style+ - the style to use when an argument is not specified e.g. #url, #path
55
57
  # +storage+ - the storage mechanism. Defaults to :filesystem
@@ -322,7 +324,7 @@ module Paperclip
322
324
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options[:hash_digest]).new, @options[:hash_secret], data)
323
325
  end
324
326
 
325
- # This method really shouldn't be called that often. It's expected use is
327
+ # This method really shouldn't be called that often. Its expected use is
326
328
  # in the paperclip:refresh rake task and that's it. It will regenerate all
327
329
  # thumbnails forcefully, by reobtaining the original file and going through
328
330
  # the post-process again.
@@ -347,7 +349,7 @@ module Paperclip
347
349
 
348
350
  # Returns true if a file has been assigned.
349
351
  def file?
350
- !original_filename.blank?
352
+ original_filename.present?
351
353
  end
352
354
 
353
355
  alias :present? :file?
@@ -426,7 +428,7 @@ module Paperclip
426
428
  def assign_attributes
427
429
  @queued_for_write[:original] = @file
428
430
  assign_file_information
429
- assign_fingerprint(@file.fingerprint)
431
+ assign_fingerprint { @file.fingerprint }
430
432
  assign_timestamps
431
433
  end
432
434
 
@@ -436,9 +438,9 @@ module Paperclip
436
438
  instance_write(:file_size, @file.size)
437
439
  end
438
440
 
439
- def assign_fingerprint(fingerprint)
441
+ def assign_fingerprint
440
442
  if instance_respond_to?(:fingerprint)
441
- instance_write(:fingerprint, fingerprint)
443
+ instance_write(:fingerprint, yield)
442
444
  end
443
445
  end
444
446
 
@@ -464,7 +466,7 @@ module Paperclip
464
466
 
465
467
  def reset_file_if_original_reprocessed
466
468
  instance_write(:file_size, @queued_for_write[:original].size)
467
- assign_fingerprint(@queued_for_write[:original].fingerprint)
469
+ assign_fingerprint { @queued_for_write[:original].fingerprint }
468
470
  reset_updater
469
471
  end
470
472
 
@@ -500,7 +502,7 @@ module Paperclip
500
502
 
501
503
  instance.run_paperclip_callbacks(:post_process) do
502
504
  instance.run_paperclip_callbacks(:"#{name}_post_process") do
503
- unless @options[:check_validity_before_processing] && instance.errors.any?
505
+ if !@options[:check_validity_before_processing] || !instance.errors.any?
504
506
  post_process_styles(*style_args)
505
507
  end
506
508
  end
@@ -521,7 +523,7 @@ module Paperclip
521
523
 
522
524
  @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
523
525
  file = Paperclip.processor(processor).make(file, style.processor_options, self)
524
- intermediate_files << file
526
+ intermediate_files << file unless file == @queued_for_write[:original]
525
527
  file
526
528
  end
527
529
 
@@ -586,7 +588,7 @@ module Paperclip
586
588
 
587
589
  # You can either specifiy :restricted_characters or you can define your own
588
590
  # :filename_cleaner object. This object needs to respond to #call and takes
589
- # the filename that will be cleaned. It should return the cleaned filenme.
591
+ # the filename that will be cleaned. It should return the cleaned filename.
590
592
  def filename_cleaner
591
593
  @options[:filename_cleaner] || FilenameCleaner.new(@options[:restricted_characters])
592
594
  end
@@ -51,7 +51,8 @@ module Paperclip
51
51
  end
52
52
 
53
53
  def definitions_for(klass)
54
- klass.ancestors.each_with_object({}) do |ancestor, inherited_definitions|
54
+ parent_classes = klass.ancestors.reverse
55
+ parent_classes.each_with_object({}) do |ancestor, inherited_definitions|
55
56
  inherited_definitions.deep_merge! @attachments[ancestor]
56
57
  end
57
58
  end
@@ -7,7 +7,7 @@ module Paperclip
7
7
 
8
8
  module Defining
9
9
  def define_paperclip_callbacks(*callbacks)
10
- define_callbacks(*[callbacks, {:terminator => callback_terminator}].flatten)
10
+ define_callbacks(*[callbacks, { terminator: hasta_la_vista_baby }].flatten)
11
11
  callbacks.each do |callback|
12
12
  eval <<-end_callbacks
13
13
  def before_#{callback}(*args, &blk)
@@ -22,11 +22,13 @@ module Paperclip
22
22
 
23
23
  private
24
24
 
25
- def callback_terminator
26
- if ::ActiveSupport::VERSION::STRING >= '4.1'
27
- lambda { |target, result| result == false }
28
- else
29
- 'result == false'
25
+ def hasta_la_vista_baby
26
+ lambda do |_, result|
27
+ if result.respond_to?(:call)
28
+ result.call == false
29
+ else
30
+ result == false
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -67,8 +67,9 @@ module Paperclip
67
67
  end
68
68
 
69
69
  def type_from_mime_magic
70
- @type_from_mime_magic ||=
71
- MimeMagic.by_magic(File.open(@filepath)).try(:type)
70
+ @type_from_mime_magic ||= File.open(@filepath) do |file|
71
+ MimeMagic.by_magic(file).try(:type)
72
+ end
72
73
  end
73
74
 
74
75
  def type_from_file_command
@@ -19,7 +19,9 @@ module Paperclip
19
19
  end
20
20
 
21
21
  # Will be thrown when ImageMagic cannot determine the uploaded file's
22
- # metadata, usually this would mean the file is not an image.
22
+ # metadata, usually this would mean the file is not an image. If you are
23
+ # consistently receiving this error on PDFs make sure that you have
24
+ # installed Ghostscript.
23
25
  class NotIdentifiedByImageMagickError < Paperclip::Error
24
26
  end
25
27
 
@@ -8,7 +8,7 @@ module Paperclip
8
8
  base.extend ClassMethods
9
9
  base.send :include, Callbacks
10
10
  base.send :include, Validators
11
- base.send :include, Schema if defined? ActiveRecord
11
+ base.send :include, Schema if defined? ActiveRecord::Base
12
12
 
13
13
  locale_path = Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}")
14
14
  I18n.load_path += locale_path unless I18n.load_path.include?(locale_path)
@@ -91,7 +91,13 @@ module Paperclip
91
91
  name = @name
92
92
  @klass.send(:after_save) { send(name).send(:save) }
93
93
  @klass.send(:before_destroy) { send(name).send(:queue_all_for_delete) }
94
- @klass.send(:after_commit, :on => :destroy) { send(name).send(:flush_deletes) }
94
+ if @klass.respond_to?(:after_commit)
95
+ @klass.send(:after_commit, on: :destroy) do
96
+ send(name).send(:flush_deletes)
97
+ end
98
+ else
99
+ @klass.send(:after_destroy) { send(name).send(:flush_deletes) }
100
+ end
95
101
  end
96
102
 
97
103
  def add_paperclip_callbacks
@@ -8,23 +8,27 @@ module Paperclip
8
8
  Paperclip::Interpolations[key] = block
9
9
  end
10
10
 
11
- # The run method takes the name of a binary to run, the arguments to that binary
12
- # and some options:
11
+ # The run method takes the name of a binary to run, the arguments
12
+ # to that binary, the values to interpolate and some local options.
13
13
  #
14
- # :command_path -> A $PATH-like variable that defines where to look for the binary
15
- # on the filesystem. Colon-separated, just like $PATH.
14
+ # :cmd -> The name of a binary to run.
16
15
  #
17
- # :expected_outcodes -> An array of integers that defines the expected exit codes
18
- # of the binary. Defaults to [0].
16
+ # :arguments -> The command line arguments to that binary.
19
17
  #
20
- # :log_command -> Log the command being run when set to true (defaults to true).
21
- # This will only log if logging in general is set to true as well.
18
+ # :interpolation_values -> Values to be interpolated into the arguments.
22
19
  #
23
- # :swallow_stderr -> Set to true if you don't care what happens on STDERR.
20
+ # :local_options -> The options to be used by Cocain::CommandLine.
21
+ # These could be: runner
22
+ # logger
23
+ # swallow_stderr
24
+ # expected_outcodes
25
+ # environment
26
+ # runner_options
24
27
  #
25
28
  def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
26
29
  command_path = options[:command_path]
27
- Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
30
+ cocaine_path_array = Cocaine::CommandLine.path.try(:split, Cocaine::OS.path_separator)
31
+ Cocaine::CommandLine.path = [cocaine_path_array, command_path].flatten.compact.uniq
28
32
  if logging? && (options[:log_command] || local_options[:log_command])
29
33
  local_options = local_options.merge(:logger => logger)
30
34
  end
@@ -4,7 +4,7 @@ module Paperclip
4
4
  REGEXP = /\Ahttps?:\/\//
5
5
 
6
6
  def initialize(target)
7
- super(URI(target))
7
+ super(URI(URI.escape(target)))
8
8
  end
9
9
 
10
10
  end