Skip to content

Commit

Permalink
Fix an error for Rails/NotNullColumn when the block for `change_tab…
Browse files Browse the repository at this point in the history
…le` is empty
  • Loading branch information
Earlopain committed Jun 19, 2024
1 parent d99bbe1 commit 0d318fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_error_for_rails_not_null_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +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][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/not_null_column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def check_add_reference_in_change_table(node, table)

def check_change_table(node)
change_table?(node) do |table|
next unless node.body

children = node.body.begin_type? ? node.body.children : [node.body]
children.each do |child|
check_add_column_in_change_table(child, table)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/rails/not_null_column_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def change
end
RUBY
end

it 'does not register an offense when the block is empty' do
expect_no_offenses(<<~RUBY)
class ExampleMigration < ActiveRecord::Migration[7.0]
def change
change_table :invoices do |t|
end
end
end
RUBY
end
end

context 'with change_table call' do
Expand Down

0 comments on commit 0d318fb

Please sign in to comment.