diff options
author | Terence Lee <hone02@gmail.com> | 2012-04-03 21:50:18 -0500 |
---|---|---|
committer | Terence Lee <hone02@gmail.com> | 2012-04-03 21:50:18 -0500 |
commit | 93f25ac6fc4493600c1648c1a60b12cc83790ad0 (patch) | |
tree | 502b5e7c76868cee83599516ff61df3dafe1b68d /railties/test | |
parent | 8e315b0e0a551fcb09e73b2b704492923d4806f3 (diff) | |
download | rails-93f25ac6fc4493600c1648c1a60b12cc83790ad0.tar.gz rails-93f25ac6fc4493600c1648c1a60b12cc83790ad0.tar.bz2 rails-93f25ac6fc4493600c1648c1a60b12cc83790ad0.zip |
test initializer logic for DATABASE_URL env var
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/initializers/active_record_test.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/railties/test/application/initializers/active_record_test.rb b/railties/test/application/initializers/active_record_test.rb new file mode 100644 index 0000000000..4a0b8fd56a --- /dev/null +++ b/railties/test/application/initializers/active_record_test.rb @@ -0,0 +1,43 @@ +require "isolation/abstract_unit" +require "rack/test" + +module ApplicationTests + class ActiveRecordTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + @database_url = ENV['DATABASE_URL'] + ENV.delete('DATABASE_URL') + build_app + boot_rails + end + + def teardown + teardown_app + ENV['DATABASE_URL'] = @database_url + end + + test "blows up when no DATABASE_URL env var or database.yml" do + FileUtils.rm_rf("#{app_path}/config/database.yml") + boot_rails + simple_controller + + get '/foo' + assert last_response.body.include?("We're sorry, but something went wrong (500)") + end + + test "uses DATABASE_URL env var when config/database.yml doesn't exist" do + database_path = "/db/foo.sqlite3" + FileUtils.rm_rf("#{app_path}/config/database.yml") + ENV['DATABASE_URL'] = "sqlite3://#{database_path}" + simple_controller + + get '/foo' + assert_equal 'foo', last_response.body + + # clean up + FileUtils.rm("#{app_path}/#{database_path}") + end + end +end |