Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Rails/ReflectionClassName to use string interpolation #6946

Merged
merged 1 commit into from Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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