views:

34

answers:

1

I'm creating a user authentication system for my site. I want to add a default user, so that if I create a new site, or reset the database I will still be able to log in (and change the default user details).

I have the code below in the migration. All seems to be working fine for the development database, but when it come to testing the default user I'm adding is removed and the data from the fixture is loaded instead. Is there any way to add unit testing for this?

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :name
      t.string :hashed_password
      t.string :salt

      t.timestamps
    end

    User.add_user("mike", "password")
  end

  def self.down
    drop_table :users
  end
end
+2  A: 

I highly recommend doing this sort of "seed data" inside a custom rake task, and have different data inside normal unit test fixtures.

Matt Briggs
Agreed, especially if "different data" is coming from a factory for the unit tests.
jdl