Skip to content

Commit

Permalink
Merge pull request #21528 from yui-knk/test/add_tests_for_mysql2_view
Browse files Browse the repository at this point in the history
Add tests for test/cases/adapters/mysql2/view_test.rb
  • Loading branch information
senny committed Sep 8, 2015
2 parents e75b92c + bb0d707 commit 8a639ff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 64 deletions.
64 changes: 0 additions & 64 deletions activerecord/test/cases/adapters/postgresql/view_test.rb

This file was deleted.

66 changes: 66 additions & 0 deletions activerecord/test/cases/view_test.rb
Expand Up @@ -110,4 +110,70 @@ def test_does_not_have_a_primary_key
assert_nil Paperback.primary_key
end
end

# sqlite dose not support CREATE, INSERT, and DELETE for VIEW
if current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
class UpdateableViewTest < ActiveRecord::TestCase
self.use_transactional_tests = false
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
end # end fo `if current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)`
end # end fo `if ActiveRecord::Base.connection.supports_views?`

if ActiveRecord::Base.connection.respond_to?(:supports_materialized_views?) &&
ActiveRecord::Base.connection.supports_materialized_views?
class MaterializedViewTest < ActiveRecord::PostgreSQLTestCase
include ViewBehavior

private
def create_view(name, query)
@connection.execute "CREATE MATERIALIZED VIEW #{name} AS #{query}"
end

def drop_view(name)
@connection.execute "DROP MATERIALIZED VIEW #{name}" if @connection.table_exists? name

end
end
end

0 comments on commit 8a639ff

Please sign in to comment.