Sha256: 80ff0e590b65390c4576d33f5a5383ff67de28cfb8382f9dec21f9b6138439bb

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

require File.dirname(__FILE__) + "/../helpers"

class MigrationsTest < Test::Unit::TestCase
  def database_adapter
    DataMapper.repository(:default).adapter
  end

  def table_exists?(table_name)
    database_adapter.storage_exists?(table_name)
  end

  def current_migrations
    database_adapter.query("SELECT * from migration_info")
  end

  def load_initial_migration_fixture
    database_adapter.execute(File.read(File.dirname(__FILE__) +
      "/../helpers/initial_migration_fixture.sql"))
  end

  before(:all) do
    require "integrity/migrations"
  end

  before(:each) do
    [Project, Build, Commit, Notifier].each(&:auto_migrate_down!)
    assert !table_exists?("migration_info") # just to be sure
  end

  test "upgrading a pre migration database" do
    util_capture { Integrity.migrate_db }

    current_migrations.should == ["initial", "add_commits"]
    assert table_exists?("integrity_projects")
    assert table_exists?("integrity_builds")
    assert table_exists?("integrity_notifiers")
    assert table_exists?("integrity_commits")
  end

  test "migrating data from initial to add_commits migration" do
    load_initial_migration_fixture

    util_capture { Integrity.migrate_db }
    current_migrations.should == ["initial", "add_commits"]

    sinatra = Project.first(:name => "Sinatra")
    sinatra.should have(1).commits
    sinatra.commits.first.should be_successful
    sinatra.commits.first.output.should =~ /sinatra/

    shout_bot = Project.first(:name => "Shout Bot")
    shout_bot.should have(1).commits
    shout_bot.commits.first.should be_failed
    shout_bot.commits.first.output.should =~ /shout-bot/
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
foca-integrity-0.1.9.0 test/unit/migrations_test.rb
foca-integrity-0.1.9.1 test/unit/migrations_test.rb
oliyoung-integrity-0.1.9.0 test/unit/migrations_test.rb
integrity-0.1.9.1 test/unit/migrations_test.rb
integrity-0.1.9.0 test/unit/migrations_test.rb
integrity-0.1.9.2 test/unit/migrations_test.rb
integrity-0.1.9 test/unit/migrations_test.rb