diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-09-11 13:37:52 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-09-11 16:47:52 +0200 |
commit | 516f431ab0618a052f53eb5b14e2c6204da244dd (patch) | |
tree | 0a641449f26014aefc04586d1e8c232a8120a23a /activerecord/test/cases/adapters | |
parent | 395573b344b0bb0579a325d8f958f692f8f66cc8 (diff) | |
download | rails-516f431ab0618a052f53eb5b14e2c6204da244dd.tar.gz rails-516f431ab0618a052f53eb5b14e2c6204da244dd.tar.bz2 rails-516f431ab0618a052f53eb5b14e2c6204da244dd.zip |
pg, add test cases for updateable views.
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/view_test.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/view_test.rb b/activerecord/test/cases/adapters/postgresql/view_test.rb index f6f96bb3ba..8a8e1d3b17 100644 --- a/activerecord/test/cases/adapters/postgresql/view_test.rb +++ b/activerecord/test/cases/adapters/postgresql/view_test.rb @@ -1,6 +1,51 @@ require "cases/helper" require "cases/view_test" +class UpdateableViewTest < ActiveRecord::TestCase + fixtures :books + + class PrintedBook < ActiveRecord::Base + self.primary_key = "id" + end + + setup do + @connection = ActiveRecord::Base.connection + @connection.execute <<-SQL + CREATE VIEW printed_books + AS SELECT id, name, status, format FROM books WHERE format = 'paperback' + SQL + end + + teardown do + @connection.execute "DROP VIEW printed_books" if @connection.table_exists? "printed_books" + end + + def test_update_record + book = PrintedBook.first + book.name = "AWDwR" + book.save! + book.reload + assert_equal "AWDwR", book.name + end + + def test_insert_record + PrintedBook.create! name: "Rails in Action", status: 0, format: "paperback" + + new_book = PrintedBook.last + assert_equal "Rails in Action", new_book.name + end + + def test_update_record_to_fail_view_conditions + book = PrintedBook.first + book.format = "ebook" + book.save! + + assert_raises ActiveRecord::RecordNotFound do + book.reload + end + end +end + if ActiveRecord::Base.connection.supports_materialized_views? class MaterializedViewTest < ActiveRecord::TestCase include ViewBehavior |