Skip to content

Commit b0f4bfd

Browse files
authored
Merge pull request #663 from koic/fix_a_false_positive_for_rails_migration_class_name
[Fix #660] Fix a false positive for `Rails/MigrationClassName`
2 parents d2ce35d + 0bb3f22 commit b0f4bfd

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+
* [#660](https://github.com/rubocop/rubocop-rails/issues/660): Fix a false positive for `Rails/MigrationClassName` when defining another class. ([@koic][])

lib/rubocop/cop/rails/migration_class_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MigrationClassName < Base
2525
MSG = 'Replace with `%<corrected_class_name>s` that matches the file name.'
2626

2727
def on_class(node)
28-
return if in_migration?(node)
28+
return unless migration_class?(node)
2929

3030
snake_class_name = to_snakecase(node.identifier.source)
3131

spec/rubocop/cop/rails/migration_class_name_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ class CreateUsers < ActiveRecord::Migration[7.0]
1212
end
1313

1414
context 'when defining another class' do
15+
it 'does not register an offense' do
16+
expect_no_offenses(<<~RUBY, filename)
17+
class Article < ActiveRecord::Base
18+
end
19+
20+
class CreateUsers < ActiveRecord::Migration[7.0]
21+
end
22+
RUBY
23+
end
24+
end
25+
26+
context 'when defining an inner class' do
1527
it 'does not register an offense' do
1628
expect_no_offenses(<<~RUBY, filename)
1729
class CreateUsers < ActiveRecord::Migration[7.0]

0 commit comments

Comments
 (0)