Skip to content

Commit b58eb20

Browse files
authored
Merge pull request #998 from fidalgo/fidalgo/not-null-method-error
[Fix #997] Allow NotNullColumn to work with method calls
2 parents d71ac2e + 7af820e commit b58eb20

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#997](https://github.com/rubocop/rubocop-rails/issues/997): Fix to Allow `NotNullColumn` to work with method calls and variables. ([@fidalgo][])

lib/rubocop/cop/rails/not_null_column.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def on_send(node)
4545

4646
def check_add_column(node)
4747
add_not_null_column?(node) do |type, pairs|
48-
return if type.value == :virtual || type.value == 'virtual'
48+
return if type.respond_to?(:value) && (type.value == :virtual || type.value == 'virtual')
4949

5050
check_pairs(pairs)
5151
end

spec/rubocop/cop/rails/not_null_column_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
end
2222
end
2323

24+
context 'with the type argument is a variable' do
25+
it 'does not register an offense' do
26+
expect_no_offenses(<<~RUBY)
27+
add_column(:users, :name, type, default: 'default')
28+
RUBY
29+
end
30+
end
31+
2432
context 'with null: false and default: nil' do
2533
it 'reports an offense' do
2634
expect_offense(<<~RUBY)

0 commit comments

Comments
 (0)