Skip to content

Commit

Permalink
[Fix #6914] Fix an error for Rails/RedundantAllowNil when with inte…
Browse files Browse the repository at this point in the history
…rpolations
  • Loading branch information
Blue-Pix authored and bbatsov committed Apr 10, 2019
1 parent 954580e commit e2b81c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6914](https://github.com/rubocop-hq/rubocop/issues/6914): [Fix #6914] Fix an error for `Rails/RedundantAllowNil` when with interpolations. ([@Blue-Pix][])

### Changes

* [#5977](https://github.com/rubocop-hq/rubocop/issues/5977): Remove Performance cops. ([@koic][])
Expand Down Expand Up @@ -3931,3 +3935,4 @@
[@anuja-joshi]: https://github.com/anuja-joshi
[@XrXr]: https://github.com/XrXr
[@thomthom]: https://github.com/thomthom
[@Blue-Pix]: https://github.com/Blue-Pix
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rails/redundant_allow_nil.rb
Expand Up @@ -79,10 +79,10 @@ def find_allow_nil_and_allow_blank(node)
node.each_descendant do |descendant|
next unless descendant.pair_type?

key = descendant.children.first.value
key = descendant.children.first.source

allow_nil = descendant if key == :allow_nil
allow_blank = descendant if key == :allow_blank
allow_nil = descendant if key == 'allow_nil'
allow_blank = descendant if key == 'allow_blank'

break if allow_nil && allow_blank
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/redundant_allow_nil_spec.rb
Expand Up @@ -73,4 +73,12 @@
RUBY
end
end

context 'when using string interpolation' do
it 'registers no offense' do
expect_no_offenses(<<-'RUBY'.strip_indent)
validates :details, "path_to_dynamic_validation/#{with_interpolation}": true
RUBY
end
end
end

0 comments on commit e2b81c9

Please sign in to comment.