Skip to content
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

Merged
merged 1 commit into from Jul 10, 2018

Conversation

utilum
Copy link
Contributor

@utilum utilum commented Jul 10, 2018

While preparing this I realised that some stubbed returns values
serve no purpose, so this patch drops those as well.

Step 3 in #33162

@rails-bot
Copy link

r? @kamipo

(@rails-bot has picked a reviewer for you, use r? to override)

@utilum utilum mentioned this pull request Jul 10, 2018
8 tasks
@utilum utilum force-pushed the replace_shallow_mocks_with_ruby branch from 6054a2b to 194eb22 Compare July 10, 2018 06:24
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
@utilum utilum force-pushed the replace_shallow_mocks_with_ruby branch from 194eb22 to f7bfb3d Compare July 10, 2018 06:30
@kamipo kamipo merged commit 23f80ce into rails:master Jul 10, 2018
end.new

connection.pool = Class.new do
def lock_thread=(lock_thread); false; end
Copy link
Contributor

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
Copy link
Contributor

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"

@utilum utilum deleted the replace_shallow_mocks_with_ruby branch July 10, 2018 13:05
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Jul 10, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants