Skip to content

Commit 611e81a

Browse files
committed
[Rails5] Fix view_exists? into public.
1 parent d82d7eb commit 611e81a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

TODO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ After we get some tests passing
1313
* Check `sql_for_insert` can do without the table regular expresion.
1414
* Do we need the `query_requires_identity_insert` check in `execute`?
1515
* Does the schema cache serialize properly since we conform to that now?
16+
* What does `supports_materialized_views?` means for SQL Server
17+
http://michaeljswart.com/2014/12/materialized-views-in-sql-server/
18+
https://blogs.msdn.microsoft.com/ssma/2011/06/20/migrating-oracle-materialized-view-to-sql-server/
19+
http://stackoverflow.com/questions/3986366/how-to-create-materialized-views-in-sql-server
1620

1721

1822
#### Does Find By SQL Work?

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def views
2121
tables('VIEW')
2222
end
2323

24+
def view_exists?(table_name)
25+
identifier = SQLServer::Utils.extract_identifiers(table_name)
26+
super(identifier.object)
27+
end
28+
2429
def create_table(table_name, comment: nil, **options)
2530
res = super
2631
clear_cache!
@@ -419,11 +424,6 @@ def lowercase_schema_reflection_sql(node)
419424

420425
# === SQLServer Specific (View Reflection) ====================== #
421426

422-
def view_exists?(table_name)
423-
identifier = SQLServer::Utils.extract_identifiers(table_name)
424-
views.include? identifier.object
425-
end
426-
427427
def view_table_name(table_name)
428428
view_info = view_information(table_name)
429429
view_info ? get_table_name(view_info['VIEW_DEFINITION']) : table_name

test/cases/coerced_tests.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,15 @@ class TransactionIsolationTest < ActiveRecord::TestCase
657657
end
658658

659659

660-
660+
require 'models/book'
661+
class Paperback < ActiveRecord::Base; end
661662
class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
662-
663+
# We have a few fews and test is poor equality based.
664+
coerce_tests! :test_views
665+
# This is deprecated and we dont care in thsi version to pass it.
666+
coerce_tests! :test_table_exists
663667
# We do better than ActiveRecord and find the views PK.
664668
coerce_tests! :test_does_not_assume_id_column_as_primary_key
665-
666669
end
667670

668671

0 commit comments

Comments
 (0)