Commit 3a6ca7d9 by Alexander Presber

fixed wrong permissions ('private' and 'public-read') into the right

ones (:private and :public_read) in the s3_test
completed test for lambda permission value
parent 15712902
...@@ -81,9 +81,9 @@ module Paperclip ...@@ -81,9 +81,9 @@ module Paperclip
@s3_permissions = set_permissions(@options.s3_permissions) @s3_permissions = set_permissions(@options.s3_permissions)
@s3_protocol = @options.s3_protocol || @s3_protocol = @options.s3_protocol ||
Proc.new do |style, attachment| Proc.new do |style, attachment|
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default]) permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
permission = permission.call(attachment, style) if permission.is_a?(Proc) permission = permission.call(attachment, style) if permission.is_a?(Proc)
permission == :public_read ? 'http' : 'https' (permission == :public_read) ? 'http' : 'https'
end end
@s3_headers = @options.s3_headers || {} @s3_headers = @options.s3_headers || {}
......
...@@ -509,7 +509,7 @@ class S3Test < Test::Unit::TestCase ...@@ -509,7 +509,7 @@ class S3Test < Test::Unit::TestCase
end end
context "S3 Permissions" do context "S3 Permissions" do
context "defaults to public-read" do context "defaults to :public_read" do
setup do setup do
rebuild_model :storage => :s3, rebuild_model :storage => :s3,
:bucket => "testing", :bucket => "testing",
...@@ -556,7 +556,7 @@ class S3Test < Test::Unit::TestCase ...@@ -556,7 +556,7 @@ class S3Test < Test::Unit::TestCase
'access_key_id' => "12345", 'access_key_id' => "12345",
'secret_access_key' => "54321" 'secret_access_key' => "54321"
}, },
:s3_permissions => 'private' :s3_permissions => :private
end end
context "when assigned" do context "when assigned" do
...@@ -575,7 +575,7 @@ class S3Test < Test::Unit::TestCase ...@@ -575,7 +575,7 @@ class S3Test < Test::Unit::TestCase
anything, anything,
'testing', 'testing',
:content_type => 'image/png', :content_type => 'image/png',
:access => 'private') :access => :private)
@dummy.save @dummy.save
end end
...@@ -599,8 +599,8 @@ class S3Test < Test::Unit::TestCase ...@@ -599,8 +599,8 @@ class S3Test < Test::Unit::TestCase
'secret_access_key' => "54321" 'secret_access_key' => "54321"
}, },
:s3_permissions => { :s3_permissions => {
:original => 'private', :original => :private,
:thumb => 'public-read' :thumb => :public_read
} }
end end
...@@ -621,7 +621,7 @@ class S3Test < Test::Unit::TestCase ...@@ -621,7 +621,7 @@ class S3Test < Test::Unit::TestCase
anything, anything,
'testing', 'testing',
:content_type => 'image/png', :content_type => 'image/png',
:access => style == :thumb ? 'public-read' : 'private') :access => style == :thumb ? :public_read : :private)
end end
@dummy.save @dummy.save
end end
...@@ -635,17 +635,21 @@ class S3Test < Test::Unit::TestCase ...@@ -635,17 +635,21 @@ class S3Test < Test::Unit::TestCase
context "proc permission set" do context "proc permission set" do
setup do setup do
rebuild_model :storage => :s3, rebuild_model(
:bucket => "testing", :storage => :s3,
:path => ":attachment/:style/:basename.:extension", :bucket => "testing",
:styles => { :path => ":attachment/:style/:basename.:extension",
:thumb => "80x80>" :styles => {
}, :thumb => "80x80>"
:s3_credentials => { },
'access_key_id' => "12345", :s3_credentials => {
'secret_access_key' => "54321" 'access_key_id' => "12345",
}, 'secret_access_key' => "54321"
:s3_permissions => lambda{|attachment, style| attachment.instance.private_attachment? && style.to_sym != :thumb ? 'private' : 'public-read' } },
:s3_permissions => lambda {|attachment, style|
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
}
)
end end
context "when assigned" do context "when assigned" do
...@@ -662,18 +666,20 @@ class S3Test < Test::Unit::TestCase ...@@ -662,18 +666,20 @@ class S3Test < Test::Unit::TestCase
setup do setup do
AWS::S3::Base.stubs(:establish_connection!) AWS::S3::Base.stubs(:establish_connection!)
[:thumb, :original].each do |style| [:thumb, :original].each do |style|
AWS::S3::S3Object.expects(:store).with("avatars/#{style}/5k.png", AWS::S3::S3Object.expects(:store).with(
anything, "avatars/#{style}/5k.png",
'testing', anything,
:content_type => 'image/png', 'testing',
:access => style == :thumb ? 'public-read' : 'private') :content_type => 'image/png',
:access => style == :thumb ? :public_read : :private
)
end end
@dummy.save @dummy.save
end end
should "succeed" do should "succeed" do
assert_equal 0, @dummy.avatar.url() =~ /^https:/ assert @dummy.avatar.url().include? "https://"
assert_equal 0, @dummy.avatar.url(:thumb) =~ /^http:/ assert @dummy.avatar.url(:thumb).include? "http://"
end 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