Commit 95fc7b6a by Mike Breen Committed by Jon Yurek

:s3_credentials will now accept a Pathname

Rails.root returns a Pathname and you can now declare your attachment
without having to call #to_s first:

has_attached_file :avatar,
                  :storage => :s3,
                  :s3_credentials => Rails.root.join('s3.yml')
(cherry picked from commit 65d7600b7246cb3bd8f10805fb618e5839694318)
parent 9283b5ef
...@@ -232,7 +232,7 @@ module Paperclip ...@@ -232,7 +232,7 @@ module Paperclip
case creds case creds
when File when File
YAML::load(ERB.new(File.read(creds.path)).result) YAML::load(ERB.new(File.read(creds.path)).result)
when String when String, Pathname
YAML::load(ERB.new(File.read(creds)).result) YAML::load(ERB.new(File.read(creds)).result)
when Hash when Hash
creds creds
......
...@@ -254,6 +254,28 @@ class StorageTest < Test::Unit::TestCase ...@@ -254,6 +254,28 @@ class StorageTest < Test::Unit::TestCase
end end
end end
context "with S3 credentials supplied as Pathname" do
setup do
ENV['S3_KEY'] = 'pathname_key'
ENV['S3_BUCKET'] = 'pathname_bucket'
ENV['S3_SECRET'] = 'pathname_secret'
rails_env('test')
rebuild_model :storage => :s3,
:s3_credentials => Pathname.new(File.join(File.dirname(__FILE__))).join("fixtures/s3.yml")
Dummy.delete_all
@dummy = Dummy.new
end
should "parse the credentials" do
assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
assert_equal 'pathname_key', AWS::S3::Base.connection.options[:access_key_id]
assert_equal 'pathname_secret', AWS::S3::Base.connection.options[:secret_access_key]
end
end
context "with S3 credentials in a YAML file" do context "with S3 credentials in a YAML file" do
setup do setup do
ENV['S3_KEY'] = 'env_key' ENV['S3_KEY'] = 'env_key'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment