Commit cb7ad7bd by Val Committed by Jon Yurek

Added per-style public setting with tests

parent ee0fe89a
......@@ -69,9 +69,16 @@ module Paperclip
@fog_file ||= @options[:fog_file] || {}
end
def fog_public
return @fog_public if defined?(@fog_public)
@fog_public = defined?(@options[:fog_public]) ? @options[:fog_public] : true
def fog_public(style = default_style)
if defined?(@options[:fog_public])
if defined?(@options[:fog_public][style])
return @options[:fog_public][style]
else
return @options[:fog_public]
end
else
return true
end
end
def flush_writes
......@@ -82,7 +89,7 @@ module Paperclip
directory.files.create(fog_file.merge(
:body => file,
:key => path(style),
:public => fog_public,
:public => fog_public(style),
:content_type => file.content_type
))
rescue Excon::Errors::NotFound
......
......@@ -232,6 +232,36 @@ class FogTest < Test::Unit::TestCase
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
should "provide an url in subdomain style" do
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