Commit d6ebd321 by Tristan Dunn

Run S3 configuration file through ERB before parsing the YAML.

parent 836f44e6
......@@ -25,6 +25,7 @@
#
# See the +has_attached_file+ documentation for more details.
require 'erb'
require 'tempfile'
require 'paperclip/upfile'
require 'paperclip/iostream'
......
......@@ -227,9 +227,9 @@ module Paperclip
def find_credentials creds
case creds
when File
YAML.load_file(creds.path)
YAML::load(ERB.new(File.read(creds.path)).result)
when String
YAML.load_file(creds)
YAML::load(ERB.new(File.read(creds)).result)
when Hash
creds
else
......
......@@ -2,3 +2,7 @@ development:
key: 54321
production:
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
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?
context "Using S3 for real, an attachment with S3 storage" 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