diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2018-07-22 09:07:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-22 09:07:56 +0200 |
commit | 9ca579ad6e05011a7b056cd3075fe09571da12e4 (patch) | |
tree | aa3ed02a915bdbf1c2153b512ad1a1e00875fdc8 /activerecord/test/cases/tasks/database_tasks_test.rb | |
parent | d3ba91315852d27e95a935359f4ad752c27d02d3 (diff) | |
parent | 82e42c1bd890bbd1e3b718b1273ef3cd9a5b5623 (diff) | |
download | rails-9ca579ad6e05011a7b056cd3075fe09571da12e4.tar.gz rails-9ca579ad6e05011a7b056cd3075fe09571da12e4.tar.bz2 rails-9ca579ad6e05011a7b056cd3075fe09571da12e4.zip |
Merge pull request #33409 from utilum/correct_epxectations_to_meet_minitest_strict_mocking
Use MethodCallAssertions instead of Mocha part 2
Diffstat (limited to 'activerecord/test/cases/tasks/database_tasks_test.rb')
-rw-r--r-- | activerecord/test/cases/tasks/database_tasks_test.rb | 26 |
1 files changed, 15 insertions, 11 deletions
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 |