Skip to content

Commit

Permalink
[Fix rubocop#476] Fix a false positive for Rails/ReversibleMigratin
Browse files Browse the repository at this point in the history
Fixes rubocop#476.

This PR fixes a false positive for `Rails/ReversibleMigratin`
when using `drop_table` with symbol proc.
  • Loading branch information
koic committed May 4, 2021
1 parent 5c44c5d commit 93ea87a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [#137](https://github.com/rubocop/rubocop-rails/issues/137): Make `Rails/HasManyOrHasOneDependent` aware of `readonly?` is `true`. ([@koic][])
* [#474](https://github.com/rubocop/rubocop-rails/pull/474): Fix a false negative for `Rails/SafeNavigation` when using `try!` without receiver. ([@koic][])
* [#126](https://github.com/rubocop/rubocop-rails/issues/126): Fix an incorrect auto-correct for `Rails/SafeNavigation` with `Style/RedndantSelf`. ([@koic][])
* [#476](https://github.com/rubocop/rubocop-rails/issues/476): Fix a false positive for `Rails/ReversibleMigratin` when using `drop_table` with symbol proc. ([@koic][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def check_irreversible_schema_statement_node(node)

def check_drop_table_node(node)
drop_table_call(node) do
unless node.parent.block_type?
unless node.parent.block_type? || node.last_argument.block_pass_type?
add_offense(
node,
message: format(MSG, action: 'drop_table(without block)')
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/rails/reversible_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def change
end
RUBY

it_behaves_like 'accepts', 'drop_table(with symbol proc)', <<~RUBY
drop_table :users, &:timestamps
RUBY

it_behaves_like 'offense', 'drop_table(without block)', <<~RUBY
drop_table :users
RUBY
Expand Down

0 comments on commit 93ea87a

Please sign in to comment.