3
3
require "cases/helper_sqlserver"
4
4
5
5
class ActiveSchemaTestSQLServer < ActiveRecord ::TestCase
6
- before do
7
- connection . create_table :schema_test_table , force : true , id : false do |t |
8
- t . column :foo , :string , limit : 100
9
- t . column :state , :string
6
+ describe "indexes" do
7
+
8
+ before do
9
+ connection . create_table :schema_test_table , force : true , id : false do |t |
10
+ t . column :foo , :string , limit : 100
11
+ t . column :state , :string
12
+ end
10
13
end
11
- end
12
14
13
- after do
14
- connection . drop_table :schema_test_table rescue nil
15
- end
15
+ after do
16
+ connection . drop_table :schema_test_table rescue nil
17
+ end
16
18
17
- it 'default index' do
18
- assert_sql ( 'CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])' ) do
19
- connection . add_index :schema_test_table , "foo"
19
+ it 'default index' do
20
+ assert_sql ( 'CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])' ) do
21
+ connection . add_index :schema_test_table , "foo"
22
+ end
20
23
end
21
- end
22
24
23
- it 'unique index' do
24
- assert_sql ( 'CREATE UNIQUE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])' ) do
25
- connection . add_index :schema_test_table , "foo" , unique : true
25
+ it 'unique index' do
26
+ assert_sql ( 'CREATE UNIQUE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])' ) do
27
+ connection . add_index :schema_test_table , "foo" , unique : true
28
+ end
26
29
end
27
- end
28
30
29
- it 'where condition on index' do
30
- assert_sql ( "CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo]) WHERE state = 'active'" ) do
31
- connection . add_index :schema_test_table , "foo" , where : "state = 'active'"
31
+ it 'where condition on index' do
32
+ assert_sql ( "CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo]) WHERE state = 'active'" ) do
33
+ connection . add_index :schema_test_table , "foo" , where : "state = 'active'"
34
+ end
32
35
end
33
- end
34
36
35
- it 'if index does not exist' do
36
- assert_sql ( "IF NOT EXISTS (SELECT name FROM sysindexes WHERE name = 'index_schema_test_table_on_foo') " \
37
- "CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])" ) do
38
- connection . add_index :schema_test_table , "foo" , if_not_exists : true
37
+ it 'if index does not exist' do
38
+ assert_sql ( "IF NOT EXISTS (SELECT name FROM sysindexes WHERE name = 'index_schema_test_table_on_foo') " \
39
+ "CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])" ) do
40
+ connection . add_index :schema_test_table , "foo" , if_not_exists : true
41
+ end
39
42
end
40
- end
41
43
42
- describe "index types" do
43
44
it 'clustered index' do
44
45
assert_sql ( 'CREATE CLUSTERED INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])' ) do
45
46
connection . add_index :schema_test_table , "foo" , type : :clustered
@@ -52,4 +53,14 @@ class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
52
53
end
53
54
end
54
55
end
56
+
57
+ it "create column with NOT NULL and COLLATE" do
58
+ assert_nothing_raised do
59
+ connection . create_table :not_null_with_collation_table , force : true , id : false do |t |
60
+ t . text :not_null_text_with_collation , null : false , collation : "Latin1_General_CS_AS"
61
+ end
62
+ end
63
+ ensure
64
+ connection . drop_table :not_null_with_collation_table rescue nil
65
+ end
55
66
end
0 commit comments