Commit b19f897f by Johnny Shields Committed by Tute Costa

Add support for proc arg for fog_public (#2302)

parent 8d08559e
...@@ -86,11 +86,14 @@ module Paperclip ...@@ -86,11 +86,14 @@ module Paperclip
end end
def fog_public(style = default_style) def fog_public(style = default_style)
if @options.has_key?(:fog_public) if @options.key?(:fog_public)
if @options[:fog_public].respond_to?(:has_key?) && @options[:fog_public].has_key?(style) value = @options[:fog_public]
@options[:fog_public][style] if value.respond_to?(:key?) && value.key?(style)
value[style]
elsif value.respond_to?(:call)
value.call(self)
else else
@options[:fog_public] value
end end
else else
true true
......
...@@ -273,6 +273,22 @@ describe Paperclip::Storage::Fog do ...@@ -273,6 +273,22 @@ describe Paperclip::Storage::Fog do
end end
end end
context "with fog_public as a proc" do
let(:proc) { ->(attachment) { !attachment } }
before do
rebuild_model(@options.merge(fog_public: proc))
@dummy = Dummy.new
@dummy.avatar = StringIO.new(".")
@dummy.save
end
it "sets the @fog_public instance variable to false" do
assert_equal proc, @dummy.avatar.instance_variable_get("@options")[:fog_public]
assert_equal false, @dummy.avatar.fog_public
end
end
context "with styles set and fog_public set to false" do context "with styles set and fog_public set to false" do
before do before do
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" })) rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
......
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