-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce
connection.supports_views?
and basic view tests.
`AbstractAdapter#supports_views?` defaults to `false` so we have to turn it on in adapter subclasses. Currently the flag only controls test execution. /cc @yahonda
- Loading branch information
Showing
6 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,10 @@ def supports_add_column? | |
true | ||
end | ||
|
||
def supports_views? | ||
true | ||
end | ||
|
||
def active? | ||
@active != false | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "cases/helper" | ||
require "models/book" | ||
|
||
if ActiveRecord::Base.connection.supports_views? | ||
class ViewWithPrimaryKeyTest < ActiveRecord::TestCase | ||
fixtures :books | ||
|
||
class Ebook < ActiveRecord::Base | ||
self.primary_key = "id" | ||
end | ||
|
||
setup do | ||
@connection = ActiveRecord::Base.connection | ||
@connection.execute <<-SQL | ||
CREATE VIEW ebooks | ||
AS SELECT id, name, status FROM books WHERE format = 'ebook' | ||
SQL | ||
end | ||
|
||
teardown do | ||
@connection.execute "DROP VIEW IF EXISTS ebooks" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
senny
Author
Member
|
||
end | ||
|
||
def test_reading | ||
books = Ebook.all | ||
assert_equal [books(:rfr).id], books.map(&:id) | ||
assert_equal ["Ruby for Rails"], books.map(&:name) | ||
end | ||
|
||
def test_table_exists | ||
skip "SQLite does not currently treat views as tables" if current_adapter?(:SQLite3Adapter) | ||
view_name = Ebook.table_name | ||
assert @connection.table_exists?(view_name), "'#{view_name}' table should exist" | ||
end | ||
|
||
def test_column_definitions | ||
assert_equal([["id", :integer], | ||
["name", :string], | ||
["status", :integer]], Ebook.columns.map { |c| [c.name, c.type] }) | ||
end | ||
end | ||
end |
@senny Thanks for the update and notify. Oracle database supports Views so this flag will be set to true.
Unfortunately Oracle does not support
drop if exists
statement. #16778 I'm wondering if there isview_exists?
or similar method.