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 3 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
46 changes: 46 additions & 0 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,52 @@ 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] },

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

bucket: "bucket",

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

s3_credentials: { "access_key_id" => "12345",

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

"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).with().yields(@file.read)

Choose a reason for hiding this comment

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

Do not use parentheses for method calls with no arguments.

@object.stubs(:exists?).with().returns(true)

Choose a reason for hiding this comment

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

Do not use parentheses for method calls with no arguments.

end

it "uploads original" do
@object.expects((defined?(::Aws) ? :upload_file : :write))
.with(anything, content_type: 'image/png',

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).returns(true)

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

@object.expects((defined?(::Aws) ? :upload_file : :write))
.with(anything, content_type: 'image/jpeg',

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).returns(true)

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

@dummy.avatar.reprocess!
end

it "doesn't upload original" do
@object.expects((defined?(::Aws) ? :upload_file : :write))
.with(anything, content_type: 'image/jpeg',

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

acl: Paperclip::Storage::S3::DEFAULT_PERMISSION).returns(true)

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

Choose a reason for hiding this comment

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

Align the elements of a hash literal if they span more than one line.

@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