Commit 74b829f4 by Les Hill Committed by Jon Yurek

Fix s3 writes with style procs

S3#flush_writes was accessing the styles option without checking for a
proc. We can just use the instance's styles method to have it done for
us.
parent e421bc1b
......@@ -310,7 +310,7 @@ module Paperclip
write_options[:server_side_encryption] = @s3_server_side_encryption
end
style_specific_options = @options[:styles][style]
style_specific_options = styles[style]
if style_specific_options.is_a?(Hash)
merge_s3_headers( style_specific_options[:s3_headers], @s3_headers, @s3_metadata) if style_specific_options.has_key?(:s3_headers)
@s3_metadata.merge!(style_specific_options[:s3_metadata]) if style_specific_options.has_key?(:s3_metadata)
......
......@@ -292,6 +292,43 @@ class S3Test < Test::Unit::TestCase
end
end
context "An attachment that uses S3 for storage and has a proc for styles" do
setup do
rebuild_model :styles => lambda { |attachment| attachment.instance.counter; {:thumbnail => '20x20#'} },
:storage => :s3,
:bucket => "bucket",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
@file = File.new(fixture_file('5k.png'), 'rb')
Dummy.class_eval do
def counter
@counter ||= 0
@counter += 1
@counter
end
end
@dummy = Dummy.new
@dummy.avatar = @file
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything, anything).twice
@dummy.save
end
teardown { @file.close }
should "succeed" do
assert_equal @dummy.counter, 7
end
end
context "An attachment that uses S3 for storage and has spaces in file name" do
setup do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
......
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