Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor style specific headers code

Allow either a hash or a Style object to set the headers.
  • Loading branch information...
commit dcd2774e791380c3c2d979692bdaf30ed30d727a 1 parent 74b829f
@leshill leshill authored jyurek committed
Showing with 9 additions and 6 deletions.
  1. +4 −3 lib/paperclip/storage/s3.rb
  2. +5 −3 test/storage/s3_test.rb
View
7 lib/paperclip/storage/s3.rb
@@ -311,9 +311,10 @@ def flush_writes #:nodoc:
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?
View
8 test/storage/s3_test.rb
@@ -294,7 +294,7 @@ class << @dummy
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 @@ def counter
@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
Please sign in to comment.
Something went wrong with that request. Please try again.