Sha256: 84bfda67543776b52c1e4bdbf2690fcafdd9c32a613e8d327f7c1086a46a5588

Contents?: true

Size: 1.71 KB

Versions: 13

Compression:

Stored size: 1.71 KB

Contents

require 'spec'

require File.dirname(__FILE__) + '/../matchers/migration_matchers'

module Spec
  module Example
    class MigrationExampleGroup < Spec::Example::ExampleGroup
      include Spec::Matchers::Migration

      before(:all) do
        if this_migration.adapter.supports_schema_transactions?
          run_prereq_migrations
        end
      end

      before(:each) do
        if ! this_migration.adapter.supports_schema_transactions?
          run_prereq_migrations
        else
          this_migration.adapter.begin_transaction
        end
      end

      after(:each) do
        if this_migration.adapter.supports_schema_transactions?
          this_migration.adapter.rollback_transaction
        end
      end

      after(:all) do
        this_migration.adapter.recreate_database
      end

      def run_prereq_migrations
        "running n-1 migrations"
        all_databases.each do |db|
          db.adapter.recreate_database
        end
        @@migrations.sort.each do |migration|
          break if migration.name.to_s == migration_name.to_s
          migration.perform_up
        end
      end

      def run_migration
        this_migration.perform_up
      end

      def migration_name
        @migration_name ||= self.class.instance_variable_get("@description_text").to_s
      end

      def all_databases
        @@migrations.map { |m| m.database }.uniq
      end

      def this_migration
        @@migrations.select { |m| m.name.to_s == migration_name }.first
      end

      def query(sql)
        this_migration.adapter.query(sql)
      end

      def table(table_name)
        this_migration.adapter.table(table_name)
      end

      Spec::Example::ExampleGroupFactory.register(:migration, self)

    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dm-migrations-0.9.10 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.11 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.2 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.5 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.3 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.4 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.6 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.7 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.8 lib/spec/example/migration_example_group.rb
dm-migrations-0.9.9 lib/spec/example/migration_example_group.rb
mack-data_mapper-0.8.2 lib/gems/dm-migrations-0.9.7/lib/spec/example/migration_example_group.rb
mack-data_mapper-0.8.3.1 lib/gems/dm-migrations-0.9.9/lib/spec/example/migration_example_group.rb
mack-data_mapper-0.8.3 lib/gems/dm-migrations-0.9.9/lib/spec/example/migration_example_group.rb