Commit 4f9ffb85 by Damian Janowski Committed by Jon Yurek

Make the build more friendly.

(cherry picked from commit f58f73210621261c214136eb7514be459032ee0f)
parent a6095d0c
......@@ -127,7 +127,13 @@ module Paperclip
# separate parts of your file name.
module S3
def self.extended base
require 'aws/s3'
begin
require 'aws/s3'
rescue LoadError => e
e.message << " (You may need to install the aws-s3 gem)"
raise e
end
base.instance_eval do
@s3_credentials = parse_credentials(@options[:s3_credentials])
@bucket = @options[:bucket] || @s3_credentials[:bucket]
......
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'mocha'
require 'tempfile'
gem 'jferris-mocha', '0.9.5.0.1241126838'
require 'mocha'
gem 'sqlite3-ruby'
require 'active_record'
......@@ -97,3 +99,10 @@ end
def attachment options
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end
......@@ -7,7 +7,7 @@ class InterpolationsTest < Test::Unit::TestCase
assert ! methods.include?(:[]=)
assert ! methods.include?(:all)
methods.each do |m|
assert Paperclip::Interpolations.respond_to? m
assert Paperclip::Interpolations.respond_to?(m)
end
end
......
require 'test/helper'
require 'aws/s3'
class StorageTest < Test::Unit::TestCase
def rails_env(env)
silence_warnings do
Object.const_set(:RAILS_ENV, env)
end
end
context "Parsing S3 credentials" do
setup do
AWS::S3::Base.stubs(:establish_connection!)
......@@ -15,25 +22,25 @@ class StorageTest < Test::Unit::TestCase
end
teardown do
Object.const_set("RAILS_ENV", @current_env)
rails_env(@current_env)
end
should "get the correct credentials when RAILS_ENV is production" do
Object.const_set('RAILS_ENV', "production")
rails_env("production")
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
Object.const_set('RAILS_ENV', "development")
rails_env("development")
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
Object.const_set('RAILS_ENV', "not really an env")
rails_env("not really an env")
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
end
end
......@@ -102,15 +109,15 @@ class StorageTest < Test::Unit::TestCase
@old_env = RAILS_ENV
end
teardown{ Object.const_set("RAILS_ENV", @old_env) }
teardown{ rails_env(@old_env) }
should "get the right bucket in production" do
Object.const_set("RAILS_ENV", "production")
rails_env("production")
assert_equal "prod_bucket", @dummy.avatar.bucket_name
end
should "get the right bucket in development" do
Object.const_set("RAILS_ENV", "development")
rails_env("development")
assert_equal "dev_bucket", @dummy.avatar.bucket_name
end
end
......
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