File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change
1
+ * [ #1335 ] ( https://github.com/rubocop/rubocop-rails/pull/1335 ) : Fix an error for ` Rails/BulkChangeTable ` when the block for ` change_table ` is empty. ([ @earlopain ] [ ] )
Original file line number Diff line number Diff line change @@ -140,9 +140,9 @@ def on_send(node)
140
140
return unless support_bulk_alter?
141
141
return unless node . command? ( :change_table )
142
142
return if include_bulk_options? ( node )
143
- return unless node . block_node
143
+ return unless ( body = node . block_node &. body )
144
144
145
- send_nodes = send_nodes_from_change_table_block ( node . block_node . body )
145
+ send_nodes = send_nodes_from_change_table_block ( body )
146
146
147
147
add_offense_for_change_table ( node ) if count_transformations ( send_nodes ) > 1
148
148
end
Original file line number Diff line number Diff line change @@ -25,6 +25,25 @@ def change
25
25
end
26
26
end
27
27
28
+ shared_examples 'wrong arguments' do
29
+ it 'does not register an offense for `change_table` with no block' do
30
+ expect_no_offenses ( <<~RUBY )
31
+ def up
32
+ change_table(:users)
33
+ end
34
+ RUBY
35
+ end
36
+
37
+ it 'does not register an offense for `change_table` with empty block' do
38
+ expect_no_offenses ( <<~RUBY )
39
+ def up
40
+ change_table(:users) do
41
+ end
42
+ end
43
+ RUBY
44
+ end
45
+ end
46
+
28
47
shared_examples 'no offense' do
29
48
it 'does not register an offense when including combinable transformations' do
30
49
expect_no_offenses ( <<~RUBY )
@@ -45,6 +64,8 @@ def change
45
64
end
46
65
RUBY
47
66
end
67
+
68
+ it_behaves_like 'wrong arguments'
48
69
end
49
70
50
71
shared_examples 'offense for mysql' do
@@ -91,6 +112,8 @@ def change
91
112
end
92
113
RUBY
93
114
end
115
+
116
+ it_behaves_like 'wrong arguments'
94
117
end
95
118
96
119
shared_examples 'offense for postgresql' do
@@ -153,6 +176,8 @@ def change
153
176
end
154
177
RUBY
155
178
end
179
+
180
+ it_behaves_like 'wrong arguments'
156
181
end
157
182
158
183
it_behaves_like 'no offense'
You can’t perform that action at this time.
0 commit comments