From ded17a498aaed63a80fe0bbf4d184aa3e468b023 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 3 Sep 2014 17:31:38 +0200 Subject: 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. --- railties/test/application/rake/dbs_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'railties/test') 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 -- cgit v1.2.3