From 6c912c4d2da0fd3c2b31c98342e84406f2fc53fb Mon Sep 17 00:00:00 2001 From: Jon Yurek Date: Wed, 24 Aug 2011 09:21:34 -0400 Subject: [PATCH] Fixes an infinite interpolation problem with fog --- lib/paperclip/storage/fog.rb | 5 ++++- test/fog_test.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/paperclip/storage/fog.rb b/lib/paperclip/storage/fog.rb index 40f09f364..5a2971d37 100644 --- a/lib/paperclip/storage/fog.rb +++ b/lib/paperclip/storage/fog.rb @@ -47,7 +47,10 @@ def self.extended base @fog_public = @options.key?(:fog_public) ? @options[:fog_public] : true @fog_file = @options[:fog_file] || {} - @url = ':fog_public_url' + unless @url.to_s.match(/^:fog.*url$/) + @path = @path.gsub(/:url/, @url) + @url = ':fog_public_url' + end Paperclip.interpolates(:fog_public_url) do |attachment, style| attachment.public_url(style) end unless Paperclip::Interpolations.respond_to? :fog_public_url diff --git a/test/fog_test.rb b/test/fog_test.rb index 4d920e0b3..2b2689b1a 100644 --- a/test/fog_test.rb +++ b/test/fog_test.rb @@ -5,6 +5,26 @@ class FogTest < Test::Unit::TestCase context "" do + context "with default values for path and url" do + setup do + rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" }, + :storage => :fog, + :url => '/:attachment/:filename', + :fog_directory => "paperclip", + :fog_credentials => { + :provider => 'AWS', + :aws_access_key_id => 'AWS_ID', + :aws_secret_access_key => 'AWS_SECRET' + } + @dummy = Dummy.new + @dummy.avatar = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb') + end + should "be able to interpolate the path without blowing up" do + puts @dummy.avatar.instance_variable_get("@path") + assert_equal File.join(File.dirname(File.expand_path(__FILE__)), + "../public/avatars/5k.png"), @dummy.avatar.path + end + end setup do @fog_directory = 'papercliptests'