Skip to content

Commit

Permalink
Allow Rails/ReflectionClassName to use string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
r7kamura committed Apr 17, 2019
1 parent fc0fe57 commit d6eb151
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
* [#6914](https://github.com/rubocop-hq/rubocop/issues/6914): [Fix #6914] Fix an error for `Rails/RedundantAllowNil` when with interpolations. ([@Blue-Pix][])
* [#6941](https://github.com/rubocop-hq/rubocop/issues/6941): Add missing absence validations to `Rails/Validation`. ([@jmanian][])
* [#6926](https://github.com/rubocop-hq/rubocop/issues/6926): [Fix #6926] Allow nil values to unset config defaults. ([@dduugg][])
* [#6946](https://github.com/rubocop-hq/rubocop/pull/6946): Allow `Rails/ReflectionClassName` to use string interpolation for `class_name`. ([@r7kamura][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/reflection_class_name.rb
Expand Up @@ -21,7 +21,7 @@ class ReflectionClassName < Cop
PATTERN

def_node_search :reflection_class_name, <<-PATTERN
(pair (sym :class_name) [!str !sym])
(pair (sym :class_name) [!dstr !str !sym])
PATTERN

def on_send(node)
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/reflection_class_name_spec.rb
Expand Up @@ -35,6 +35,12 @@
end
end

it 'does not register an offense when using string with interpolation' do
expect_no_offenses(<<-'RUBY'.strip_indent)
has_many :accounts, class_name: "#{prefix}Account"
RUBY
end

it 'does not register an offense when using `foreign_key :account_id`' do
expect_no_offenses(<<-RUBY.strip_indent)
has_many :accounts, class_name: 'Account', foreign_key: :account_id
Expand Down

0 comments on commit d6eb151

Please sign in to comment.