Skip to content

Commit

Permalink
Merge pull request #785 from koic/fix_false_positive_for_rails_dynami…
Browse files Browse the repository at this point in the history
…c_find_by

[Fix #778] Fix a false positive for `Rails/DynamicFindBy`
  • Loading branch information
koic authored Sep 30, 2022
2 parents 181b497 + 449162b commit 150728d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_false_positive_for_rails_dynamic_find_by.md
Original file line number Diff line number Diff line change
@@ -0,0 +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][])
1 change: 1 addition & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Rails/DynamicFindBy:
- find_by_token_for
AllowedReceivers:
- Gem::Specification
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778

Rails/EagerEvaluationLogMessage:
Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/rails/dynamic_find_by.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ module Rails
# User.find_by_sql(users_sql)
# User.find_by_token_for(:password_reset, token)
#
# @example AllowedReceivers: ['Gem::Specification'] (default)
# @example AllowedReceivers: ['Gem::Specification', 'page'] (default)
# # bad
# Specification.find_by_name('backend').gem_dir
# page.find_by_id('a_dom_id').click
#
# # good
# Gem::Specification.find_by_name('backend').gem_dir
# page.find_by_id('a_dom_id').click
class DynamicFindBy < Base
include ActiveRecordHelper
extend AutoCorrector
Expand Down

0 comments on commit 150728d

Please sign in to comment.