Skip to content

Commit

Permalink
Changed ENV['RAILS_ENV'] to plain RAILS_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed May 11, 2009
1 parent f47a4b5 commit 93073d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/storage.rb
Expand Up @@ -173,7 +173,7 @@ def s3_host_alias

def parse_credentials creds
creds = find_credentials(creds).stringify_keys
(creds[ENV['RAILS_ENV']] || creds).symbolize_keys
(creds[RAILS_ENV] || creds).symbolize_keys
end

def exists?(style = default_style)
Expand Down
2 changes: 0 additions & 2 deletions test/helper.rb
Expand Up @@ -26,8 +26,6 @@

require 'shoulda_macros/paperclip'

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")
Expand Down
19 changes: 12 additions & 7 deletions test/storage_test.rb
Expand Up @@ -10,29 +10,29 @@ class StorageTest < Test::Unit::TestCase
@dummy = Dummy.new
@avatar = @dummy.avatar

@current_env = ENV['RAILS_ENV']
@current_env = RAILS_ENV
end

teardown do
ENV['RAILS_ENV'] = @current_env
Object.const_set("RAILS_ENV", @current_env)
end

should "get the correct credentials when RAILS_ENV is production" do
ENV['RAILS_ENV'] = 'production'
Object.const_set('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
ENV['RAILS_ENV'] = 'development'
Object.const_set('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
ENV['RAILS_ENV'] = "not really an env"
Object.const_set('RAILS_ENV', "not really an env")
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
end
end
Expand Down Expand Up @@ -94,13 +94,18 @@ class StorageTest < Test::Unit::TestCase
:development => { :bucket => "dev_bucket" }
}
@dummy = Dummy.new
@old_env = RAILS_ENV
end

should "get the right bucket in production", :before => lambda{ ENV.expects(:[]).returns('production') } do
teardown{ Object.const_set("RAILS_ENV", @old_env) }

should "get the right bucket in production" do
Object.const_set("RAILS_ENV", "production")
assert_equal "prod_bucket", @dummy.avatar.bucket_name
end

should "get the right bucket in development", :before => lambda{ ENV.expects(:[]).returns('development') } do
should "get the right bucket in development" do
Object.const_set("RAILS_ENV", "development")
assert_equal "dev_bucket", @dummy.avatar.bucket_name
end
end
Expand Down

0 comments on commit 93073d5

Please sign in to comment.