aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/view_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-09-11 13:14:37 +0200
committerYves Senn <yves.senn@gmail.com>2014-09-11 16:47:52 +0200
commit395573b344b0bb0579a325d8f958f692f8f66cc8 (patch)
treeaaaf3d49339737474042afa290a12eef95dcd503 /activerecord/test/cases/view_test.rb
parente40bf04a2f074557467d1a623bf4e34aacf2c701 (diff)
downloadrails-395573b344b0bb0579a325d8f958f692f8f66cc8.tar.gz
rails-395573b344b0bb0579a325d8f958f692f8f66cc8.tar.bz2
rails-395573b344b0bb0579a325d8f958f692f8f66cc8.zip
reuse view test-cases for pg materialized view tests.
Diffstat (limited to 'activerecord/test/cases/view_test.rb')
-rw-r--r--activerecord/test/cases/view_test.rb36
1 files changed, 27 insertions, 9 deletions
diff --git a/activerecord/test/cases/view_test.rb b/activerecord/test/cases/view_test.rb
index 357265aa05..3aed90ba36 100644
--- a/activerecord/test/cases/view_test.rb
+++ b/activerecord/test/cases/view_test.rb
@@ -1,24 +1,28 @@
require "cases/helper"
require "models/book"
-if ActiveRecord::Base.connection.supports_views?
-class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
- fixtures :books
+module ViewBehavior
+ extend ActiveSupport::Concern
+
+ included do
+ fixtures :books
+ end
class Ebook < ActiveRecord::Base
self.primary_key = "id"
end
- setup do
+ def setup
+ super
@connection = ActiveRecord::Base.connection
- @connection.execute <<-SQL
- CREATE VIEW ebooks
- AS SELECT id, name, status FROM books WHERE format = 'ebook'
+ create_view "ebooks", <<-SQL
+ SELECT id, name, status FROM books WHERE format = 'ebook'
SQL
end
- teardown do
- @connection.execute "DROP VIEW ebooks" if @connection.table_exists? "ebooks"
+ def teardown
+ super
+ drop_view "ebooks"
end
def test_reading
@@ -51,6 +55,20 @@ class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
end
end
+if ActiveRecord::Base.connection.supports_views?
+class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
+ include ViewBehavior
+
+ private
+ def create_view(name, query)
+ @connection.execute "CREATE VIEW #{name} AS #{query}"
+ end
+
+ def drop_view(name)
+ @connection.execute "DROP VIEW #{name}" if @connection.table_exists? name
+ end
+end
+
class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
fixtures :books