Skip to content

Commit 9254ef6

Browse files
authored
Merge pull request #1456 from Earlopain/timestamp-numblock
Fix a false positive for `Rails/CreateTableWithTimestamps` with numblocks
2 parents c67ec6f + f226d20 commit 9254ef6

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1456](https://github.com/rubocop/rubocop-rails/pull/1456): Fix a false positive for `Rails/CreateTableWithTimestamps` with numblocks. ([@earlopain][])

lib/rubocop/cop/mixin/active_record_migrations_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ module ActiveRecordMigrationsHelper
2222
].freeze
2323

2424
def_node_matcher :create_table_with_block?, <<~PATTERN
25-
(block
25+
(any_block
2626
(send nil? :create_table ...)
27-
(args (arg _var))
27+
{ _ | (args (arg _var)) }
2828
_)
2929
PATTERN
3030
end

spec/rubocop/cop/rails/create_table_with_timestamps_spec.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
RUBY
3636
end
3737

38-
it 'registers an offense when not including timestampswith `to_proc` syntax' do
38+
it 'registers an offense when not including timestamps with `to_proc` syntax' do
3939
expect_offense <<~RUBY
4040
create_table :users, &:extension_columns
4141
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add timestamps when creating a new table.
@@ -53,13 +53,24 @@
5353
RUBY
5454
end
5555

56-
it 'does not register an offense when including timestampswith `to_proc` syntax' do
56+
it 'does not register an offense when including timestamps in numblock' do
57+
expect_no_offenses <<~RUBY
58+
create_table :users do
59+
_1.string :name
60+
_1.string :email
61+
62+
_1.timestamps
63+
end
64+
RUBY
65+
end
66+
67+
it 'does not register an offense when including timestamps with `to_proc` syntax' do
5768
expect_no_offenses <<~RUBY
5869
create_table :users, &:timestamps
5970
RUBY
6071
end
6172

62-
it 'does not register an offense when including timestampswith options and `to_proc` syntax' do
73+
it 'does not register an offense when including timestamps with options and `to_proc` syntax' do
6374
expect_no_offenses <<~RUBY
6475
create_table :users, id: :string, limit: 42, &:timestamps
6576
RUBY

0 commit comments

Comments
 (0)