Skip to content

Commit 449162b

Browse files
committed
[Fix rubocop#778] Fix a false positive for Rails/DynamicFindBy
Fixes rubocop#778. This PR fixes a false positive for `Rails/DynamicFindBy` when using `page.find_by_id` as a Capybara testing API. This default setting emphasizes suppressing false positive over false negative.
1 parent 313cd20 commit 449162b

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#778](https://github.com/rubocop/rubocop-rails/issues/778): Fix a false positive for `Rails/DynamicFindBy` when using `page.find_by_id` as a Capybara testing API. ([@koic][])

config/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ Rails/DynamicFindBy:
352352
- find_by_sql
353353
AllowedReceivers:
354354
- Gem::Specification
355+
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
355356

356357
Rails/EagerEvaluationLogMessage:
357358
Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'

lib/rubocop/cop/rails/dynamic_find_by.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ module Rails
2929
# # good
3030
# User.find_by_sql(users_sql)
3131
#
32-
# @example AllowedReceivers: ['Gem::Specification'] (default)
32+
# @example AllowedReceivers: ['Gem::Specification', 'page'] (default)
3333
# # bad
3434
# Specification.find_by_name('backend').gem_dir
35+
# page.find_by_id('a_dom_id').click
3536
#
3637
# # good
3738
# Gem::Specification.find_by_name('backend').gem_dir
39+
# page.find_by_id('a_dom_id').click
3840
class DynamicFindBy < Base
3941
include ActiveRecordHelper
4042
extend AutoCorrector

0 commit comments

Comments
 (0)