aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorutilum <oz@utilum.com>2018-07-19 11:48:05 +0300
committerutilum <oz@utilum.com>2018-07-22 08:38:56 +0300
commit82e42c1bd890bbd1e3b718b1273ef3cd9a5b5623 (patch)
treeaa3ed02a915bdbf1c2153b512ad1a1e00875fdc8 /activerecord/test/cases
parentd89937505867eac91830d34a97d55b08d48573fc (diff)
downloadrails-82e42c1bd890bbd1e3b718b1273ef3cd9a5b5623.tar.gz
rails-82e42c1bd890bbd1e3b718b1273ef3cd9a5b5623.tar.bz2
rails-82e42c1bd890bbd1e3b718b1273ef3cd9a5b5623.zip
Replace permissive Mocha expectations
Step 6 in #33162 When using Mocha like this: `ActiveRecord::Base.expects(:establish_connection).with(some_args)`, the expectations created look something like this: ``` @expectations= [#<Expectation:0x561350d968e0 expected exactly once, not yet invoked: ActiveRecord::Base.establish_connection("adapter" => "mysql2", "database" => nil) >, #<Expectation:0x561350dab8f8 allowed any number of times, not yet invoked: ActiveRecord::Base.establish_connection(any_parameters) >, #<Expectation:0x561350dc30c0 allowed any number of times, not yet invoked: ActiveRecord::Base.connection(any_parameters) >] ``` Minitest mocking (and the way we use it in `MethodCallAssertions`) expressly refuses to facilitate such permissiive expectations, insisting that all calls be specified in the actual expected order. This patch replaces such calls to `Mocha#expects` with `ActiveSupport::Testing::MethodCallAssertions` and specifies all expected calls in the epxected order.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/tasks/mysql_rake_test.rb29
-rw-r--r--activerecord/test/cases/tasks/postgresql_rake_test.rb89
2 files changed, 86 insertions, 32 deletions
diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index a86ddd3c16..eeb4222d97 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -21,11 +21,17 @@ if current_adapter?(:Mysql2Adapter)
end
def test_establishes_connection_without_database
- ActiveRecord::Base.stubs(:establish_connection)
ActiveRecord::Base.stub(:connection, @connection) do
- ActiveRecord::Base.expects(:establish_connection).
- with("adapter" => "mysql2", "database" => nil)
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ [ "adapter" => "mysql2", "database" => nil ],
+ [ "adapter" => "mysql2", "database" => "my-app-db" ],
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
@@ -58,12 +64,17 @@ if current_adapter?(:Mysql2Adapter)
end
def test_establishes_connection_to_database
- ActiveRecord::Base.stubs(:establish_connection)
-
ActiveRecord::Base.stub(:connection, @connection) do
- ActiveRecord::Base.expects(:establish_connection).with(@configuration)
-
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ ["adapter" => "mysql2", "database" => nil],
+ [@configuration]
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb
index 289847e514..00005e7a0d 100644
--- a/activerecord/test/cases/tasks/postgresql_rake_test.rb
+++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -21,14 +21,24 @@ if current_adapter?(:PostgreSQLAdapter)
end
def test_establishes_connection_to_postgresql_database
- ActiveRecord::Base.stubs(:establish_connection)
ActiveRecord::Base.stub(:connection, @connection) do
- ActiveRecord::Base.expects(:establish_connection).with(
- "adapter" => "postgresql",
- "database" => "postgres",
- "schema_search_path" => "public"
- )
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ [
+ "adapter" => "postgresql",
+ "database" => "postgres",
+ "schema_search_path" => "public"
+ ],
+ [
+ "adapter" => "postgresql",
+ "database" => "my-app-db"
+ ]
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
@@ -78,11 +88,23 @@ if current_adapter?(:PostgreSQLAdapter)
end
def test_establishes_connection_to_new_database
- ActiveRecord::Base.stubs(:establish_connection)
ActiveRecord::Base.stub(:connection, @connection) do
- ActiveRecord::Base.expects(:establish_connection).with(@configuration)
-
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ [
+ "adapter" => "postgresql",
+ "database" => "postgres",
+ "schema_search_path" => "public"
+ ],
+ [
+ @configuration
+ ]
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
@@ -207,15 +229,24 @@ if current_adapter?(:PostgreSQLAdapter)
end
def test_establishes_connection_to_postgresql_database
- ActiveRecord::Base.stubs(:establish_connection)
with_stubbed_connection do
- ActiveRecord::Base.expects(:establish_connection).with(
- "adapter" => "postgresql",
- "database" => "postgres",
- "schema_search_path" => "public"
- )
-
- ActiveRecord::Tasks::DatabaseTasks.purge @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ [
+ "adapter" => "postgresql",
+ "database" => "postgres",
+ "schema_search_path" => "public"
+ ],
+ [
+ "adapter" => "postgresql",
+ "database" => "my-app-db"
+ ]
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.purge @configuration
+ end
end
end
@@ -244,11 +275,23 @@ if current_adapter?(:PostgreSQLAdapter)
end
def test_establishes_connection
- ActiveRecord::Base.stubs(:establish_connection)
with_stubbed_connection do
- ActiveRecord::Base.expects(:establish_connection).with(@configuration)
-
- ActiveRecord::Tasks::DatabaseTasks.purge @configuration
+ assert_called_with(
+ ActiveRecord::Base,
+ :establish_connection,
+ [
+ [
+ "adapter" => "postgresql",
+ "database" => "postgres",
+ "schema_search_path" => "public"
+ ],
+ [
+ @configuration
+ ]
+ ]
+ ) do
+ ActiveRecord::Tasks::DatabaseTasks.purge @configuration
+ end
end
end