Sha256: 58bb250c4767c667eabefb33d78127da3146ad6d75a0504e68f29c5283fcd1a7

Contents?: true

Size: 1.65 KB

Versions: 18

Compression:

Stored size: 1.65 KB

Contents

require 'cases/helper_sqlserver'

class IndexTestSQLServer < ActiveRecord::TestCase

  before do
    connection.create_table(:testings) do |t|
      t.column :foo, :string, limit: 100
      t.column :bar, :string, limit: 100
      t.string :first_name
      t.string :last_name,    limit: 100
      t.string :key,          limit: 100
      t.boolean :administrator
    end
  end

  after do
    connection.drop_table :testings rescue nil
  end

  it 'add index with order' do
    assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC\)/i) do
      connection.add_index 'testings', ['last_name'], order: { last_name: :desc }
      connection.remove_index 'testings', ['last_name']
    end
    assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\]\)/i) do
      connection.add_index 'testings', ['last_name', 'first_name'], order: { last_name: :desc }
      connection.remove_index 'testings', ['last_name', 'first_name']
    end
    assert_sql(/CREATE.*INDEX.*\(\[last_name\] DESC, \[first_name\] ASC\)/i) do
      connection.add_index 'testings', ['last_name', 'first_name'], order: { last_name: :desc, first_name: :asc }
      connection.remove_index 'testings', ['last_name', 'first_name']
    end
  end

  it 'add index with where' do
    assert_sql(/CREATE.*INDEX.*\(\[last_name\]\) WHERE \[first_name\] = N'john doe'/i) do
      connection.add_index 'testings', 'last_name', where: "[first_name] = N'john doe'"
      connection.remove_index 'testings', 'last_name'
    end
  end

  it 'add index with expression' do
    connection.execute "ALTER TABLE [testings] ADD [first_name_upper] AS UPPER([first_name])"
    connection.add_index 'testings', 'first_name_upper'
  end

end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
activerecord-jdbcsqlserver-adapter-52.0.0 test/cases/index_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.1.0 test/cases/index_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.1.0 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.2.1 test/cases/index_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.1 test/cases/index_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.0 test/cases/index_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.0.0 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.2.0 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.2.0.rc2 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.2.0.rc1 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.6 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.8 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.5 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.2 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.1 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.1.0 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.7 test/cases/index_test_sqlserver.rb
activerecord-sqlserver-adapter-5.0.6 test/cases/index_test_sqlserver.rb