Skip to content

Commit

Permalink
Merge pull request #232 from eugeneius/touch_boolean_literal
Browse files Browse the repository at this point in the history
[Fix #12] Allow passing boolean literals to touch
  • Loading branch information
koic authored Apr 12, 2020
2 parents 94745ee + 95064f6 commit c8f3e0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/cop/rails/skips_model_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/skips_model_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8f3e0c

Please sign in to comment.