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

Fix an error for Rails/ReversibleMigration when calling drop_table without any arguments #1409

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading