rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Allow model associations to reference class_name: self.name

Open avit opened this issue 5 years ago • 4 comments
trafficstars

When used in concern mixins, the class name that the association is included in may be declared dynamically, instead of a static string.

This now only verifies that the class_name: option is not referencing a constant, so other (dynamic) means of passing a string to the association reflection can be supported.


Before submitting the PR make sure the following are checked:

  • [x] Wrote good commit messages.
  • [x] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [ ] Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • [x] Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

avit avatar Dec 24 '19 19:12 avit

Migrated from rubocop-hq/rubocop#6862

avit avatar Dec 24 '19 19:12 avit

@avit Ping

pirj avatar Dec 25 '21 10:12 pirj

Another thought: is this cop even needed anymore? I believe it should be deleted instead.

Rails now validates that the option sent to class_name is a string so it seems redundant to also check it with Rubocop.

avit avatar Dec 29 '21 18:12 avit

is this cop even needed anymore? Rails now validates that the option sent to class_name is a string

In what version Rails has introduced this check? We support Rails 4.2+.

pirj avatar Dec 30 '21 11:12 pirj