Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Don't write original if it wasn't reprocessed #1993

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [85/80]

@queued_for_write.except!(:original)
end
flush_writes
@dirty = false
true
Expand Down
52 changes: 52 additions & 0 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.

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(
Expand Down