Skip to content

Commit

Permalink
Make the build more friendly.
Browse files Browse the repository at this point in the history
  • Loading branch information
djanowski committed Aug 9, 2009
1 parent 98eff60 commit f58f732
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/paperclip/storage.rb
Expand Up @@ -127,7 +127,13 @@ def flush_deletes #:nodoc:
# 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]
Expand Down
11 changes: 10 additions & 1 deletion test/helper.rb
@@ -1,9 +1,11 @@
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'
Expand Down Expand Up @@ -97,3 +99,10 @@ def run_callbacks name, *args
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
2 changes: 1 addition & 1 deletion test/interpolations_test.rb
Expand Up @@ -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

Expand Down
21 changes: 14 additions & 7 deletions test/storage_test.rb
@@ -1,6 +1,13 @@
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!)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f58f732

Please sign in to comment.