aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/rake
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-09-03 17:31:38 +0200
committerYves Senn <yves.senn@gmail.com>2014-09-03 18:02:44 +0200
commitded17a498aaed63a80fe0bbf4d184aa3e468b023 (patch)
treef552d5c9e2e8b7f01d3cda3f1c94807afbcbb421 /railties/test/application/rake
parente2ce4c7aa3e15ffba9436bd8d179a28351d41e1f (diff)
downloadrails-ded17a498aaed63a80fe0bbf4d184aa3e468b023.tar.gz
rails-ded17a498aaed63a80fe0bbf4d184aa3e468b023.tar.bz2
rails-ded17a498aaed63a80fe0bbf4d184aa3e468b023.zip
schema loading rake tasks maintain database connection for current env.
[Joshua Cody & Yves Senn] Closes #16757. Prior to this patch schema loading rake tasks had the potential to leak a connection to a different database. This had side-effects when rake tasks operating on the current connection (like `db:seed`) were chained.
Diffstat (limited to 'railties/test/application/rake')
-rw-r--r--railties/test/application/rake/dbs_test.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index 15414db00f..c727e0e46d 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -173,6 +173,32 @@ module ApplicationTests
"your test schema automatically, see the release notes for details.\n", output
end
end
+
+ test 'db:setup loads schema and seeds database' do
+ begin
+ @old_env = ENV["RAILS_ENV"]
+ ENV.delete "RAILS_ENV"
+
+ app_file 'db/schema.rb', <<-RUBY
+ ActiveRecord::Schema.define(version: "1") do
+ create_table :users do |t|
+ t.string :name
+ end
+ end
+ RUBY
+
+ app_file 'db/seeds.rb', <<-RUBY
+ puts ActiveRecord::Base.connection_config[:database]
+ RUBY
+
+ Dir.chdir(app_path) do
+ database_path = `bundle exec rake db:setup`
+ assert_equal "development.sqlite3", File.basename(database_path.strip)
+ end
+ ensure
+ ENV["RAILS_ENV"] = @old_env
+ end
+ end
end
end
end