Skip to content

Commit b666c89

Browse files
committed
Add specs
1 parent d3548bd commit b666c89

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

test/cases/adapter_test_sqlserver.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,22 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
379379
assert_match(/CREATE VIEW sst_customers_view/, view_info["VIEW_DEFINITION"])
380380
end
381381

382+
it "allows connection#view_information to work across databases when using qualified object names" do
383+
# College is defined in activerecord_unittest2 database.
384+
view_info = College.connection.send(:view_information, "[activerecord_unittest].[dbo].[sst_customers_view]")
385+
assert_equal("sst_customers_view", view_info["TABLE_NAME"])
386+
assert_match(/CREATE VIEW sst_customers_view/, view_info["VIEW_DEFINITION"])
387+
end
388+
382389
it "allow the connection#view_table_name method to return true table_name for the view" do
383390
assert_equal "customers", connection.send(:view_table_name, "sst_customers_view")
384391
assert_equal "topics", connection.send(:view_table_name, "topics"), "No view here, the same table name should come back."
385392
end
386393

394+
it "allow the connection#view_table_name method to return true table_name for the view for other connections" do
395+
assert_equal "customers", College.connection.send(:view_table_name, "[activerecord_unittest].[dbo].[sst_customers_view]")
396+
assert_equal "topics", College.connection.send(:view_table_name, "topics"), "No view here, the same table name should come back."
397+
end
387398
# With same column names
388399

389400
it "have matching column objects" do

test/models/sqlserver/uuid_view.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
class SSTestUuidView < ActiveRecord::Base
4+
self.table_name = "[activerecord_unittest2].[test2].[sst_uuid_view]"
5+
end

test/schema/sqlserver_specific_schema.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,11 @@
312312
CONSTRAINT PK_sst_composite_with_identity PRIMARY KEY (pk_col_one, pk_col_two)
313313
);
314314
COMPOSITE_WITH_IDENTITY
315+
316+
# Separate db view.
317+
execute "DROP VIEW IF EXISTS sst_cross_college_view"
318+
execute <<-SPECIFIC_SCHEMA_VIEW
319+
CREATE VIEW sst_cross_college_view AS
320+
SELECT * FROM activerecord_unittest2.dbo.colleges
321+
SPECIFIC_SCHEMA_VIEW
315322
end

0 commit comments

Comments
 (0)