Permalink
Browse files

Fix using using default path and url options for Fog storage

* 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...
1 parent 39717c6 commit 86cddc6ea2401ec59472f1b5abd0f7198510684a @michiels michiels committed with mike-burns Jul 6, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/paperclip/storage/fog.rb
  2. +23 −0 test/storage/fog_test.rb
@@ -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|
View
@@ -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'

0 comments on commit 86cddc6

Please sign in to comment.