From a94d6ae81fea43d075ab31d53c54d3065c57d233 Mon Sep 17 00:00:00 2001 From: utilum Date: Sat, 21 Jul 2018 01:30:15 +0300 Subject: Fix Mocha replacement that slipped out of #33337 --- .../test/cases/tasks/database_tasks_test.rb | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'activerecord/test/cases/tasks/database_tasks_test.rb') diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 1f79f1a630..b9cc08c446 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -143,9 +143,6 @@ module ActiveRecord def setup @configurations = { "development" => { "database" => "my-db" } } - # To refrain from connecting to a newly created empty DB in sqlite3_mem tests - ActiveRecord::Base.connection_handler.stubs(:establish_connection) - $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr end @@ -157,7 +154,7 @@ module ActiveRecord def test_ignores_configurations_without_databases @configurations["development"].merge!("database" => nil) - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all end @@ -167,7 +164,7 @@ module ActiveRecord def test_ignores_remote_databases @configurations["development"].merge!("host" => "my.server.tld") - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all end @@ -177,7 +174,7 @@ module ActiveRecord def test_warning_for_remote_databases @configurations["development"].merge!("host" => "my.server.tld") - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do ActiveRecord::Tasks::DatabaseTasks.create_all assert_match "This task only modifies local databases. my-db is on a remote host.", @@ -188,7 +185,7 @@ module ActiveRecord def test_creates_configurations_with_local_ip @configurations["development"].merge!("host" => "127.0.0.1") - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all end @@ -198,7 +195,7 @@ module ActiveRecord def test_creates_configurations_with_local_host @configurations["development"].merge!("host" => "localhost") - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all end @@ -208,7 +205,7 @@ module ActiveRecord def test_creates_configurations_with_blank_hosts @configurations["development"].merge!("host" => nil) - with_stubbed_configurations do + with_stubbed_configurations_establish_connection do assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all end @@ -217,9 +214,16 @@ module ActiveRecord private - def with_stubbed_configurations + def with_stubbed_configurations_establish_connection ActiveRecord::Base.stub(:configurations, @configurations) do - yield + # To refrain from connecting to a newly created empty DB in + # sqlite3_mem tests + ActiveRecord::Base.connection_handler.stub( + :establish_connection, + nil + ) do + yield + end end end end -- cgit v1.2.3