Commit dcd2774e by Les Hill Committed by Jon Yurek

Refactor style specific headers code

Allow either a hash or a Style object to set the headers.
parent 74b829f4
......@@ -311,9 +311,10 @@ module Paperclip
end
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)
if style_specific_options
merge_s3_headers( style_specific_options[:s3_headers], @s3_headers, @s3_metadata) if style_specific_options[:s3_headers]
@s3_metadata.merge!(style_specific_options[:s3_metadata]) if style_specific_options[:s3_metadata]
end
write_options[:metadata] = @s3_metadata unless @s3_metadata.empty?
......
......@@ -294,7 +294,7 @@ class S3Test < Test::Unit::TestCase
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#'} },
rebuild_model :styles => lambda { |attachment| attachment.instance.counter; {:thumbnail => { :geometry => "50x50#", :s3_headers => {'Cache-Control' => 'max-age=31557600'}} }},
:storage => :s3,
:bucket => "bucket",
:path => ":attachment/:style/:basename.:extension",
......@@ -317,8 +317,10 @@ class S3Test < Test::Unit::TestCase
@dummy.avatar = @file
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything, anything).twice
@dummy.avatar.stubs(:s3_object).with(:original).returns(object)
@dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
object.expects(:write).with(anything, :content_type => 'image/png', :acl => :public_read)
object.expects(:write).with(anything, :content_type => 'image/png', :acl => :public_read, :cache_control => 'max-age=31557600')
@dummy.save
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