Commit 1c7d7f66 by Aleksandr Zykov Committed by Tute Costa

Don't write original file if it wasn't reprocessed

If `only_process` list is not empty, but it doesn't contain `:original`
style, original file hasn't been reprocessed and it's not needed to
rewrite/reupload it.

[fixes #1993]
[fixes #2046]
[fixes #1804]
parent ce223815
......@@ -50,7 +50,7 @@ module Paperclip
# +url+ - a relative URL of the attachment. This is interpolated using +interpolator+
# +path+ - where on the filesystem to store the attachment. This is interpolated using +interpolator+
# +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
# +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
# +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
# a special case that indicates all styles should be processed)
# +default_url+ - a URL for the missing image
# +default_style+ - the style to use when an argument is not specified e.g. #url, #path
......@@ -238,6 +238,9 @@ module Paperclip
# the instance's errors and returns false, cancelling the save.
def save
flush_deletes unless @options[:keep_old_files]
if @options[:only_process].any? && !@options[:only_process].include?(:original)
@queued_for_write.except!(:original)
end
flush_writes
@dirty = false
true
......
......@@ -364,6 +364,58 @@ describe Paperclip::Storage::S3 do
end
end
context "An attachment that uses S3 for storage and has styles" do
before do
rebuild_model(
(aws2_add_region).merge(
storage: :s3,
styles: { thumb: ["90x90#", :jpg] },
bucket: "bucket",
s3_credentials: {
"access_key_id" => "12345",
"secret_access_key" => "54321" }
)
)
@file = File.new(fixture_file("5k.png"), "rb")
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
end
context "reprocess" do
before do
@object = stub
@dummy.avatar.stubs(:s3_object).with(:original).returns(@object)
@dummy.avatar.stubs(:s3_object).with(:thumb).returns(@object)
@object.stubs(:get).yields(@file.read)
@object.stubs(:exists?).returns(true)
end
it "uploads original" do
@object.expects(:upload_file).with(
anything,
content_type: "image/png",
acl: :"public-read").returns(true)
@object.expects(:upload_file).with(
anything,
content_type: "image/jpeg",
acl: :"public-read").returns(true)
@dummy.avatar.reprocess!
end
it "doesn't upload original" do
@object.expects(:upload_file).with(
anything,
content_type: "image/jpeg",
acl: :"public-read").returns(true)
@dummy.avatar.reprocess!(:thumb)
end
end
after { @file.close }
end
context "An attachment that uses S3 for storage and has spaces in file name" do
before do
rebuild_model(
......
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