Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Fixes an infinite interpolation problem with fog
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Aug 24, 2011
1 parent 3f56e70 commit 6c912c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/paperclip/storage/fog.rb
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/fog_test.rb
Expand Up @@ -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'
Expand Down

0 comments on commit 6c912c4

Please sign in to comment.