Commit 7ff4120e by Franco Catena Committed by Jon Yurek

Do not cache dynamic attachment styles

parent 3b170824
......@@ -64,7 +64,7 @@ module Paperclip
end
def styles
unless @normalized_styles
if @styles.respond_to?(:call) || !@normalized_styles
@normalized_styles = {}
(@styles.respond_to?(:call) ? @styles.call(self) : @styles).each do |name, args|
@normalized_styles[name] = Paperclip::Style.new(name, args.dup, self)
......
......@@ -287,6 +287,24 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end
end
context "An attachment with conditional :styles that is a proc" do
setup do
rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
@dummy = Dummy.new(:other => 'a')
end
should "have the correct styles for the assigned instance values" do
assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
assert_nil @dummy.avatar.styles[:large]
@dummy.other = 'b'
assert_equal "400x400", @dummy.avatar.styles[:large][:geometry]
assert_nil @dummy.avatar.styles[:thumb]
end
end
context "An attachment with :url that is a proc" do
setup do
......
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