From ba882934bb66e240aef5e240272f3875ff86b8e7 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 25 Dec 2013 09:47:57 -0500 Subject: [PATCH 1/4] Partial fix of database url tests Prior to #13463 when `DATABASE_URL` was set, Rails automagically used that value instead of the database.yml. There are tests in dbs_test that expect this to still be true. After that PR, `RAILS_DATABASE_URL` is expected to be read into the YAML file via ERB, this PR fixes that behavior. Note: this does not entirely fix the tests. It seems that `ActiveRecord::Tasks::DatabaseTasks.current_config` does not process the url string correctly (convert it into a hash), and ` ActiveRecord::Tasks::DatabaseTasks.structure_load(current_config, filename)` as well as other methods in `DatabaseTasks` expect a hash. It seems like we should involve the resolver somewhere in this process to correctly convert the database url, I do not know the best place for that /cc @josevalim --- railties/test/application/rake/dbs_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 9a36d1ca01..3577aa2e6b 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -20,9 +20,12 @@ module ApplicationTests end def set_database_url - ENV['DATABASE_URL'] = File.join("sqlite3://:@localhost", database_url_db_name) + ENV['RAILS_DATABASE_URL'] = File.join("sqlite3://:@localhost", database_url_db_name) # ensure it's using the DATABASE_URL FileUtils.rm_rf("#{app_path}/config/database.yml") + File.open("#{app_path}/config/database.yml", 'w') do |f| + f << {ENV['RAILS_ENV'] => '<%= ENV["RAILS_DATABASE_URL"] %>'}.to_yaml + end end def expected From 707be603cfae39e82b63bbcf1fc64a2392edb693 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 25 Dec 2013 17:25:38 -0500 Subject: [PATCH 2/4] ensure environment is run before db:structure:load Right now `db:drop` depends on `load_config` since so when `db:drop` gets executed `load_config` gets run. `db:structure:load` depends on `[:environment, :load_config]`. So before it runs, it executes `environment` but because `load_config` has already executed it is skipped. Note `db:load_config` is "invoke"-d twice, but only "execute"-d once: ``` ** Invoke db:drop (first_time) ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:drop ** Invoke db:structure:load (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config ** Execute db:structure:load ``` The fix for this is making sure that the environment is run before any `load_config`: ``` ** Invoke environment (first_time) ** Execute environment ** Invoke db:drop (first_time) ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:drop ** Invoke db:structure:load (first_time) ** Invoke environment ** Invoke db:load_config ** Execute db:structure:load ``` --- railties/test/application/rake/dbs_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 3577aa2e6b..f8c7f98b03 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -129,7 +129,7 @@ module ApplicationTests bundle exec rake db:migrate db:structure:dump` structure_dump = File.read("db/structure.sql") assert_match(/CREATE TABLE \"books\"/, structure_dump) - `bundle exec rake db:drop db:structure:load` + `bundle exec rake environment db:drop db:structure:load` assert_match(/#{expected[:database]}/, ActiveRecord::Base.connection_config[:database]) require "#{app_path}/app/models/book" From d0926d3d5e8ad9378c5f976db819d8c949314b59 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 25 Dec 2013 18:27:09 -0500 Subject: [PATCH 3/4] fix 2.1.0 bug :( --- railties/test/application/rake/dbs_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index f8c7f98b03..0f4f01df1b 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -24,7 +24,7 @@ module ApplicationTests # ensure it's using the DATABASE_URL FileUtils.rm_rf("#{app_path}/config/database.yml") File.open("#{app_path}/config/database.yml", 'w') do |f| - f << {ENV['RAILS_ENV'] => '<%= ENV["RAILS_DATABASE_URL"] %>'}.to_yaml + f << {ENV['RAILS_ENV'] => %Q{<%= ENV['RAILS_DATABASE_URL'] %>}}.to_yaml end end From 2409c61661f0b1c4f946a99c215cc4b4635c0cd6 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 25 Dec 2013 18:45:26 -0500 Subject: [PATCH 4/4] Fix failure introduced from #13488 --- activerecord/test/cases/tasks/database_tasks_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index a9a114328c..3257b782a9 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -143,7 +143,7 @@ module ActiveRecord def test_establishes_connection_for_the_given_environment ActiveRecord::Tasks::DatabaseTasks.stubs(:create).returns true - ActiveRecord::Base.expects(:establish_connection).with('development') + ActiveRecord::Base.expects(:establish_connection).with(:development) ActiveRecord::Tasks::DatabaseTasks.create_current( ActiveSupport::StringInquirer.new('development')