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

Rails/BelongsTo does not work with scoped associations #435

Closed
syakovyn opened this issue Feb 6, 2021 · 0 comments · Fixed by #438
Closed

Rails/BelongsTo does not work with scoped associations #435

syakovyn opened this issue Feb 6, 2021 · 0 comments · Fixed by #438
Labels
bug Something isn't working

Comments

@syakovyn
Copy link

syakovyn commented Feb 6, 2021

The cop Rails/BelongsTo does not warn about using required keyword in
belongs_to :event, -> { with_deleted }, inverse_of: :task_work_templates, required: true

However, it works as expected when the scope is removed
belongs_to :event, inverse_of: :task_work_templates, required: true


Expected behavior

The cop warns about using the required keyword in belongs_to no matter a scope is specified or not.

Actual behavior

The cop does not warn about using the required keyword in belongs_to when a scope is specified.

Steps to reproduce the problem

Add a scope, e.g. -> {} to any existing belongs_to that uses required.

RuboCop version

$ bundle exec rubocop -V
1.9.1 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-darwin19)
  - rubocop-performance 1.8.1
  - rubocop-rails 2.9.1
  - rubocop-rspec 2.2.0
@koic koic added the bug Something isn't working label Feb 9, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Feb 9, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required: false`.
koic added a commit to koic/rubocop-rails that referenced this issue Feb 9, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required: false`.
koic added a commit to koic/rubocop-rails that referenced this issue Feb 9, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required: false`.
koic added a commit to koic/rubocop-rails that referenced this issue Feb 9, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required` option.
koic added a commit to koic/rubocop-rails that referenced this issue Feb 9, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required` option.
koic added a commit to koic/rubocop-rails that referenced this issue Feb 15, 2021
Fixes rubocop#435.

This PR fixes a false negative for `Rails/BelongsTo`
when using `belongs_to` lambda block with `required` option.
@koic koic closed this as completed in #438 Feb 15, 2021
koic added a commit that referenced this issue Feb 15, 2021
…s_to

[Fix #435] Fix a false negative for `Rails/BelongsTo`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants