Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enable conditional `pattern` assignment to Interpolations

  • Loading branch information...
commit 996ca871a9677fed8cc0d62562e8f0c6ebd1054d 1 parent 8d43e19
@edison edison authored sikachu committed
Showing with 9 additions and 0 deletions.
  1. +2 −0  lib/paperclip/interpolations.rb
  2. +7 −0 test/attachment_test.rb
View
2  lib/paperclip/interpolations.rb
@@ -25,7 +25,9 @@ def self.all
# 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 )
View
7 test/attachment_test.rb
@@ -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

0 comments on commit 996ca87

Please sign in to comment.
Something went wrong with that request. Please try again.