Skip to content

Commit d098903

Browse files
committed
[Fix #979] Fix an error for Rails/ThreeStateBooleanColumn
Fixes #979. This PR fixes an error for `Rails/ThreeStateBooleanColumn` when using `t.boolean` in `drop_table`.
1 parent 73fd423 commit d098903

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#979](https://github.com/rubocop/rubocop-rails/issues/979): Fix an error for `Rails/ThreeStateBooleanColumn` when using `t.boolean` in `drop_table`. ([@koic][])

lib/rubocop/cop/rails/three_state_boolean_column.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def on_send(node)
4646

4747
def_node = node.each_ancestor(:def, :defs).first
4848
table_node = table_node(node)
49-
return if def_node && change_column_null?(def_node, table_node.value, column_node.value)
49+
if def_node && (table_node.nil? || change_column_null?(def_node, table_node.value, column_node.value))
50+
return
51+
end
5052

5153
add_offense(node)
5254
end

spec/rubocop/cop/rails/three_state_boolean_column_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ def change
115115
RUBY
116116
end
117117

118+
it 'does not register an offense when using `t.boolean` in `drop_table`' do
119+
expect_no_offenses(<<~RUBY)
120+
def change
121+
drop_table(:users) do |t|
122+
t.boolean :active
123+
end
124+
end
125+
RUBY
126+
end
127+
118128
it 'does not register an offense when using `#change_column_null`' do
119129
expect_no_offenses(<<~RUBY)
120130
def change

0 commit comments

Comments
 (0)