diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index e3c355fe7..88a18087f 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -236,6 +236,9 @@ def dirty? # 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 diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index c361bfc35..585e0c79f 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -379,6 +379,58 @@ def counter 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(defined?(::Aws) ? :get : :read).yields(@file.read) + @object.stubs(:exists?).returns(true) + end + + it "uploads original" do + @object.expects((defined?(::Aws) ? :upload_file : :write)).with( + anything, + content_type: "image/png", + acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).returns(true) + @object.expects((defined?(::Aws) ? :upload_file : :write)).with( + anything, + content_type: "image/jpeg", + acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).returns(true) + @dummy.avatar.reprocess! + end + + it "doesn't upload original" do + @object.expects((defined?(::Aws) ? :upload_file : :write)).with( + anything, + content_type: "image/jpeg", + acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).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(