New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace shallow mocks with Ruby classes #33326
Conversation
r? @kamipo (@rails-bot has picked a reviewer for you, use r? to override) |
6054a2b
to
194eb22
Compare
While preparing this I realised that some stubbed returns values serve no purpose, so this patch drops those as well. Step 3 in rails#33162
194eb22
to
f7bfb3d
Compare
end.new | ||
|
||
connection.pool = Class.new do | ||
def lock_thread=(lock_thread); false; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning false
seems extra to me. There is one more occurrence below. See diff:
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index 2d8cbed24e..2ead2c4816 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -842,7 +842,7 @@ def rollback_transaction(*args); end
end.new
connection.pool = Class.new do
- def lock_thread=(lock_thread); false; end
+ def lock_thread=(lock_thread); end
end.new
connection.expects(:begin_transaction).with(joinable: false)
@@ -863,7 +863,7 @@ def rollback_transaction(*args)
end.new
connection.pool = Class.new do
- def lock_thread=(lock_thread); false; end
+ def lock_thread=(lock_thread); end
end.new
fire_connection_notification(connection)
ActiveRecord::Tasks::DatabaseTasks.create @configuration | ||
end | ||
end | ||
end | ||
|
||
class MySQLDBDropTest < ActiveRecord::TestCase | ||
def setup | ||
@connection = stub(drop_database: true) | ||
@connection = Class.new { def drop_database(name); true end }.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like returing true
doesn't make any effect on test cases, so i think we can omit returing true
too.
diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index ff2d66b17e..155b060b1e 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -104,7 +104,7 @@ def test_raises_error
class MySQLDBDropTest < ActiveRecord::TestCase
def setup
- @connection = Class.new { def drop_database(name); true end }.new
+ @connection = Class.new { def drop_database(name); end }.new
@configuration = {
"adapter" => "mysql2",
"database" => "my-app-db"
Remove returning of `false` value for stubbed `lock_thread=` methods since there aren't any needs in it. Remove unnecessary returning of `true` for stubbed `drop_database` method. Follow up rails#33309. Related to rails#33162, rails#33326.
While preparing this I realised that some stubbed returns values
serve no purpose, so this patch drops those as well.
Step 3 in #33162