Commit 996ca871 by Edison Committed by Prem Sichanugrist

Enable conditional `pattern` assignment to Interpolations

parent 8d43e19e
......@@ -25,7 +25,9 @@ module Paperclip
# Perform the actual interpolation. Takes the pattern to interpolate
# and the arguments to pass, which are the attachment and style name.
# You can pass a :symbol as pattern assigning some method in your model class.
def self.interpolate pattern, *args
pattern = args.first.instance.send(pattern) if pattern.kind_of? Symbol
all.reverse.inject( pattern.dup ) do |result, tag|
result.gsub(/:#{tag}/) do |match|
send( tag, *args )
......
......@@ -36,6 +36,13 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "fake_models/blegga.png", @attachment.url
end
should "return the url by executing and interpolating the default_url when assigned with symbol as method in attachment model" do
@attachment = attachment :default_url => :some_method_to_determine_default_url
@model = @attachment.instance
@model.stubs(:some_method_to_determine_default_url).returns(":class/female_:style_blegga.png")
assert_equal "fake_models/female_foostyle_blegga.png", @attachment.url(:foostyle)
end
context "Attachment default_options" do
setup do
rebuild_model
......
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