Sha256: 1e3664881a7151cd812ec25f627a6a12b7b2ea798121a6bfe804aedc7dc80ec9

Contents?: true

Size: 1.82 KB

Versions: 14

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require "cases/helper_sqlserver"

class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
  before do
    connection.create_table :schema_test_table, force: true, id: false do |t|
      t.column :foo, :string, limit: 100
      t.column :state, :string
    end
  end

  after do
    connection.drop_table :schema_test_table rescue nil
  end

  it 'default index' do
    assert_sql('CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
      connection.add_index :schema_test_table, "foo"
    end
  end

  it 'unique index' do
    assert_sql('CREATE UNIQUE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
      connection.add_index :schema_test_table, "foo", unique: true
    end
  end

  it 'where condition on index' do
    assert_sql("CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo]) WHERE state = 'active'") do
      connection.add_index :schema_test_table, "foo", where: "state = 'active'"
    end
  end

  it 'if index does not exist' do
    assert_sql("IF NOT EXISTS (SELECT name FROM sysindexes WHERE name = 'index_schema_test_table_on_foo') " \
               "CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])") do
      connection.add_index :schema_test_table, "foo", if_not_exists: true
    end
  end

  describe "index types" do
    it 'clustered index' do
      assert_sql('CREATE CLUSTERED INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
        connection.add_index :schema_test_table, "foo", type: :clustered
      end
    end

    it 'nonclustered index' do
      assert_sql('CREATE NONCLUSTERED INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
        connection.add_index :schema_test_table, "foo", type: :nonclustered
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.0.7 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.1.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.6 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.1.0.rc2 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.1.0.rc1 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.5.1 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.1.0.beta1 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.5.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.4.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.3.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.2.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-6.1.3.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.1.0 test/cases/active_schema_test_sqlserver.rb
activerecord-sqlserver-adapter-7.0.0.0 test/cases/active_schema_test_sqlserver.rb