Sha256: ba11c273580c78eaa8d7b45922996ccb3c6cc98280018200190594fdbb41f5d8

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require File.dirname(__FILE__) + '/../test_helper.rb'

class DbTasksTest < Test::Unit::TestCase
  
  $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_tasks.rake")
  
  def test_db_rollback
    test_db_migrate
    si = SchemaInfo.find(:first)
    assert_equal 2, si.version
    assert_equal 1, User.count
    rake_task("db:rollback")
    si = SchemaInfo.find(:first)
    assert_equal 1, si.version
    assert_equal 0, User.count
  end
  
  def test_db_rollback_two_steps
    test_db_migrate
    si = SchemaInfo.find(:first)
    assert_equal 2, si.version
    rake_task("db:rollback", "STEP" => "2")
    si = SchemaInfo.find(:first)
    assert_equal 0, si.version
    assert !User.table_exists?
  end
  
  def test_db_rollback_unrun_migrations
    test_db_migrate
    MigrationGenerator.run("name" => "create_comments")
    si = SchemaInfo.find(:first)
    assert_equal 2, si.version
    assert_raise(Mack::Errors::UnrunMigrations) { rake_task("db:rollback") }
  end

  def test_db_migrate
    assert !SchemaInfo.table_exists?
    rake_task("db:migrate") do
      assert SchemaInfo.table_exists?
      si = SchemaInfo.find(:first)
      assert_equal 0, si.version
    end
    FileUtils.cp(fixture_path("create_users_migration.rb"), File.join(migrations_directory, "001_create_users.rb"))
    assert !User.table_exists?
    rake_task("db:migrate")
    assert User.table_exists?
    si = SchemaInfo.find(:first)
    assert_equal 1, si.version
    FileUtils.cp(fixture_path("add_users_migration.rb"), File.join(migrations_directory, "002_add_users.rb"))
    assert_equal 0, User.count
    rake_task("db:migrate")
    assert_equal 1, User.count
    si = SchemaInfo.find(:first)
    assert_equal 2, si.version
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mack-active_record-0.5.1 test/tasks/db_tasks_test.rb