Skip to content

Commit

Permalink
Merge pull request #657 from sunny/migration-class-name-only-consider…
Browse files Browse the repository at this point in the history
…-migration-classes

Only consider migration classes for `MigrationClassName`
  • Loading branch information
koic committed Mar 15, 2022
2 parents 60f0e8d + ba2d060 commit c39bff3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
@@ -0,0 +1 @@
* [#657](https://github.com/rubocop/rubocop-rails/pull/657): Only consider migration classes for `Rails/MigrationClassName`. ([@sunny][])
3 changes: 3 additions & 0 deletions lib/rubocop/cop/rails/migration_class_name.rb
Expand Up @@ -20,10 +20,13 @@ module Rails
#
class MigrationClassName < Base
extend AutoCorrector
include MigrationsHelper

MSG = 'Replace with `%<corrected_class_name>s` that matches the file name.'

def on_class(node)
return if in_migration?(node)

snake_class_name = to_snakecase(node.identifier.source)

basename = basename_without_timestamp_and_suffix
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/rails/migration_class_name_spec.rb
Expand Up @@ -10,6 +10,17 @@ class CreateUsers < ActiveRecord::Migration[7.0]
end
RUBY
end

context 'when defining another class' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY, filename)
class CreateUsers < ActiveRecord::Migration[7.0]
class Article < ActiveRecord::Base
end
end
RUBY
end
end
end

context 'when the class name does not match its file name' do
Expand Down

0 comments on commit c39bff3

Please sign in to comment.