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/NotNullColumn when the block for change_table is empty #1299

Merged
merged 1 commit into from
Jun 19, 2024
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_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