-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathschema_test_sqlserver.rb
54 lines (40 loc) · 1.92 KB
/
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
require 'cases/helper_sqlserver'
class SchemaTestSQLServer < ActiveRecord::TestCase
describe 'When table is dbo schema' do
it 'find primary key for tables with odd schema' do
connection.primary_key('sst_natural_pk_data').must_equal 'legacy_id'
end
end
describe 'When table is in non-dbo schema' do
it 'work with table exists' do
assert connection.data_source_exists?('test.sst_schema_natural_id')
assert connection.data_source_exists?('[test].[sst_schema_natural_id]')
end
it 'find primary key for tables with odd schema' do
connection.primary_key('test.sst_schema_natural_id').must_equal 'legacy_id'
end
it "have only one identity column" do
columns = connection.columns("test.sst_schema_identity")
assert_equal 2, columns.size
assert_equal 1, columns.select{ |c| c.is_identity? }.size
end
it "read only column properties for table in specific schema" do
test_columns = connection.columns("test.sst_schema_columns")
dbo_columns = connection.columns("dbo.sst_schema_columns")
columns = connection.columns("sst_schema_columns") # This returns table from dbo schema
assert_equal 7, test_columns.size
assert_equal 2, dbo_columns.size
assert_equal 2, columns.size
assert_equal 1, test_columns.select{ |c| c.is_identity? }.size
assert_equal 1, dbo_columns.select{ |c| c.is_identity? }.size
assert_equal 1, columns.select{ |c| c.is_identity? }.size
end
it "return correct varchar and nvarchar column limit length when table is in non dbo schema" do
columns = connection.columns("test.sst_schema_columns")
assert_equal 255, columns.find {|c| c.name == 'name'}.limit
assert_equal 1000, columns.find {|c| c.name == 'description'}.limit
assert_equal 255, columns.find {|c| c.name == 'n_name'}.limit
assert_equal 1000, columns.find {|c| c.name == 'n_description'}.limit
end
end
end