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

Don't register BulkChangeTable offense if block intervenes #170

Merged
merged 1 commit into from
Dec 8, 2019

Conversation

mvz
Copy link
Contributor

@mvz mvz commented Dec 6, 2019

Replace this text with a summary of the changes in your PR.
The more detailed you are, the better.

The Rails/BulkChangeTable cop currently won't suggest combining table change method calls if there is another method call between them. However, this logic fails if the intervening call has a block, like so:

add_column :users, :name, :string, null: false
User.find_each do |user|
  user.update(name: user.nick_name)
end
remove_column :users, :nickname

This pull request fixes that problem by looking at all of the method body's children, not just the :send nodes.

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

@mvz mvz force-pushed the make-bulk-change-table-handle-blocks branch from 20544c6 to cd182c0 Compare December 6, 2019 20:11
@koic koic merged commit f9224f9 into rubocop:master Dec 8, 2019
@koic
Copy link
Member

koic commented Dec 8, 2019

Thanks!

@mvz mvz deleted the make-bulk-change-table-handle-blocks branch December 8, 2019 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants