This project is archived and is in readonly mode.

#4835 ✓committed
sabat (at area51)

[PATCH] Migrations with Improper Names Generate Invalid Code

Reported by sabat (at area51) | June 11th, 2010 @ 08:49 PM | in 3.0.2

In beta 4, if you generate a migration and use a name for it that does not start with "add" or "remove", the template fails to generate valid code. The template should not create code for adding or removing attributes unless the generator knows for sure that the developer is intending to do an add or remove migration -- he may just want to create a table without generating a model (e.g. "rails g migration CreateArticleTable name:string author:string").

If you attempt that example in beta 4, you end up with bogus template code that looks like:

class CreateArticleTable < ActiveRecord::Migration
  def self.up
    _column :create_article_tables, :name
    _column :create_article_tables, :author
  end

  def self.down
    add_column :create_article_tables, :author
    add_column :create_article_tables, :name
  end
end

This should instead generate empty methods:

class CreateArticleTable < ActiveRecord::Migration
  def self.up

  end

  def self.down

  end
end

I've attached a patch that fixes the template to do this. I don't have any tests for it; it seemed awkward to try to create a test for the presence of method bodies.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages