Skip to content

Commit 188f986

Browse files
author
Jippe Holwerda
committed
Fixed failing tests.
1 parent f90848a commit 188f986

File tree

1 file changed

+57
-45
lines changed

1 file changed

+57
-45
lines changed
Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,70 @@
11
require 'cases/helper_sqlserver'
22

33
class FullyQualifiedIdentifierTestSQLServer < ActiveRecord::TestCase
4-
it 'should use fully qualified table name in select from clause' do
5-
table = Arel::Table.new("[my.server].db.schema.table")
6-
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table]"
7-
assert_equal expected_sql, table.project(Arel.star).to_sql
4+
describe 'local server' do
5+
it 'should use table name in select projections' do
6+
table = Arel::Table.new(:table)
7+
expected_sql = "SELECT [table].[name] FROM [table]"
8+
assert_equal expected_sql, table.project(table[:name]).to_sql
9+
end
810
end
911

10-
it 'should not use fully qualified table name in select projections' do
11-
table = Arel::Table.new("[my.server].db.schema.table")
12-
expected_sql = "SELECT [table].[name] FROM [my.server].[db].[schema].[table]"
13-
assert_equal expected_sql, table.project(table[:name]).to_sql
14-
end
12+
describe 'remote server' do
13+
before do
14+
connection.instance_variable_get(:@connection_options)[:database_prefix] = "[my.server].db.schema."
15+
end
1516

16-
it 'should not use fully qualified table name in where clause' do
17-
table = Arel::Table.new("[my.server].db.schema.table")
18-
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
19-
assert_equal expected_sql, table.project(Arel.star).where(table[:id].eq(42)).to_sql
20-
end
17+
after do
18+
connection.instance_variable_get(:@connection_options).delete(:database_prefix)
19+
end
2120

22-
it 'should not use fully qualified table name in order clause' do
23-
table = Arel::Table.new("[my.server].db.schema.table")
24-
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] ORDER BY [table].[name]"
25-
assert_equal expected_sql, table.project(Arel.star).order(table[:name]).to_sql
26-
end
21+
it 'should use fully qualified table name in select from clause' do
22+
table = Arel::Table.new(:table)
23+
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table]"
24+
assert_equal expected_sql, table.project(Arel.star).to_sql
25+
end
2726

28-
it 'should use table name in select projections' do
29-
table = Arel::Table.new(:table)
30-
expected_sql = "SELECT [table].[name] FROM [table]"
31-
assert_equal expected_sql, table.project(table[:name]).to_sql
32-
end
27+
it 'should not use fully qualified table name in select projections' do
28+
table = Arel::Table.new(:table)
29+
expected_sql = "SELECT [table].[name] FROM [my.server].[db].[schema].[table]"
30+
assert_equal expected_sql, table.project(table[:name]).to_sql
31+
end
3332

34-
it 'should use fully qualified table name in insert statement' do
35-
manager = Arel::InsertManager.new(Arel::Table.engine)
36-
manager.into Arel::Table.new("[my.server].db.schema.table")
37-
manager.values = manager.create_values [Arel.sql('*')], %w{ a }
38-
expected_sql = "INSERT INTO [my.server].[db].[schema].[table] VALUES (*)"
39-
assert_equal expected_sql, manager.to_sql
40-
end
33+
it 'should not use fully qualified table name in where clause' do
34+
table = Arel::Table.new(:table)
35+
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
36+
assert_equal expected_sql, table.project(Arel.star).where(table[:id].eq(42)).to_sql
37+
end
4138

42-
it 'should use fully qualified table name in update statement' do
43-
table = Arel::Table.new("[my.server].db.schema.table")
44-
manager = Arel::UpdateManager.new(Arel::Table.engine)
45-
manager.table(table).where(table[:id].eq(42))
46-
manager.set([[table[:name], "Bob"]])
47-
expected_sql = "UPDATE [my.server].[db].[schema].[table] SET [name] = N'Bob' WHERE [table].[id] = 42"
48-
assert_equal expected_sql, manager.to_sql
49-
end
39+
it 'should not use fully qualified table name in order clause' do
40+
table = Arel::Table.new(:table)
41+
expected_sql = "SELECT * FROM [my.server].[db].[schema].[table] ORDER BY [table].[name]"
42+
assert_equal expected_sql, table.project(Arel.star).order(table[:name]).to_sql
43+
end
44+
45+
it 'should use fully qualified table name in insert statement' do
46+
manager = Arel::InsertManager.new(Arel::Table.engine)
47+
manager.into Arel::Table.new(:table)
48+
manager.values = manager.create_values [Arel.sql('*')], %w{ a }
49+
expected_sql = "INSERT INTO [my.server].[db].[schema].[table] VALUES (*)"
50+
assert_equal expected_sql, manager.to_sql
51+
end
52+
53+
it 'should use fully qualified table name in update statement' do
54+
table = Arel::Table.new(:table)
55+
manager = Arel::UpdateManager.new(Arel::Table.engine)
56+
manager.table(table).where(table[:id].eq(42))
57+
manager.set([[table[:name], "Bob"]])
58+
expected_sql = "UPDATE [my.server].[db].[schema].[table] SET [name] = N'Bob' WHERE [table].[id] = 42"
59+
assert_equal expected_sql, manager.to_sql
60+
end
5061

51-
it 'should use fully qualified table name in delete statement' do
52-
table = Arel::Table.new("[my.server].db.schema.table")
53-
manager = Arel::DeleteManager.new(Arel::Table.engine)
54-
manager.from(table).where(table[:id].eq(42))
55-
expected_sql = "DELETE FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
56-
assert_equal expected_sql, manager.to_sql
62+
it 'should use fully qualified table name in delete statement' do
63+
table = Arel::Table.new(:table)
64+
manager = Arel::DeleteManager.new(Arel::Table.engine)
65+
manager.from(table).where(table[:id].eq(42))
66+
expected_sql = "DELETE FROM [my.server].[db].[schema].[table] WHERE [table].[id] = 42"
67+
assert_equal expected_sql, manager.to_sql
68+
end
5769
end
5870
end

0 commit comments

Comments
 (0)