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,7 +55,7 @@ module Paperclip ...@@ -55,7 +55,7 @@ module Paperclip
end end
def parse_credentials creds def parse_credentials creds
case creds cred_hash = case creds
when File: when File:
YAML.load_file(creds.path) YAML.load_file(creds.path)
when String: when String:
...@@ -65,6 +65,7 @@ module Paperclip ...@@ -65,6 +65,7 @@ module Paperclip
else else
raise ArgumentError, "Credentials are not a path, file, or hash." raise ArgumentError, "Credentials are not a path, file, or hash."
end end
cred_hash[ENV['RAILS_ENV']] || cred_hash
end end
def locate_files def locate_files
......
...@@ -6,6 +6,42 @@ require 'right_aws' ...@@ -6,6 +6,42 @@ require 'right_aws'
require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb') require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
class S3Test < Test::Unit::TestCase 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 context "An attachment with S3 storage" do
setup do setup do
rebuild_model :storage => :s3, 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