diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6a74c26c..265cdd2770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [#12](https://github.com/rubocop-hq/rubocop-rails/issues/12): Fix a false positive for `Rails/SkipsModelValidations` when passing a boolean literal to `touch`. ([@eugeneius][]) + ## 2.5.2 (2020-04-09) ### Bug fixes diff --git a/lib/rubocop/cop/rails/skips_model_validations.rb b/lib/rubocop/cop/rails/skips_model_validations.rb index 03ec93fe5b..d5c7b18a5a 100644 --- a/lib/rubocop/cop/rails/skips_model_validations.rb +++ b/lib/rubocop/cop/rails/skips_model_validations.rb @@ -50,7 +50,10 @@ class SkipsModelValidations < Cop update_counters].freeze def_node_matcher :good_touch?, <<~PATTERN - (send (const nil? :FileUtils) :touch ...) + { + (send (const nil? :FileUtils) :touch ...) + (send _ :touch {true false}) + } PATTERN def on_send(node) diff --git a/spec/rubocop/cop/rails/skips_model_validations_spec.rb b/spec/rubocop/cop/rails/skips_model_validations_spec.rb index 171e88dcf0..9f25d5c736 100644 --- a/spec/rubocop/cop/rails/skips_model_validations_spec.rb +++ b/spec/rubocop/cop/rails/skips_model_validations_spec.rb @@ -35,6 +35,14 @@ it 'accepts FileUtils.touch' do expect_no_offenses("FileUtils.touch('file')") end + + it 'accepts touch with literal true' do + expect_no_offenses('belongs_to(:user).touch(true)') + end + + it 'accepts touch with literal false' do + expect_no_offenses('belongs_to(:user).touch(false)') + end end context 'with methods that require at least an argument' do