Permalink
Browse files

Added per-style public setting with tests

  • Loading branch information...
1 parent ee0fe89 commit cb7ad7bd427825bf4a10a539e6f15a6d7a945b99 Val committed with jyurek Aug 2, 2012
Showing with 42 additions and 5 deletions.
  1. +12 −5 lib/paperclip/storage/fog.rb
  2. +30 −0 test/storage/fog_test.rb
@@ -69,9 +69,16 @@ def fog_file
@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])
@ncr

ncr Oct 9, 2012

This does not work as intended, the defined? operator can't be used to check for a key in hash.

+ 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 @@ def flush_writes
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
@@ -197,4 +204,4 @@ def directory
end
end
end
-end
+end
View
@@ -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/

0 comments on commit cb7ad7b

Please sign in to comment.