Skip to content

Commit 4e5dbff

Browse files
committed
Schema specific test done.
1 parent 04f22a1 commit 4e5dbff

File tree

3 files changed

+28
-55
lines changed

3 files changed

+28
-55
lines changed

test/cases/schema_test_sqlserver.rb

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
require 'cases/helper_sqlserver'
2-
require 'models/sqlserver/sql_server_natural_pk_data'
3-
require 'models/sqlserver/sql_server_natural_pk_data_schema'
42

53
class SchemaTestSQLServer < ActiveRecord::TestCase
64

7-
setup do
8-
@connection = ActiveRecord::Base.connection
9-
end
10-
11-
context 'When table is dbo schema' do
5+
describe 'When table is dbo schema' do
126

13-
should 'find primary key for tables with odd schema' do
14-
assert_equal 'legacy_id', @connection.primary_key('natural_pk_data')
15-
assert SSTestNaturalPkData.columns_hash['legacy_id'].primary
7+
it 'find primary key for tables with odd schema' do
8+
connection.primary_key('natural_pk_data').must_equal 'legacy_id'
169
end
1710

1811
end
1912

20-
context 'When table is in non-dbo schema' do
13+
describe 'When table is in non-dbo schema' do
2114

22-
should 'work with #table_exists?' do
23-
assert @connection.table_exists?('test.sql_server_schema_natural_id')
15+
it 'work with table exists' do
16+
assert connection.table_exists?('test.sst_schema_natural_id')
17+
assert connection.table_exists?('[test].[sst_schema_natural_id]')
2418
end
2519

26-
should 'find primary key for tables with odd schema' do
27-
assert_equal 'legacy_id', @connection.primary_key('test.sql_server_schema_natural_id')
28-
assert SqlServerNaturalPkDataSchema.columns_hash['legacy_id'].primary
20+
it 'find primary key for tables with odd schema' do
21+
connection.primary_key('test.sst_schema_natural_id').must_equal 'legacy_id'
2922
end
3023

31-
should "have only one identity column" do
32-
columns = @connection.columns("test.sql_server_schema_identity")
24+
it "have only one identity column" do
25+
columns = connection.columns("test.sst_schema_identity")
3326
assert_equal 2, columns.size
34-
assert_equal 1, columns.select{ |c| c.primary }.size
27+
assert_equal 1, columns.select{ |c| c.is_identity? }.size
3528
end
3629

37-
should "read only column properties for table in specific schema" do
38-
test_columns = @connection.columns("test.sql_server_schema_columns")
39-
dbo_columns = @connection.columns("dbo.sql_server_schema_columns")
40-
columns = @connection.columns("sql_server_schema_columns") # This returns table from dbo schema
30+
it "read only column properties for table in specific schema" do
31+
test_columns = connection.columns("test.sst_schema_columns")
32+
dbo_columns = connection.columns("dbo.sst_schema_columns")
33+
columns = connection.columns("sst_schema_columns") # This returns table from dbo schema
4134
assert_equal 7, test_columns.size
4235
assert_equal 2, dbo_columns.size
4336
assert_equal 2, columns.size
44-
assert_equal 1, test_columns.select{ |c| c.primary }.size
45-
assert_equal 1, dbo_columns.select{ |c| c.primary }.size
46-
assert_equal 1, columns.select{ |c| c.primary }.size
37+
assert_equal 1, test_columns.select{ |c| c.is_identity? }.size
38+
assert_equal 1, dbo_columns.select{ |c| c.is_identity? }.size
39+
assert_equal 1, columns.select{ |c| c.is_identity? }.size
4740
end
4841

49-
should "return correct varchar and nvarchar column limit (length) when table is in non dbo schema" do
50-
columns = @connection.columns("test.sql_server_schema_columns")
42+
it "return correct varchar and nvarchar column limit length when table is in non dbo schema" do
43+
columns = connection.columns("test.sst_schema_columns")
5144
assert_equal 255, columns.find {|c| c.name == 'name'}.limit
5245
assert_equal 1000, columns.find {|c| c.name == 'description'}.limit
5346
assert_equal 255, columns.find {|c| c.name == 'n_name'}.limit

test/models/sql_server_natural_pk_data_schema.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/schema/sqlserver_specific_schema.rb

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,33 +139,16 @@
139139
FROM sst_string_defaults
140140
STRINGDEFAULTSBIGVIEW
141141

142-
143-
144-
145-
146-
147-
148-
149-
150-
151-
152-
153-
154-
155-
156-
157-
158-
159142
# Another schema.
160143

161-
create_table :sql_server_schema_columns, force: true do |t|
144+
create_table :sst_schema_columns, force: true do |t|
162145
t.column :field1 , :integer
163146
end
164147

165148
execute "IF NOT EXISTS(SELECT * FROM sys.schemas WHERE name = 'test') EXEC sp_executesql N'CREATE SCHEMA test'"
166-
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sql_server_schema_columns' and TABLE_SCHEMA = 'test') DROP TABLE test.sql_server_schema_columns"
149+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sst_schema_columns' and TABLE_SCHEMA = 'test') DROP TABLE test.sst_schema_columns"
167150
execute <<-SIMILIARTABLEINOTHERSCHEMA
168-
CREATE TABLE test.sql_server_schema_columns(
151+
CREATE TABLE test.sst_schema_columns(
169152
id int IDENTITY NOT NULL primary key,
170153
filed_1 int,
171154
field_2 int,
@@ -176,17 +159,17 @@
176159
)
177160
SIMILIARTABLEINOTHERSCHEMA
178161

179-
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sql_server_schema_identity' and TABLE_SCHEMA = 'test') DROP TABLE test.sql_server_schema_identity"
162+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sst_schema_identity' and TABLE_SCHEMA = 'test') DROP TABLE test.sst_schema_identity"
180163
execute <<-SIMILIARTABLEINOTHERSCHEMA
181-
CREATE TABLE test.sql_server_schema_identity(
164+
CREATE TABLE test.sst_schema_identity(
182165
id int IDENTITY NOT NULL primary key,
183166
filed_1 int
184167
)
185168
SIMILIARTABLEINOTHERSCHEMA
186169

187-
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sql_server_schema_natural_id' and TABLE_SCHEMA = 'test') DROP TABLE test.sql_server_schema_natural_id"
170+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sst_schema_natural_id' and TABLE_SCHEMA = 'test') DROP TABLE test.sst_schema_natural_id"
188171
execute <<-NATURALPKTABLESQLINOTHERSCHEMA
189-
CREATE TABLE test.sql_server_schema_natural_id(
172+
CREATE TABLE test.sst_schema_natural_id(
190173
parent_id int,
191174
name nvarchar(255),
192175
description nvarchar(1000),

0 commit comments

Comments
 (0)