Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with ReversibleMigrationMethodDefinition with inline ActiveRecord model #680

Closed
javierjulio opened this issue Mar 24, 2022 · 0 comments · Fixed by #682
Closed
Labels
bug Something isn't working

Comments

@javierjulio
Copy link
Contributor

If creating or updating data as part of a migration (e.g. creating a few records for a lookup table), it's considered good practice to inline the model definition to not break the migration if future changes are made, such as removing or renaming the model.

Expected behavior

To not trigger any warning when defining a local ActiveRecord model when needing to create or update data as part of the migration.

Actual behavior

With this example migration:

class CreateNotificationTypes < ActiveRecord::Migration[6.1]
  class NotificationType < ApplicationRecord
  end

  def change
    # ...
  end
end

The Rails/ReversibleMigrationMethodDefinition rule triggered a warning:

C: Rails/ReversibleMigrationMethodDefinition: Migrations must contain either a change method, or both an up and a down method.
  class NotificationType < ApplicationRecord ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

  • Edit any migration file and paste the example from the "Actual behavior" section
  • Run bundle exec rubocop --only Rails/ReversibleMigrationMethodDefinition
  • The warning should be reported on the line defining the inline ActiveRecord model

RuboCop version

> bundle exec rubocop -V
1.26.0 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 2.7.5 x86_64-darwin20)
  - rubocop-rails 2.14.2
@koic koic added the bug Something isn't working label Mar 25, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2022
…MethodDefinition`

Fixes rubocop#680.

This PR fixes a false positive for `Rails/ReversibleMigrationMethodDefinition`
when using an inner class.
@koic koic closed this as completed in #682 Mar 27, 2022
koic added a commit that referenced this issue Mar 27, 2022
…rsible_migration_method_definition

[Fix #680] Fix a false positive for `Rails/ReversibleMigrationMethodDefinition`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants