Skip to content

Commit

Permalink
Fix using using default path and url options for Fog storage
Browse files Browse the repository at this point in the history
* Added test for checking if path gets interpolated correctly without passing
  :path or :url options
* gsub default :rails_root filesystem-like path to nothing for Fog storage,
  just like in S3 Storage.
  • Loading branch information
michiels authored and mike-burns committed Jul 9, 2012
1 parent 39717c6 commit 86cddc6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.extended base

base.instance_eval do
unless @options[:url].to_s.match(/^:fog.*url$/)
@options[:path] = @options[:path].gsub(/:url/, @options[:url])
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system\//, '')
@options[:url] = ':fog_public_url'
end
Paperclip.interpolates(:fog_public_url) do |attachment, style|
Expand Down
23 changes: 23 additions & 0 deletions test/storage/fog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ class FogTest < Test::Unit::TestCase
@dummy.avatar.path
end
end

context "with no path or url given and using defaults" do
setup do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:fog_directory => "paperclip",
:fog_credentials => {
:provider => 'AWS',
:aws_access_key_id => 'AWS_ID',
:aws_secret_access_key => 'AWS_SECRET'
}
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.id = 1
@dummy.avatar = @file
end

teardown { @file.close }

should "have correct path and url from interpolated defaults" do
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
end
end

setup do
@fog_directory = 'papercliptests'
Expand Down

0 comments on commit 86cddc6

Please sign in to comment.