Commit dc64b2ba by Amanda Munoz and Prem Sichanugrist Committed by Mike Burns

Skip validity check when reprocess attachment

This validation was causing issue when there is no content_type column
in the database, as the content type of the attachment would be empty.
There should be no need to check attachment's validity because this
`#reprocess!` method is running internally on the server.

Fix #2078
parent fa37ab74
...@@ -337,8 +337,15 @@ module Paperclip ...@@ -337,8 +337,15 @@ module Paperclip
# inconsistencies in timing of S3 commands. It's possible that calling # inconsistencies in timing of S3 commands. It's possible that calling
# #reprocess! will lose data if the files are not kept. # #reprocess! will lose data if the files are not kept.
def reprocess!(*style_args) def reprocess!(*style_args)
saved_only_process, @options[:only_process] = @options[:only_process], style_args saved_flags = @options.slice(
saved_preserve_files, @options[:preserve_files] = @options[:preserve_files], true :only_process,
:preserve_files,
:check_validity_before_processing
)
@options[:only_process] = style_args
@options[:preserve_files] = true
@options[:check_validity_before_processing] = false
begin begin
assign(self) assign(self)
save save
...@@ -347,8 +354,7 @@ module Paperclip ...@@ -347,8 +354,7 @@ module Paperclip
warn "#{e} - skipping file." warn "#{e} - skipping file."
false false
ensure ensure
@options[:only_process] = saved_only_process @options.merge!(saved_flags)
@options[:preserve_files] = saved_preserve_files
end end
end end
......
...@@ -53,6 +53,22 @@ describe Paperclip::Attachment do ...@@ -53,6 +53,22 @@ describe Paperclip::Attachment do
expect(dummy.avatar.path(:original)).to exist expect(dummy.avatar.path(:original)).to exist
end end
it "reprocess works with virtual content_type attribute" do
rebuild_class styles: { small: "100x>" }
modify_table { |t| t.remove :avatar_content_type }
Dummy.send :attr_accessor, :avatar_content_type
Dummy.validates_attachment_content_type(
:avatar,
content_type: %w(image/jpeg image/png)
)
Dummy.create!(avatar: File.new(fixture_file("50x50.png"), "rb"))
dummy = Dummy.first
dummy.avatar.reprocess!(:small)
expect(dummy.avatar.path(:small)).to exist
end
context "having a not empty hash as a default option" do context "having a not empty hash as a default option" do
before do before do
@old_default_options = Paperclip::Attachment.default_options.dup @old_default_options = Paperclip::Attachment.default_options.dup
......
...@@ -27,7 +27,7 @@ module ModelReconstruction ...@@ -27,7 +27,7 @@ module ModelReconstruction
ActiveRecord::Base.connection.create_table :dummies, {force: true}, &block ActiveRecord::Base.connection.create_table :dummies, {force: true}, &block
end end
def modify_table table_name, &block def modify_table &block
ActiveRecord::Base.connection.change_table :dummies, &block ActiveRecord::Base.connection.change_table :dummies, &block
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment