-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathactive_schema_test_sqlserver.rb
127 lines (109 loc) · 4.35 KB
/
active_schema_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# frozen_string_literal: true
require "cases/helper_sqlserver"
class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
describe "indexes" do
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
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
describe 'collation' do
it "create column with NOT NULL and COLLATE" do
assert_nothing_raised do
connection.create_table :not_null_with_collation_table, force: true, id: false do |t|
t.text :not_null_text_with_collation, null: false, collation: "Latin1_General_CS_AS"
end
end
ensure
connection.drop_table :not_null_with_collation_table rescue nil
end
end
describe 'datetimeoffset precision' do
it 'valid precisions are correct' do
assert_nothing_raised do
connection.create_table :datetimeoffset_precisions do |t|
t.datetimeoffset :precision_default
t.datetimeoffset :precision_5, precision: 5
t.datetimeoffset :precision_7, precision: 7
end
end
columns = connection.columns("datetimeoffset_precisions")
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
ensure
connection.drop_table :datetimeoffset_precisions rescue nil
end
it 'invalid precision raises exception' do
assert_raise(ActiveRecord::ActiveRecordError) do
connection.create_table :datetimeoffset_precisions do |t|
t.datetimeoffset :precision_8, precision: 8
end
end
ensure
connection.drop_table :datetimeoffset_precisions rescue nil
end
end
describe 'time precision' do
it 'valid precisions are correct' do
assert_nothing_raised do
connection.create_table :time_precisions do |t|
t.time :precision_default
t.time :precision_5, precision: 5
t.time :precision_7, precision: 7
end
end
columns = connection.columns("time_precisions")
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
ensure
connection.drop_table :time_precisions rescue nil
end
it 'invalid precision raises exception' do
assert_raise(ActiveRecord::ActiveRecordError) do
connection.create_table :time_precisions do |t|
t.time :precision_8, precision: 8
end
end
ensure
connection.drop_table :time_precisions rescue nil
end
end
end