Commit 7a8d1e63 by iltempo Committed by Jon Yurek

S3 headers can be set as a proc now

parent f56e8635
......@@ -98,7 +98,9 @@ module Paperclip
(permission == :public_read) ? 'http' : 'https'
end
@s3_metadata = @options[:s3_metadata] || {}
@s3_headers = (@options[:s3_headers] || {}).inject({}) do |headers,(name,value)|
@s3_headers = @options[:s3_headers] || {}
@s3_headers = @s3_headers.call(instance) if @s3_headers.is_a?(Proc)
@s3_headers = (@s3_headers).inject({}) do |headers,(name,value)|
case name.to_s
when /^x-amz-meta-(.*)/i
@s3_metadata[$1.downcase] = value
......
......@@ -940,4 +940,53 @@ class S3Test < Test::Unit::TestCase
end
end
context "An attachment with S3 storage and metadata set using a proc as headers" do
setup do
rebuild_model(
:storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
},
:s3_credentials => {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_headers => lambda {|attachment|
{'Content-Disposition' => "attachment; filename=\"#{attachment.name}\""}
}
)
end
context "when assigned" do
setup do
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.stubs(:name => 'Custom Avatar Name.png')
@dummy.avatar = @file
end
teardown { @file.close }
context "and saved" do
setup do
[:thumb, :original].each do |style|
object = stub
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:content_disposition => 'attachment; filename="Custom Avatar Name.png"')
end
@dummy.save
end
should "succeed" do
assert true
end
end
end
end
end
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