Skip to content

Commit 574e4ef

Browse files
authored
Merge pull request #1409 from Earlopain/reversible-migration-error
Fix an error for `Rails/ReversibleMigration` when calling `drop_table` without any arguments
2 parents 1eacbc3 + 6a16fe3 commit 574e4ef

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1409](https://github.com/rubocop/rubocop-rails/pull/1409): Fix an error for `Rails/ReversibleMigration` when calling `drop_table` without any arguments. ([@earlopain][])

lib/rubocop/cop/rails/reversible_migration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ def check_irreversible_schema_statement_node(node)
215215
end
216216

217217
def check_drop_table_node(node)
218+
return unless (last_argument = node.last_argument)
219+
218220
drop_table_call(node) do
219-
unless node.parent.block_type? || node.last_argument.block_pass_type?
221+
unless node.parent.block_type? || last_argument.block_pass_type?
220222
add_offense(node, message: format(MSG, action: 'drop_table(without block)'))
221223
end
222224
end

spec/rubocop/cop/rails/reversible_migration_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def change
121121
it_behaves_like 'offense', 'drop_table(without block)', <<~RUBY
122122
drop_table :users
123123
RUBY
124+
125+
it_behaves_like 'accepts', 'drop_table(without arguments)', <<~RUBY
126+
drop_table
127+
RUBY
124128
end
125129

126130
context 'change_column' do

0 commit comments

Comments
 (0)