Sha256: f01e403906f02039c65eb0b07d3dfe44cffabc4670bee78ec30390c56c298cfc

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

require 'assert'
require 'ardb/migration_helpers'

module Ardb::MigrationHelpers

  class UnitTests < Assert::Context
    desc "Ardb migration helpers"
    subject{ Ardb::MigrationHelpers }

    should have_imeths :foreign_key, :drop_foreign_key, :remove_column_with_fk

  end

  class ForeignKeyTests < UnitTests
    desc "ForeignKey handler"
    setup do
      @fk = ForeignKey.new('fromtbl', 'fromcol', 'totbl')
    end
    subject{ @fk }

    should have_readers :from_table, :from_column, :to_table, :to_column
    should have_readers :name, :adapter
    should have_imeths :add_sql, :drop_sql

    should "know its from table/column and to table" do
      assert_equal 'fromtbl', subject.from_table
      assert_equal 'fromcol', subject.from_column
      assert_equal 'totbl',   subject.to_table
    end

    should "default its to column" do
      assert_equal 'id', subject.to_column
    end

    should "default its name" do
      exp_name = "fk_fromtbl_fromcol"
      assert_equal exp_name, subject.name
    end

    should "use Ardb's config db adapter" do
      exp_adapter = Ardb::Adapter.send(Ardb.config.db.adapter)
      assert_equal exp_adapter, subject.adapter
    end

    should "generate appropriate foreign key sql" do
      exp_add_sql = "ALTER TABLE fromtbl"\
                    " ADD CONSTRAINT fk_fromtbl_fromcol"\
                    " FOREIGN KEY (fromcol)"\
                    " REFERENCES totbl (id)"
      assert_equal exp_add_sql, subject.add_sql

      exp_drop_sql = "ALTER TABLE fromtbl"\
                     " DROP CONSTRAINT fk_fromtbl_fromcol"
      assert_equal exp_drop_sql, subject.drop_sql
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ardb-0.27.3 test/unit/migration_helpers_tests.rb
ardb-0.27.2 test/unit/migration_helpers_tests.rb
ardb-0.27.1 test/unit/migration_helpers_tests.rb
ardb-0.27.0 test/unit/migration_helpers_tests.rb
ardb-0.26.0 test/unit/migration_helpers_tests.rb
ardb-0.25.0 test/unit/migration_helpers_tests.rb
ardb-0.24.0 test/unit/migration_helpers_tests.rb
ardb-0.23.0 test/unit/migration_helpers_tests.rb
ardb-0.22.1 test/unit/migration_helpers_tests.rb
ardb-0.22.0 test/unit/migration_helpers_tests.rb
ardb-0.21.0 test/unit/migration_helpers_tests.rb