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