Commit 96dc32b2 by jyurek

Tweaked the interpolation matching so :id won't step on :id_partition.


git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@458 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 61d8253b
......@@ -148,7 +148,9 @@ module Paperclip
def self.interpolations
@interpolations ||= {
:rails_root => lambda{|attachment,style| RAILS_ROOT },
:class => lambda{|attachment,style| attachment.instance.class.to_s.downcase.pluralize },
:class => lambda do |attachment,style|
attachment.instance.class.to_s.downcase.pluralize
end,
:basename => lambda do |attachment,style|
attachment.original_filename.gsub(/\.(.*?)$/, "")
end,
......@@ -157,7 +159,7 @@ module Paperclip
File.extname(attachment.original_filename).gsub(/^\.+/, "")
end,
:id => lambda{|attachment,style| attachment.instance.id },
:partition_id => lambda do |attachment, style|
:id_partition => lambda do |attachment, style|
("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
end,
:attachment => lambda{|attachment,style| attachment.name.to_s.downcase.pluralize },
......@@ -215,7 +217,7 @@ module Paperclip
style ||= default_style
pattern = pattern.dup
self.class.interpolations.each do |tag, l|
pattern.gsub!(/:#{tag}/) do |match|
pattern.gsub!(/:\b#{tag}\b/) do |match|
l.call( self, style )
end
end
......
......@@ -60,6 +60,22 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context "An attachment with similarly named interpolations" do
setup do
rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
@dummy = Dummy.new
@dummy.stubs(:id).returns(1024)
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"))
@dummy.avatar = @file
end
should "make sure that they are interpolated correctly" do
assert_equal "1024.omg/1024-bbq/:idwhat/000/001/024.wtf", @dummy.avatar.path
end
end
context "An attachment" do
setup do
Paperclip::Attachment.default_options.merge!({
......
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