Skip to content
Browse files

Fixes an infinite interpolation problem with fog

  • Loading branch information...
1 parent 3f56e70 commit 6c912c4d2da0fd3c2b31c98342e84406f2fc53fb @jyurek jyurek committed Aug 24, 2011
Showing with 24 additions and 1 deletion.
  1. +4 −1 lib/paperclip/storage/fog.rb
  2. +20 −0 test/fog_test.rb
View
5 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
View
20 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'

0 comments on commit 6c912c4

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