Skip to content

Commit

Permalink
Fix an error for Rails/ReversibleMigration when calling `drop_table…
Browse files Browse the repository at this point in the history
…` without any arguments

As it happens when you type it
  • Loading branch information
Earlopain committed Jan 8, 2025
1 parent 1eacbc3 commit 2379661
Show file tree
Hide file tree
Showing 3 changed files with 6 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][])
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 @@ -216,7 +216,7 @@ def check_irreversible_schema_statement_node(node)

def check_drop_table_node(node)
drop_table_call(node) do
unless node.parent.block_type? || node.last_argument.block_pass_type?
unless node.parent.block_type? || node.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 'offense', 'drop_table(without block)', <<~RUBY
drop_table
RUBY
end

context 'change_column' do
Expand Down

0 comments on commit 2379661

Please sign in to comment.