Skip to content

Commit 0d318fb

Browse files
committed
Fix an error for Rails/NotNullColumn when the block for change_table is empty
1 parent d99bbe1 commit 0d318fb

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1299](https://github.com/rubocop/rubocop-rails/pull/1299): Fix an error for `Rails/NotNullColumn` when the block for `change_table` is empty. ([@earlopain][])

lib/rubocop/cop/rails/not_null_column.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def check_add_reference_in_change_table(node, table)
136136

137137
def check_change_table(node)
138138
change_table?(node) do |table|
139+
next unless node.body
140+
139141
children = node.body.begin_type? ? node.body.children : [node.body]
140142
children.each do |child|
141143
check_add_column_in_change_table(child, table)

spec/rubocop/cop/rails/not_null_column_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def change
8585
end
8686
RUBY
8787
end
88+
89+
it 'does not register an offense when the block is empty' do
90+
expect_no_offenses(<<~RUBY)
91+
class ExampleMigration < ActiveRecord::Migration[7.0]
92+
def change
93+
change_table :invoices do |t|
94+
end
95+
end
96+
end
97+
RUBY
98+
end
8899
end
89100

90101
context 'with change_table call' do

0 commit comments

Comments
 (0)