aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/view_test.rb
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2015-09-19 15:56:01 -0700
committerJeremy Daer <jeremydaer@gmail.com>2015-09-19 15:56:01 -0700
commit7286677050c1923020c71a77e9427d19391bc20f (patch)
treee2a3bf29c77fbde33074934c86619bd2eae8e186 /activerecord/test/cases/view_test.rb
parent96a0475d10e7a7d95d938518183c581f29cd9045 (diff)
parentad4654f2751217ec93a4fad1ef5454ab1255e833 (diff)
downloadrails-7286677050c1923020c71a77e9427d19391bc20f.tar.gz
rails-7286677050c1923020c71a77e9427d19391bc20f.tar.bz2
rails-7286677050c1923020c71a77e9427d19391bc20f.zip
Merge pull request #21609 from kamipo/do_not_dump_view_as_table
Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
Diffstat (limited to 'activerecord/test/cases/view_test.rb')
-rw-r--r--activerecord/test/cases/view_test.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/cases/view_test.rb b/activerecord/test/cases/view_test.rb
index 1eb1430065..d7b3e223ed 100644
--- a/activerecord/test/cases/view_test.rb
+++ b/activerecord/test/cases/view_test.rb
@@ -1,7 +1,9 @@
require "cases/helper"
require "models/book"
+require "support/schema_dumping_helper"
module ViewBehavior
+ include SchemaDumpingHelper
extend ActiveSupport::Concern
included do
@@ -31,6 +33,15 @@ module ViewBehavior
assert_equal ["Ruby for Rails"], books.map(&:name)
end
+ def test_views
+ assert_equal [Ebook.table_name], @connection.views
+ end
+
+ def test_view_exists
+ view_name = Ebook.table_name
+ assert @connection.view_exists?(view_name), "'#{view_name}' view should exist"
+ end
+
def test_table_exists
view_name = Ebook.table_name
assert @connection.table_exists?(view_name), "'#{view_name}' table should exist"
@@ -53,6 +64,11 @@ module ViewBehavior
end
assert_nil model.primary_key
end
+
+ def test_does_not_dump_view_as_table
+ schema = dump_table_schema "ebooks"
+ assert_no_match %r{create_table "ebooks"}, schema
+ end
end
if ActiveRecord::Base.connection.supports_views?
@@ -70,6 +86,7 @@ class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
end
class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
+ include SchemaDumpingHelper
fixtures :books
class Paperback < ActiveRecord::Base; end
@@ -91,6 +108,15 @@ class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
assert_equal ["Agile Web Development with Rails"], books.map(&:name)
end
+ def test_views
+ assert_equal [Paperback.table_name], @connection.views
+ end
+
+ def test_view_exists
+ view_name = Paperback.table_name
+ assert @connection.view_exists?(view_name), "'#{view_name}' view should exist"
+ end
+
def test_table_exists
view_name = Paperback.table_name
assert @connection.table_exists?(view_name), "'#{view_name}' table should exist"
@@ -109,6 +135,11 @@ class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
def test_does_not_have_a_primary_key
assert_nil Paperback.primary_key
end
+
+ def test_does_not_dump_view_as_table
+ schema = dump_table_schema "paperbacks"
+ assert_no_match %r{create_table "paperbacks"}, schema
+ end
end
# sqlite dose not support CREATE, INSERT, and DELETE for VIEW