Commit 03e325bf by jyurek

The :s3_credentials option should be using symbols instead of strings.


git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@454 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 8cdc876a
......@@ -43,8 +43,8 @@ module Paperclip
@s3_options = @options[:s3_options] || {}
@s3_permissions = @options[:s3_permissions] || 'public-read'
@s3 = RightAws::S3.new(@s3_credentials['access_key_id'],
@s3_credentials['secret_access_key'],
@s3 = RightAws::S3.new(@s3_credentials[:access_key_id],
@s3_credentials[:secret_access_key],
@s3_options)
@s3_bucket = @s3.bucket(@bucket, true, @s3_permissions)
@url = ":s3_url"
......@@ -55,17 +55,8 @@ module Paperclip
end
def parse_credentials creds
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
creds = find_credentials(creds).stringify_keys
(creds[ENV['RAILS_ENV']] || creds).symbolize_keys
end
def locate_files
......@@ -103,6 +94,20 @@ module Paperclip
@queued_for_delete = []
end
def find_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
end
private :find_credentials
end
end
end
......@@ -19,6 +19,8 @@ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
require File.join(ROOT, 'lib', 'paperclip.rb')
ENV['RAILS_ENV'] ||= 'test'
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
......
......@@ -28,12 +28,16 @@ class S3Test < Test::Unit::TestCase
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")
assert_equal({:key => "12345"},
@avatar.parse_credentials('production' => {:key => '12345'},
:development => {:key => "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")
assert_equal({:key => "54321"},
@avatar.parse_credentials('production' => {:key => '12345'},
:development => {:key => "54321"}))
end
should "return the argument if the key does not exist" 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