Don't make empty 'NEWS' or 'AUTHORS' files

#!/bin/sh

test "$BASH" && set -o pipefail

echo > AUTHORS
echo > NEWS
mkdir m4

echo -n "Creating the build system... "

intltoolize --copy --force --automake || exit
libtoolize --copy --force --quiet || exit
aclocal || exit
autoheader || exit
automake --copy --force-missing --add-missing --gnu 2>&1 | sed "/installing/d" || exit
autoconf -Wno-obsolete || exit

echo "done."

# clean up in order to keep repository small
# (will be needed if 'make dist' is used though)
rm AUTHORS NEWS INSTALL aclocal.m4 intltool-extract.in intltool-merge.in intltool-update.in
rm -f config.h.in~ configure~
rm -r autom4te.cache m4

#!/bin/sh

test "$BASH" && set -o pipefail

mkdir m4

echo -n "Creating the build system... "

intltoolize --copy --force --automake || exit
libtoolize --copy --force --quiet || exit
aclocal || exit
autoheader || exit
automake --copy --force-missing --add-missing --gnu 2>&1 | sed "/installing/d" || exit
autoconf -Wno-obsolete || exit

echo "done."

# clean up in order to keep repository small
# (will be needed if 'make dist' is used though)
rm INSTALL aclocal.m4 intltool-extract.in intltool-merge.in intltool-update.in
rm -f config.h.in~ configure~
rm -r autom4te.cache m4


Rails 3.1 fixes

if RAILS_ENV == 'test'
  require 'migration_test_helper'
  require 'test/unit'
  Test::Unit::TestCase.class_eval do
    include MigrationTestHelper
  end
end

#--
# Copyright (c) 2007 Micah Alles, Patrick Bacon, David Crosby
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++

require 'test/unit/assertions'

module MigrationTestHelper
  def self.migration_dir
    @migration_dir || File.expand_path(RAILS_ROOT + '/db/migrate')
  end

  #
  # sets the directory in which the migrations reside to be run with migrate
  #
  def self.migration_dir=(new_dir)
    @migration_dir = new_dir
  end

  #
  # verifies the schema exactly matches the one specified (schema_info does not have to be specified)
  #
  #   assert_schema do |s|
  #     s.table :dogs do |t|
  #       t.column :id,   :integer, :default => 2
  #       t.column :name, :string
  #     end
  #   end
  #
  def assert_schema
    schema = Schema.new
    yield schema
    schema.verify
  end

  #
  # verifies a single table exactly matches the one specified
  #
  #   assert_table :dogs do |t|
  #     t.column :id,   :integer, :default => 2
  #     t.column :name, :string
  #   end
  #
  def assert_table(name)
    table = Table.new(name)
    yield table
    table.verify
  end

  #
  # drops all tables in the database
  #
  def drop_all_tables
    ActiveRecord::Base.connection.tables.each do |table|
      ActiveRecord::Base.connection.drop_table(table)
    end
  end

  #
  # executes your migrations
  #
  #   migrate                # same as rake db:migrate
  #
  # Options are:
  # * :version - version to migrate to (same as VERSION=.. option to rake db:migrate)
  # * :verbose - print migration status messages to STDOUT, defaults to false
  #
  def migrate(opts={})
    old_verbose = ActiveRecord::Migration.verbose
    ActiveRecord::Migration.verbose = opts[:verbose].nil? ? false : opts[:verbose]
    version = opts[:version] ? opts[:version].to_i : nil
    ActiveRecord::Migrator.migrate(MigrationTestHelper.migration_dir, version)
  ensure
    ActiveRecord::Migration.verbose = old_verbose
  end

  module Connection #:nodoc:
    def conn
      ActiveRecord::Base.connection
    end
  end

  class Schema
    include Connection
    include Test::Unit::Assertions

    def initialize #:nodoc:
      @tables = []
    end

    def table(name)
      table = Table.new(name)
      yield table
      table.verify
      @tables << table
    end

    def verify #:nodoc:
      actual_tables = conn.tables.reject {|t| t == 'schema_info' || t == 'schema_migrations'}
      expected_tables = @tables.map {|t| t.name }
      assert_equal expected_tables.sort, actual_tables.sort, 'wrong tables in schema'
    end
  end

  class Table
    include Connection
    include Test::Unit::Assertions
    attr_reader :name

    def initialize(name) #:nodoc:
      @name = name.to_s
      @columns = []
      @indexes = []
      assert conn.tables.include?(@name), "table <#{@name}> not found in schema"
    end

    def column(colname,type,options={})
      colname = colname.to_s
      @columns << colname
      col = conn.columns(name).find {|c| c.name == colname }
      assert_not_nil col, "column <#{colname}> not found in table <#{self.name}>"
      assert_equal type, col.type, "wrong type for column <#{colname}> in table <#{name}>"
      options.each do |k,v|
        k = k.to_sym; actual = col.send(k); actual = actual.is_a?(String) ? actual.sub(/'$/,'').sub(/^'/,'') : actual
        assert_equal v, actual, "column <#{colname}> in table <#{name}> has wrong :#{k}"
      end
    end

    def index(column_name, options = {})
      @indexes << "name <#{options[:name]}> columns <#{Array(column_name).join(",")}> unique <#{options[:unique] == true}>"
    end

    def verify #:nodoc:
      actual_columns = conn.columns(name).map {|c| c.name }
      assert_equal @columns.sort, actual_columns.sort, "wrong columns for table: <#{name}>"

      actual_indexes = conn.indexes(@name).collect { |i| "name <#{i.name}> columns <#{i.columns.join(",")}> unique <#{i.unique}>" }
      assert_equal @indexes.sort, actual_indexes.sort, "wrong indexes for table: <#{name}>"
    end

    def method_missing(type, *columns)
      options = columns.extract_options!
      columns.each do |colname|
        column colname, type, options
      end
    end
  end
end

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
require 'logger'
require 'fileutils'
require 'test_help'

plugin_path = RAILS_ROOT + "/vendor/plugins/migration_test_helper"

config_location = File.expand_path(plugin_path + "/test/config/database.yml")

config = YAML::load(ERB.new(IO.read(config_location)).result)
ActiveRecord::Base.logger = Logger.new(plugin_path + "/test/log/test.log")
ActiveRecord::Base.establish_connection(config['test'])

Test::Unit::TestCase.fixture_path = plugin_path + "/test/fixtures/"

$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)

class Test::Unit::TestCase
  include FileUtils
  def plugin_path(path)
    File.expand_path(File.dirname(__FILE__) + '/../' + path)
  end

  def load_default_schema
    ActiveRecord::Migration.suppress_messages do
      schema_file = plugin_path("/test/db/schema.rb")
      load(schema_file) if File.exist?(schema_file)
    end
  end

  def migration_test_path
    File.expand_path(RAILS_ROOT + "/test/migration")
  end

  def run_in_rails_root(command)
    cd RAILS_ROOT do
      @output = `#{command}`
    end
  end

  def check_output(string_or_regexp)
    assert_not_nil @output, "No output collected"
    case string_or_regexp
    when String
      assert_match(/#{Regexp.escape(string_or_regexp)}/, @output)
    when Regexp
      assert_match(string_or_regexp, @output)
    else
      raise "Can't check output using oddball object #{string_or_regexp.inspect}"
    end
  end

  def rm_migration_test_path
    rm_rf migration_test_path
  end

  def self.should(behave,&block)
    return unless running_in_foundry
    @context ||= nil
    @context_setup ||= nil
    context_string = @context.nil? ? '' : @context + ' '
    mname = "test #{context_string}should #{behave}"
    context_setup = @context_setup
    if block_given?
      define_method(mname) do
        instance_eval(&context_setup) unless context_setup.nil?
        instance_eval(&block)
      end
    else
      puts ">>> UNIMPLEMENTED CASE: #{name.sub(/Test$/,'')} should #{behave}"
    end
  end

end

require File.expand_path(File.dirname(__FILE__) + '/helper')

class MigrationTestHelperTest < Test::Unit::TestCase

  def setup
    load_default_schema
    MigrationTestHelper.migration_dir = plugin_path('test/db/migrate_good')
  end

  #
  # HELPERS
  #
  def see_failure(pattern='')
    err = assert_raise(Test::Unit::AssertionFailedError) do
      yield
    end
    assert_match(/#{pattern}/mi, err.message)
  end

  def see_no_failure
    assert_nothing_raised do
      yield
    end
  end

  def declare_columns_on_table(t)
    t.column :id,   :integer
    t.column :tail, :string, :default => 'top dog', :limit => 187
  end

  #
  # TESTS
  #
  def test_assert_schema_should_not_fail_if_schema_is_matched
    see_no_failure do
      assert_schema do |s|
        s.table :dogs do |t|
	  declare_columns_on_table(t)
	  t.index :tail, :name => 'index_tail_on_dogs'
        end

      end
    end
  end

  def test_assert_schema_should_fail_if_a_table_is_not_specified
    see_failure 'wrong tables in schema.*dogs' do
      assert_schema do |s|
      end
    end
  end

  def test_assert_schema_should_fail_if_a_table_is_not_found
    see_failure 'table <things> not found in schema' do
      assert_schema do |s|
        s.table :things do |t|
          t.column :id, :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_is_not_specified
    see_failure 'wrong columns for table.*dogs.*tail' do
      assert_schema do |s|
        s.table :dogs do |t|
          t.column :id,   :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_is_not_found
    see_failure 'column <legs> not found in table <dogs>' do
      assert_schema do |s|
        s.table :dogs do |t|
          t.column :id,   :integer
          t.column :tail, :string
          t.column :legs, :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_wrong_options_not_specified
    see_failure 'column <tail> in table <dogs> has wrong :default' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string, :default => "blah"
      end
    end
  end

  def test_assert_table_should_not_fail_if_table_is_matched
    see_no_failure do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :tail, :name => 'index_tail_on_dogs'
      end
    end
  end

  def test_assert_table_should_fail_if_a_table_is_not_found
    see_failure 'table <things> not found in schema' do
      assert_table :things do |t|
        t.column :id, :integer
      end
    end
  end

  def test_assert_table_should_fail_if_a_column_is_not_specified
    see_failure 'wrong columns for table.*dogs.*tail' do
      assert_table :dogs do |t|
        t.column :id,   :integer
      end
    end
  end

  def test_assert_table_should_fail_if_a_column_is_not_found
    see_failure 'column <legs> not found in table <dogs>' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string
        t.column :legs, :integer
      end
    end
  end

  def test_assert_table_should_fail_if_wrong_options_not_specified
    see_failure 'column <tail> in table <dogs> has wrong :default' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string, :default => "blah"
      end
    end
  end

  def test_assert_table_should_fail_if_an_index_is_not_specified
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_in_an_index_is_not_found
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :legs, :name => 'index_legs_on_dogs'
      end
    end
  end

  def test_assert_schema_should_fail_if_wrong_options_on_an_index
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :tail, :name => 'index_tail_on_dogs', :unique => true
      end
    end
  end

  def test_should_drop_all_tables
    assert_equal ['dogs','schema_info'].sort, ActiveRecord::Base.connection.tables.sort
    drop_all_tables
    assert_equal [], ActiveRecord::Base.connection.tables
    drop_all_tables
    assert_equal [], ActiveRecord::Base.connection.tables
  end

  def test_should_migrate_to_highest_version
    drop_all_tables
    assert_schema do |s|
    end

    migrate :version => 1

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
    end

    migrate :version => 2

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
    end

    migrate :version => 3

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
      s.table :cats do |t|
        t.column :id,      :integer
        t.column :lives,   :integer
      end
    end

    migrate :version => 0

    assert_schema do |s|
    end

    migrate

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
      s.table :cats do |t|
        t.column :id,      :integer
        t.column :lives,   :integer
      end
    end
  end

  def test_should_have_default_migration_dir_set
    MigrationTestHelper.migration_dir = nil
    assert_equal File.expand_path(RAILS_ROOT + '/db/migrate'), MigrationTestHelper.migration_dir,
      "wrong default migration dir"

  end

  def test_should_raise_error_if_migration_fails
    MigrationTestHelper.migration_dir = plugin_path('test/db/migrate_bad')
    drop_all_tables
    err = assert_raise RuntimeError do
      migrate
    end
    assert_match(//i, err.message)
  end
end

if Rails.env.test?
  require 'migration_test_helper'
  require 'test/unit'
  Test::Unit::TestCase.class_eval do
    include MigrationTestHelper
  end
end

#--
# Copyright (c) 2007 Micah Alles, Patrick Bacon, David Crosby
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++

require 'test/unit/assertions'

module MigrationTestHelper
  def self.migration_dir
    @migration_dir || File.expand_path(Rails.root.to_s + '/db/migrate')
  end

  #
  # sets the directory in which the migrations reside to be run with migrate
  #
  def self.migration_dir=(new_dir)
    @migration_dir = new_dir
  end

  #
  # verifies the schema exactly matches the one specified (schema_info does not have to be specified)
  #
  #   assert_schema do |s|
  #     s.table :dogs do |t|
  #       t.column :id,   :integer, :default => 2
  #       t.column :name, :string
  #     end
  #   end
  #
  def assert_schema
    schema = Schema.new
    yield schema
    schema.verify
  end

  #
  # verifies a single table exactly matches the one specified
  #
  #   assert_table :dogs do |t|
  #     t.column :id,   :integer, :default => 2
  #     t.column :name, :string
  #   end
  #
  def assert_table(name)
    table = Table.new(name)
    yield table
    table.verify
  end

  #
  # drops all tables in the database
  #
  def drop_all_tables
    ActiveRecord::Base.connection.tables.each do |table|
      ActiveRecord::Base.connection.drop_table(table)
    end
  end

  #
  # executes your migrations
  #
  #   migrate                # same as rake db:migrate
  #
  # Options are:
  # * :version - version to migrate to (same as VERSION=.. option to rake db:migrate)
  # * :verbose - print migration status messages to STDOUT, defaults to false
  #
  def migrate(opts={})
    old_verbose = ActiveRecord::Migration.verbose
    ActiveRecord::Migration.verbose = opts[:verbose].nil? ? false : opts[:verbose]
    version = opts[:version] ? opts[:version].to_i : nil
    ActiveRecord::Migrator.migrate(MigrationTestHelper.migration_dir, version)
  ensure
    ActiveRecord::Migration.verbose = old_verbose
  end

  module Connection #:nodoc:
    def conn
      ActiveRecord::Base.connection
    end
  end

  class Schema
    include Connection
    include Test::Unit::Assertions

    def initialize #:nodoc:
      @tables = []
    end

    def table(name)
      table = Table.new(name)
      yield table
      table.verify
      @tables << table
    end

    def verify #:nodoc:
      actual_tables = conn.tables.reject {|t| t == 'schema_info' || t == 'schema_migrations'}
      expected_tables = @tables.map {|t| t.name }
      assert_equal expected_tables.sort, actual_tables.sort, 'wrong tables in schema'
    end
  end

  class Table
    include Connection
    include Test::Unit::Assertions
    attr_reader :name

    def initialize(name) #:nodoc:
      @name = name.to_s
      @columns = []
      @indexes = []
      assert conn.tables.include?(@name), "table <#{@name}> not found in schema"
    end

    def column(colname,type,options={})
      colname = colname.to_s
      @columns << colname
      col = conn.columns(name).find {|c| c.name == colname }
      assert_not_nil col, "column <#{colname}> not found in table <#{self.name}>"
      assert_equal type, col.type, "wrong type for column <#{colname}> in table <#{name}>"
      options.each do |k,v|
        k = k.to_sym; actual = col.send(k); actual = actual.is_a?(String) ? actual.sub(/'$/,'').sub(/^'/,'') : actual
        assert_equal v, actual, "column <#{colname}> in table <#{name}> has wrong :#{k}"
      end
    end

    def index(column_name, options = {})
      @indexes << "name <#{options[:name]}> columns <#{Array(column_name).join(",")}> unique <#{options[:unique] == true}>"
    end

    def verify #:nodoc:
      actual_columns = conn.columns(name).map {|c| c.name }
      assert_equal @columns.sort, actual_columns.sort, "wrong columns for table: <#{name}>"

      actual_indexes = conn.indexes(@name).collect { |i| "name <#{i.name}> columns <#{i.columns.join(",")}> unique <#{i.unique}>" }
      assert_equal @indexes.sort, actual_indexes.sort, "wrong indexes for table: <#{name}>"
    end

    def method_missing(type, *columns)
      options = columns.extract_options!
      columns.each do |colname|
        column colname, type, options
      end
    end
  end
end

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
require 'logger'
require 'fileutils'
require 'rails/test_help'

plugin_path = Rails.root.to_s + "/vendor/plugins/migration_test_helper"

config_location = File.expand_path(plugin_path + "/test/config/database.yml")

config = YAML::load(ERB.new(IO.read(config_location)).result)
ActiveRecord::Base.logger = Logger.new(plugin_path + "/test/log/test.log")
ActiveRecord::Base.establish_connection(config['test'])

ActiveSupport::TestCase.fixture_path = plugin_path + "/test/fixtures/"

$LOAD_PATH.unshift(ActiveSupport::TestCase.fixture_path)

class Test::Unit::TestCase
  include FileUtils
  def plugin_path(path)
    File.expand_path(File.dirname(__FILE__) + '/../' + path)
  end

  def load_default_schema
    ActiveRecord::Migration.suppress_messages do
      schema_file = plugin_path("/test/db/schema.rb")
      load(schema_file) if File.exist?(schema_file)
    end
  end

  def migration_test_path
    File.expand_path(RAILS_ROOT + "/test/migration")
  end

  def run_in_rails_root(command)
    cd RAILS_ROOT do
      @output = `#{command}`
    end
  end

  def check_output(string_or_regexp)
    assert_not_nil @output, "No output collected"
    case string_or_regexp
    when String
      assert_match(/#{Regexp.escape(string_or_regexp)}/, @output)
    when Regexp
      assert_match(string_or_regexp, @output)
    else
      raise "Can't check output using oddball object #{string_or_regexp.inspect}"
    end
  end

  def rm_migration_test_path
    rm_rf migration_test_path
  end

  def self.should(behave,&block)
    return unless running_in_foundry
    @context ||= nil
    @context_setup ||= nil
    context_string = @context.nil? ? '' : @context + ' '
    mname = "test #{context_string}should #{behave}"
    context_setup = @context_setup
    if block_given?
      define_method(mname) do
        instance_eval(&context_setup) unless context_setup.nil?
        instance_eval(&block)
      end
    else
      puts ">>> UNIMPLEMENTED CASE: #{name.sub(/Test$/,'')} should #{behave}"
    end
  end

end

require File.expand_path(File.dirname(__FILE__) + '/helper')

class MigrationTestHelperTest < Test::Unit::TestCase

  def setup
    load_default_schema
    MigrationTestHelper.migration_dir = plugin_path('test/db/migrate_good')
  end

  #
  # HELPERS
  #
  def see_failure(pattern='')
    err = assert_raise(Test::Unit::AssertionFailedError) do
      yield
    end
    assert_match(/#{pattern}/mi, err.message)
  end

  def see_no_failure
    assert_nothing_raised do
      yield
    end
  end

  def declare_columns_on_table(t)
    t.column :id,   :integer
    t.column :tail, :string, :default => 'top dog', :limit => 187
  end

  #
  # TESTS
  #
  def test_assert_schema_should_not_fail_if_schema_is_matched
    see_no_failure do
      assert_schema do |s|
        s.table :dogs do |t|
	  declare_columns_on_table(t)
	  t.index :tail, :name => 'index_tail_on_dogs'
        end

      end
    end
  end

  def test_assert_schema_should_fail_if_a_table_is_not_specified
    see_failure 'wrong tables in schema.*dogs' do
      assert_schema do |s|
      end
    end
  end

  def test_assert_schema_should_fail_if_a_table_is_not_found
    see_failure 'table <things> not found in schema' do
      assert_schema do |s|
        s.table :things do |t|
          t.column :id, :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_is_not_specified
    see_failure 'wrong columns for table.*dogs.*tail' do
      assert_schema do |s|
        s.table :dogs do |t|
          t.column :id,   :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_is_not_found
    see_failure 'column <legs> not found in table <dogs>' do
      assert_schema do |s|
        s.table :dogs do |t|
          t.column :id,   :integer
          t.column :tail, :string
          t.column :legs, :integer
        end
      end
    end
  end

  def test_assert_schema_should_fail_if_wrong_options_not_specified
    see_failure 'column <tail> in table <dogs> has wrong :default' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string, :default => "blah"
      end
    end
  end

  def test_assert_table_should_not_fail_if_table_is_matched
    see_no_failure do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :tail, :name => 'index_tail_on_dogs'
      end
    end
  end

  def test_assert_table_should_fail_if_a_table_is_not_found
    see_failure 'table <things> not found in schema' do
      assert_table :things do |t|
        t.column :id, :integer
      end
    end
  end

  def test_assert_table_should_fail_if_a_column_is_not_specified
    see_failure 'wrong columns for table.*dogs.*tail' do
      assert_table :dogs do |t|
        t.column :id,   :integer
      end
    end
  end

  def test_assert_table_should_fail_if_a_column_is_not_found
    see_failure 'column <legs> not found in table <dogs>' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string
        t.column :legs, :integer
      end
    end
  end

  def test_assert_table_should_fail_if_wrong_options_not_specified
    see_failure 'column <tail> in table <dogs> has wrong :default' do
      assert_table :dogs do |t|
        t.column :id,   :integer
        t.column :tail, :string, :default => "blah"
      end
    end
  end

  def test_assert_table_should_fail_if_an_index_is_not_specified
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
      end
    end
  end

  def test_assert_schema_should_fail_if_a_column_in_an_index_is_not_found
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :legs, :name => 'index_legs_on_dogs'
      end
    end
  end

  def test_assert_schema_should_fail_if_wrong_options_on_an_index
    see_failure 'wrong indexes for table: <dogs>' do
      assert_table :dogs do |t|
        declare_columns_on_table(t)
	t.index :tail, :name => 'index_tail_on_dogs', :unique => true
      end
    end
  end

  def test_should_drop_all_tables
    assert_equal ['dogs','schema_migrations'].sort, ActiveRecord::Base.connection.tables.sort
    drop_all_tables
    assert_equal [], ActiveRecord::Base.connection.tables
    drop_all_tables
    assert_equal [], ActiveRecord::Base.connection.tables
  end

  def test_should_migrate_to_highest_version
    drop_all_tables
    assert_schema do |s|
    end

    migrate :version => 1

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
    end

    migrate :version => 2

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
    end

    migrate :version => 3

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
      s.table :cats do |t|
        t.column :id,      :integer
        t.column :lives,   :integer
      end
    end

    migrate :version => 0

    assert_schema do |s|
    end

    migrate

    assert_schema do |s|
      s.table :top_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
      end
      s.table :bottom_dogs do |t|
        t.column :id,      :integer
        t.column :name,    :string
        t.column :sick,    :boolean
      end
      s.table :cats do |t|
        t.column :id,      :integer
        t.column :lives,   :integer
      end
    end
  end

  def test_should_have_default_migration_dir_set
    MigrationTestHelper.migration_dir = nil
    assert_equal File.expand_path(Rails.root.to_s + '/db/migrate'), MigrationTestHelper.migration_dir,
      "wrong default migration dir"

  end

  def test_should_raise_error_if_migration_fails
    MigrationTestHelper.migration_dir = plugin_path('test/db/migrate_bad')
    drop_all_tables
    err = assert_raise StandardError do
      migrate
    end
    assert_match(//i, err.message)
  end
end