Skip to content

Commit

Permalink
Merge pull request #1409 from Earlopain/reversible-migration-error
Browse files Browse the repository at this point in the history
Fix an error for `Rails/ReversibleMigration` when calling `drop_table` without any arguments
  • Loading branch information
koic authored Jan 8, 2025
2 parents 1eacbc3 + 6a16fe3 commit 574e4ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_error_reversible_migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1409](https://github.com/rubocop/rubocop-rails/pull/1409): Fix an error for `Rails/ReversibleMigration` when calling `drop_table` without any arguments. ([@earlopain][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ def check_irreversible_schema_statement_node(node)
end

def check_drop_table_node(node)
return unless (last_argument = node.last_argument)

drop_table_call(node) do
unless node.parent.block_type? || node.last_argument.block_pass_type?
unless node.parent.block_type? || last_argument.block_pass_type?
add_offense(node, message: format(MSG, action: 'drop_table(without block)'))
end
end
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 @@ -121,6 +121,10 @@ def change
it_behaves_like 'offense', 'drop_table(without block)', <<~RUBY
drop_table :users
RUBY

it_behaves_like 'accepts', 'drop_table(without arguments)', <<~RUBY
drop_table
RUBY
end

context 'change_column' do
Expand Down

0 comments on commit 574e4ef

Please sign in to comment.