class RuboCop::Cop::Rails::ReversibleMigrationMethodDefinition

This cop checks whether the migration implements either a `change` method or both an `up` and a `down` method.

@example

# bad
class SomeMigration < ActiveRecord::Migration[6.0]
  def up
    # up migration
  end

  # <----- missing down method
end

class SomeMigration < ActiveRecord::Migration[6.0]
  # <----- missing up method

  def down
    # down migration
  end
end

# good
class SomeMigration < ActiveRecord::Migration[6.0]
  def change
    # reversible migration
  end
end

# good
class SomeMigration < ActiveRecord::Migration[6.0]
  def up
    # up migration
  end

  def down
    # down migration
  end
end

Constants

MSG

Public Instance Methods

on_class(node) click to toggle source
# File lib/rubocop/cop/rails/reversible_migration_method_definition.rb, line 67
def on_class(node)
  return if change_method?(node) || up_and_down_methods?(node)

  add_offense(node)
end