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
...@@ -238,6 +238,9 @@ module Paperclip ...@@ -238,6 +238,9 @@ module Paperclip
# the instance's errors and returns false, cancelling the save. # the instance's errors and returns false, cancelling the save.
def save def save
flush_deletes unless @options[:keep_old_files] 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 flush_writes
@dirty = false @dirty = false
true true
......
...@@ -364,6 +364,58 @@ describe Paperclip::Storage::S3 do ...@@ -364,6 +364,58 @@ describe Paperclip::Storage::S3 do
end end
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 context "An attachment that uses S3 for storage and has spaces in file name" do
before do before do
rebuild_model( 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