Commit d6ebd321 by Tristan Dunn

Run S3 configuration file through ERB before parsing the YAML.

parent 836f44e6
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
# See the +has_attached_file+ documentation for more details. # See the +has_attached_file+ documentation for more details.
require 'erb'
require 'tempfile' require 'tempfile'
require 'paperclip/upfile' require 'paperclip/upfile'
require 'paperclip/iostream' require 'paperclip/iostream'
......
...@@ -227,9 +227,9 @@ module Paperclip ...@@ -227,9 +227,9 @@ module Paperclip
def find_credentials creds def find_credentials creds
case creds case creds
when File when File
YAML.load_file(creds.path) YAML::load(ERB.new(File.read(creds.path)).result)
when String when String
YAML.load_file(creds) YAML::load(ERB.new(File.read(creds)).result)
when Hash when Hash
creds creds
else else
......
...@@ -2,3 +2,7 @@ development: ...@@ -2,3 +2,7 @@ development:
key: 54321 key: 54321
production: production:
key: 12345 key: 12345
test:
bucket: <%= ENV['S3_BUCKET'] %>
access_key_id: <%= ENV['S3_KEY'] %>
secret_access_key: <%= ENV['S3_SECRET'] %>
...@@ -236,6 +236,29 @@ class StorageTest < Test::Unit::TestCase ...@@ -236,6 +236,29 @@ class StorageTest < Test::Unit::TestCase
end end
end end
context "with S3 credentials in a YAML file" do
setup do
ENV['S3_KEY'] = 'env_key'
ENV['S3_BUCKET'] = 'env_bucket'
ENV['S3_SECRET'] = 'env_secret'
rails_env('test')
rebuild_model :storage => :s3,
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "fixtures/s3.yml"))
Dummy.delete_all
@dummy = Dummy.new
end
should "run it the file through ERB" do
assert_equal 'env_bucket', @dummy.avatar.bucket_name
assert_equal 'env_key', AWS::S3::Base.connection.options[:access_key_id]
assert_equal 'env_secret', AWS::S3::Base.connection.options[:secret_access_key]
end
end
unless ENV["S3_TEST_BUCKET"].blank? unless ENV["S3_TEST_BUCKET"].blank?
context "Using S3 for real, an attachment with S3 storage" do context "Using S3 for real, an attachment with S3 storage" do
setup do setup do
......
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