Commit cb7ad7bd by Val Committed by Jon Yurek

Added per-style public setting with tests

parent ee0fe89a
...@@ -69,9 +69,16 @@ module Paperclip ...@@ -69,9 +69,16 @@ module Paperclip
@fog_file ||= @options[:fog_file] || {} @fog_file ||= @options[:fog_file] || {}
end end
def fog_public def fog_public(style = default_style)
return @fog_public if defined?(@fog_public) if defined?(@options[:fog_public])
@fog_public = defined?(@options[:fog_public]) ? @options[:fog_public] : true if defined?(@options[:fog_public][style])
return @options[:fog_public][style]
else
return @options[:fog_public]
end
else
return true
end
end end
def flush_writes def flush_writes
...@@ -82,7 +89,7 @@ module Paperclip ...@@ -82,7 +89,7 @@ module Paperclip
directory.files.create(fog_file.merge( directory.files.create(fog_file.merge(
:body => file, :body => file,
:key => path(style), :key => path(style),
:public => fog_public, :public => fog_public(style),
:content_type => file.content_type :content_type => file.content_type
)) ))
rescue Excon::Errors::NotFound rescue Excon::Errors::NotFound
...@@ -197,4 +204,4 @@ module Paperclip ...@@ -197,4 +204,4 @@ module Paperclip
end end
end end
end end
end end
\ No newline at end of file
...@@ -232,6 +232,36 @@ class FogTest < Test::Unit::TestCase ...@@ -232,6 +232,36 @@ class FogTest < Test::Unit::TestCase
end end
end end
context "with styles set and fog_public set to false" do
setup do
rebuild_model(@options.merge(:fog_public => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
end
should 'set the @fog_public for a perticular style to false' do
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
assert_equal false, @dummy.avatar.fog_public(:thumb)
end
end
context "with styles set and fog_public set per-style" do
setup do
rebuild_model(@options.merge(:fog_public => { :medium => false, :thumb => true}, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
end
should 'set the fog_public for a perticular style to correct value' do
assert_equal false, @dummy.avatar.fog_public(:medium)
assert_equal true, @dummy.avatar.fog_public(:thumb)
end
end
context "with a valid bucket name for a subdomain" do context "with a valid bucket name for a subdomain" do
should "provide an url in subdomain style" do should "provide an url in subdomain style" do
assert_match @dummy.avatar.url, /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/ assert_match @dummy.avatar.url, /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/
......
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