diff --git a/CHANGELOG.md b/CHANGELOG.md index 892ad6b9cb2..5c1a02b4919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/rails/reflection_class_name.rb b/lib/rubocop/cop/rails/reflection_class_name.rb index 1bfc2f5c099..1af134c949a 100644 --- a/lib/rubocop/cop/rails/reflection_class_name.rb +++ b/lib/rubocop/cop/rails/reflection_class_name.rb @@ -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) diff --git a/spec/rubocop/cop/rails/reflection_class_name_spec.rb b/spec/rubocop/cop/rails/reflection_class_name_spec.rb index 0da8e640d17..ea08fcedf63 100644 --- a/spec/rubocop/cop/rails/reflection_class_name_spec.rb +++ b/spec/rubocop/cop/rails/reflection_class_name_spec.rb @@ -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