Skip to content

Commit 150728d

Browse files
authored
Merge pull request rubocop#785 from koic/fix_false_positive_for_rails_dynamic_find_by
[Fix rubocop#778] Fix a false positive for `Rails/DynamicFindBy`
2 parents 181b497 + 449162b commit 150728d

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
@@ -354,6 +354,7 @@ Rails/DynamicFindBy:
354354
- find_by_token_for
355355
AllowedReceivers:
356356
- Gem::Specification
357+
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
357358

358359
Rails/EagerEvaluationLogMessage:
359360
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
@@ -31,12 +31,14 @@ module Rails
3131
# User.find_by_sql(users_sql)
3232
# User.find_by_token_for(:password_reset, token)
3333
#
34-
# @example AllowedReceivers: ['Gem::Specification'] (default)
34+
# @example AllowedReceivers: ['Gem::Specification', 'page'] (default)
3535
# # bad
3636
# Specification.find_by_name('backend').gem_dir
37+
# page.find_by_id('a_dom_id').click
3738
#
3839
# # good
3940
# Gem::Specification.find_by_name('backend').gem_dir
41+
# page.find_by_id('a_dom_id').click
4042
class DynamicFindBy < Base
4143
include ActiveRecordHelper
4244
extend AutoCorrector

0 commit comments

Comments
 (0)