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

Rails/ReversibleMigrationMethodDefinition false positive when up and down defined as class methods #1232

Open
marcoroth opened this issue Jan 24, 2024 · 1 comment

Comments

@marcoroth
Copy link

Expected behavior

A migration like this shouldn't add a Rails/ReversibleMigrationMethodDefinition offense:

class SomeMigration < ActiveRecord::Migration[7.1]
  def self.up
    # ...
  end

  def self.down
    # ...
  end
end

Actual behavior

It's adding the following offense:

# db/migrate/some_migration.rb:1:1: C: Rails/ReversibleMigrationMethodDefinition: Migrations must contain either a change method, or both an up and a down method.

# class SomeMigration < ActiveRecord::Migration[7.1] ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

  1. Create file db/migrate/some_migration.rb
  2. Copy the file content from above
  3. Run RuboCop with rubocop-rails required and the Rails/ReversibleMigrationMethodDefinition cop enabled
Rails/ReversibleMigrationMethodDefinition:
  Enabled: true

RuboCop version

❯ bundle exec rubocop -V
1.60.1 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.3.0) [x86_64-darwin23]
  - rubocop-rails 2.23.1
@marcoroth marcoroth changed the title Rails/ReversibleMigrationMethodDefinition false positive for up and down when defined as class methods Rails/ReversibleMigrationMethodDefinition false positive when up and down defined as class methods Jan 24, 2024
@Earlopain
Copy link
Contributor

This working seems like an implementation detail, I don't find any documentation on this.

Trying to do the same with change doesn't work at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants