Commit db786b99 by jyurek

S3's credentials parsing now allows for different environments.


git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@449 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 1e1e7577
......@@ -55,16 +55,17 @@ module Paperclip
end
def parse_credentials creds
case creds
when File:
YAML.load_file(creds.path)
when String:
YAML.load_file(creds)
when Hash:
creds
else
raise ArgumentError, "Credentials are not a path, file, or hash."
end
cred_hash = case creds
when File:
YAML.load_file(creds.path)
when String:
YAML.load_file(creds)
when Hash:
creds
else
raise ArgumentError, "Credentials are not a path, file, or hash."
end
cred_hash[ENV['RAILS_ENV']] || cred_hash
end
def locate_files
......
......@@ -6,6 +6,42 @@ require 'right_aws'
require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
class S3Test < Test::Unit::TestCase
context "Parsing S3 credentials" do
setup do
rebuild_model :storage => :s3,
:bucket => "testing",
:s3_credentials => {:not => :important}
@s3_stub = stub
@bucket_stub = stub
RightAws::S3.expects(:new).returns(@s3_stub)
@s3_stub.expects(:bucket).returns(@bucket_stub)
@dummy = Dummy.new
@avatar = @dummy.avatar
@current_env = ENV['RAILS_ENV']
end
teardown do
ENV['RAILS_ENV'] = @current_env
end
should "get the correct credentials when RAILS_ENV is production" do
ENV['RAILS_ENV'] = 'production'
assert_equal "12345", @avatar.parse_credentials('production' => '12345', :production => "54321")
end
should "get the correct credentials when RAILS_ENV is development" do
ENV['RAILS_ENV'] = 'development'
assert_equal "12345", @avatar.parse_credentials('development' => '12345', :development => "54321")
end
should "return the argument if the key does not exist" do
ENV['RAILS_ENV'] = "not really an env"
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
end
end
context "An attachment with S3 storage" do
setup do
rebuild_model :storage => :s3,
......
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