-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathindex_test_sqlserver.rb
47 lines (40 loc) · 1.65 KB
/
index_test_sqlserver.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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