From b4ff2c5777df6ac3b0942dc645cfde2d1ace62c8 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 12 Dec 2011 18:27:57 -0500 Subject: [PATCH] Do not show warning if :class exists in the interpolation URL This fixes #660 --- lib/paperclip.rb | 2 +- test/paperclip_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index fdee37b66..02026cb15 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -193,7 +193,7 @@ def class_for(class_name) def check_for_url_clash(name,url,klass) @names_url ||= {} default_url = url || Attachment.default_options[:url] - if @names_url[name] && @names_url[name][:url] == default_url && @names_url[name][:class] != klass + if @names_url[name] && @names_url[name][:url] == default_url && @names_url[name][:class] != klass && @names_url[name][:url] !~ /:class/ log("Duplicate URL for #{name} with #{default_url}. This will clash with attachment defined in #{@names_url[name][:class]} class") end @names_url[name] = {:url => default_url, :class => klass} diff --git a/test/paperclip_test.rb b/test/paperclip_test.rb index 1880b0ebb..c11357c76 100644 --- a/test/paperclip_test.rb +++ b/test/paperclip_test.rb @@ -86,6 +86,16 @@ class Dummy2 < ActiveRecord::Base has_attached_file :blah end end + + should "not generate warning if attachment is redifined with the same url string but has :class in it" do + Paperclip.expects(:log).never + Dummy.class_eval do + has_attached_file :blah, :url => "/system/:class/:attachment/:id/:style/:filename" + end + Dummy2.class_eval do + has_attached_file :blah, :url => "/system/:class/:attachment/:id/:style/:filename" + end + end end context "An ActiveRecord model with an 'avatar' attachment" do