@@ -193,17 +193,31 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
193
193
@identity_insert_sql_unquoted = "INSERT INTO funny_jokes (id, name) VALUES(420, 'Knock knock')"
194
194
@identity_insert_sql_unordered = "INSERT INTO [funny_jokes] ([name],[id]) VALUES('Knock knock',420)"
195
195
@identity_insert_sql_sp = "EXEC sp_executesql N'INSERT INTO [funny_jokes] ([id],[name]) VALUES (@0, @1)', N'@0 int, @1 nvarchar(255)', @0 = 420, @1 = N'Knock knock'"
196
- @identity_insert_sql_unquoted_sp = "EXEC sp_executesql N'INSERT INTO [ funny_jokes] (id, name) VALUES (@0, @1)', N'@0 int, @1 nvarchar(255)', @0 = 420, @1 = N'Knock knock'"
196
+ @identity_insert_sql_unquoted_sp = "EXEC sp_executesql N'INSERT INTO funny_jokes (id, name) VALUES (@0, @1)', N'@0 int, @1 nvarchar(255)', @0 = 420, @1 = N'Knock knock'"
197
197
@identity_insert_sql_unordered_sp = "EXEC sp_executesql N'INSERT INTO [funny_jokes] ([name],[id]) VALUES (@0, @1)', N'@0 nvarchar(255), @1 int', @0 = N'Knock knock', @1 = 420"
198
+
199
+ @identity_insert_sql_non_dbo = "INSERT INTO [test].[aliens] ([id],[name]) VALUES(420,'Mork')"
200
+ @identity_insert_sql_non_dbo_unquoted = "INSERT INTO test.aliens ([id],[name]) VALUES(420,'Mork')"
201
+ @identity_insert_sql_non_dbo_unordered = "INSERT INTO [test].[aliens] ([name],[id]) VALUES('Mork',420)"
202
+ @identity_insert_sql_non_dbo_sp = "EXEC sp_executesql N'INSERT INTO [test].[aliens] ([id],[name]) VALUES (@0, @1)', N'@0 int, @1 nvarchar(255)', @0 = 420, @1 = N'Mork'"
203
+ @identity_insert_sql_non_dbo_unquoted_sp = "EXEC sp_executesql N'INSERT INTO test.aliens (id, name) VALUES (@0, @1)', N'@0 int, @1 nvarchar(255)', @0 = 420, @1 = N'Mork'"
204
+ @identity_insert_sql_non_dbo_unordered_sp = "EXEC sp_executesql N'INSERT INTO [test].[aliens] ([name],[id]) VALUES (@0, @1)', N'@0 nvarchar(255), @1 int', @0 = N'Mork', @1 = 420"
198
205
end
199
206
200
- it "return unquoted table_name to #query_requires_identity_insert? when INSERT sql contains id column" do
201
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql )
202
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unquoted )
203
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unordered )
204
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_sp )
205
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unquoted_sp )
206
- assert_equal "funny_jokes" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unordered_sp )
207
+ it "return quoted table_name to #query_requires_identity_insert? when INSERT sql contains id column" do
208
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql )
209
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unquoted )
210
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unordered )
211
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_sp )
212
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unquoted_sp )
213
+ assert_equal "[funny_jokes]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_unordered_sp )
214
+
215
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo )
216
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo_unquoted )
217
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo_unordered )
218
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo_sp )
219
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo_unquoted_sp )
220
+ assert_equal "[test].[aliens]" , connection . send ( :query_requires_identity_insert? , @identity_insert_sql_non_dbo_unordered_sp )
207
221
end
208
222
209
223
it "return false to #query_requires_identity_insert? for normal SQL" do
@@ -533,6 +547,16 @@ def test_doesnt_error_when_a_select_query_is_called_while_preventing_writes
533
547
end
534
548
end
535
549
550
+ describe 'table is in non-dbo schema' do
551
+ it "records can be created successfully" do
552
+ Alien . create! ( name : 'Trisolarans' )
553
+ end
554
+
555
+ it 'records can be inserted using SQL' do
556
+ Alien . connection . exec_insert ( "insert into [test].[aliens] (id, name) VALUES(1, 'Trisolarans'), (2, 'Xenomorph')" )
557
+ end
558
+ end
559
+
536
560
describe "exec_insert" do
537
561
it 'values clause should be case-insensitive' do
538
562
assert_difference ( "Post.count" , 4 ) do
0 commit comments