|
| 1 | +require 'cases/helper_sqlserver' |
| 2 | + |
| 3 | +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 |
| 8 | + end |
| 9 | + |
| 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 |
| 15 | + |
| 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 |
| 21 | + |
| 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 |
| 27 | + |
| 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 |
| 33 | + |
| 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 |
| 41 | + |
| 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 |
| 50 | + |
| 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 |
| 57 | + end |
| 58 | +end |
0 commit comments