diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-07-09 15:24:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-09 15:24:50 -0400 |
commit | 2cc514a74a293d175904c08fd74b8a037d8959e2 (patch) | |
tree | c13f96886fd7e983c5fb0cac8cc3609475aa515a /activerecord/test | |
parent | d4ea114bd611c608482375af94f49e2d54889202 (diff) | |
parent | 8c1e1726dcec3b178cf462636d08355d5b190f78 (diff) | |
download | rails-2cc514a74a293d175904c08fd74b8a037d8959e2.tar.gz rails-2cc514a74a293d175904c08fd74b8a037d8959e2.tar.bz2 rails-2cc514a74a293d175904c08fd74b8a037d8959e2.zip |
Merge pull request #33309 from utilum/remove_unnecessary_mocha_stubs
Remove unnecessary Mocha stubs
Diffstat (limited to 'activerecord/test')
5 files changed, 18 insertions, 48 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb index 976c5dde58..58fa39d18c 100644 --- a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb @@ -158,7 +158,6 @@ class Mysql2ActiveSchemaTest < ActiveRecord::Mysql2TestCase def test_indexes_in_create ActiveRecord::Base.connection.stubs(:data_source_exists?).with(:temp).returns(false) - ActiveRecord::Base.connection.stubs(:index_name_exists?).with(:index_temp_on_zip).returns(false) expected = "CREATE TEMPORARY TABLE `temp` ( INDEX `index_temp_on_zip` (`zip`)) AS SELECT id, name, zip FROM a_really_complicated_query" actual = ActiveRecord::Base.connection.create_table(:temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query") do |t| diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 60c7cb1bb4..a6f684a137 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -135,7 +135,7 @@ module ActiveRecord def test_ignores_remote_databases @configurations["development"].merge!("host" => "my.server.tld") - $stderr.stubs(:puts).returns(nil) + $stderr.stubs(:puts) assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do ActiveRecord::Tasks::DatabaseTasks.create_all @@ -184,7 +184,7 @@ module ActiveRecord } ActiveRecord::Base.stubs(:configurations).returns(@configurations) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) end def test_creates_current_environment_database @@ -238,7 +238,7 @@ module ActiveRecord end def test_establishes_connection_for_the_given_environments - ActiveRecord::Tasks::DatabaseTasks.stubs(:create).returns true + ActiveRecord::Tasks::DatabaseTasks.stubs(:create) ActiveRecord::Base.expects(:establish_connection).with(:development) @@ -257,7 +257,7 @@ module ActiveRecord } ActiveRecord::Base.stubs(:configurations).returns(@configurations) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) end def test_creates_current_environment_database @@ -319,7 +319,7 @@ module ActiveRecord end def test_establishes_connection_for_the_given_environments_config - ActiveRecord::Tasks::DatabaseTasks.stubs(:create).returns true + ActiveRecord::Tasks::DatabaseTasks.stubs(:create) ActiveRecord::Base.expects(:establish_connection).with(:development) @@ -357,7 +357,7 @@ module ActiveRecord def test_ignores_remote_databases @configurations[:development].merge!("host" => "my.server.tld") - $stderr.stubs(:puts).returns(nil) + $stderr.stubs(:puts) assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do ActiveRecord::Tasks::DatabaseTasks.drop_all diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb index 6cddfaefeb..ddbff81e72 100644 --- a/activerecord/test/cases/tasks/mysql_rake_test.rb +++ b/activerecord/test/cases/tasks/mysql_rake_test.rb @@ -14,7 +14,7 @@ if current_adapter?(:Mysql2Adapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -77,7 +77,6 @@ if current_adapter?(:Mysql2Adapter) class MysqlDBCreateWithInvalidPermissionsTest < ActiveRecord::TestCase def setup - @connection = stub("Connection", create_database: true) @error = Mysql2::Error.new("Invalid permissions") @configuration = { "adapter" => "mysql2", @@ -86,7 +85,6 @@ if current_adapter?(:Mysql2Adapter) "password" => "wossname" } - ActiveRecord::Base.stubs(:connection).returns(@connection) ActiveRecord::Base.stubs(:establish_connection).raises(@error) $stdout, @original_stdout = StringIO.new, $stdout @@ -113,7 +111,7 @@ if current_adapter?(:Mysql2Adapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -151,7 +149,7 @@ if current_adapter?(:Mysql2Adapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) end def test_establishes_connection_to_the_appropriate_database @@ -185,7 +183,6 @@ if current_adapter?(:Mysql2Adapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_db_retrieves_charset @@ -203,7 +200,6 @@ if current_adapter?(:Mysql2Adapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_db_retrieves_collation diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb index a1a3700f07..bdce1cbd20 100644 --- a/activerecord/test/cases/tasks/postgresql_rake_test.rb +++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb @@ -14,7 +14,7 @@ if current_adapter?(:PostgreSQLAdapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -66,7 +66,7 @@ if current_adapter?(:PostgreSQLAdapter) def test_db_create_with_error_prints_message ActiveRecord::Base.stubs(:establish_connection).raises(Exception) - $stderr.stubs(:puts).returns(true) + $stderr.stubs(:puts) $stderr.expects(:puts). with("Couldn't create database for #{@configuration.inspect}") @@ -99,7 +99,7 @@ if current_adapter?(:PostgreSQLAdapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -141,8 +141,7 @@ if current_adapter?(:PostgreSQLAdapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:clear_active_connections!).returns(true) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) end def test_clears_active_connections @@ -190,7 +189,7 @@ if current_adapter?(:PostgreSQLAdapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) end def test_db_retrieves_charset @@ -208,7 +207,6 @@ if current_adapter?(:PostgreSQLAdapter) } ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_db_retrieves_collation @@ -219,16 +217,12 @@ if current_adapter?(:PostgreSQLAdapter) class PostgreSQLStructureDumpTest < ActiveRecord::TestCase def setup - @connection = stub(schema_search_path: nil, structure_dump: true) @configuration = { "adapter" => "postgresql", "database" => "my-app-db" } @filename = "/tmp/awesome-file.sql" FileUtils.touch(@filename) - - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def teardown @@ -358,14 +352,10 @@ if current_adapter?(:PostgreSQLAdapter) class PostgreSQLStructureLoadTest < ActiveRecord::TestCase def setup - @connection = stub @configuration = { "adapter" => "postgresql", "database" => "my-app-db" } - - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_structure_load diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb index d368a7a6ee..7b4cb51c56 100644 --- a/activerecord/test/cases/tasks/sqlite_rake_test.rb +++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb @@ -9,15 +9,12 @@ if current_adapter?(:SQLite3Adapter) class SqliteDBCreateTest < ActiveRecord::TestCase def setup @database = "db_create.sqlite3" - @connection = stub :connection @configuration = { "adapter" => "sqlite3", "database" => @database } - File.stubs(:exist?).returns(false) - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) + ActiveRecord::Base.stubs(:establish_connection) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -49,7 +46,6 @@ if current_adapter?(:SQLite3Adapter) def test_db_create_with_file_does_nothing File.stubs(:exist?).returns(true) - $stderr.stubs(:puts).returns(nil) ActiveRecord::Base.expects(:establish_connection).never @@ -84,7 +80,7 @@ if current_adapter?(:SQLite3Adapter) Pathname.stubs(:new).returns(@path) File.stubs(:join).returns("/former/relative/path") - FileUtils.stubs(:rm).returns(true) + FileUtils.stubs(:rm) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr @@ -101,16 +97,13 @@ if current_adapter?(:SQLite3Adapter) end def test_removes_file_with_absolute_path - File.stubs(:exist?).returns(true) - @path.stubs(:absolute?).returns(true) - FileUtils.expects(:rm).with("/absolute/path") ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root" end def test_generates_absolute_path_with_given_root - @path.stubs(:absolute?).returns(false) + @path.stubs(:absolute?) File.expects(:join).with("/rails/root", @path). returns("/former/relative/path") @@ -119,8 +112,7 @@ if current_adapter?(:SQLite3Adapter) end def test_removes_file_with_relative_path - File.stubs(:exist?).returns(true) - @path.stubs(:absolute?).returns(false) + @path.stubs(:absolute?) FileUtils.expects(:rm).with("/former/relative/path") @@ -143,9 +135,7 @@ if current_adapter?(:SQLite3Adapter) "database" => @database } - File.stubs(:exist?).returns(false) ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_db_retrieves_charset @@ -157,15 +147,10 @@ if current_adapter?(:SQLite3Adapter) class SqliteDBCollationTest < ActiveRecord::TestCase def setup @database = "db_create.sqlite3" - @connection = stub :connection @configuration = { "adapter" => "sqlite3", "database" => @database } - - File.stubs(:exist?).returns(false) - ActiveRecord::Base.stubs(:connection).returns(@connection) - ActiveRecord::Base.stubs(:establish_connection).returns(true) end def test_db_retrieves_collation |