Skip to content

Commit

Permalink
Merge pull request #14400 from tgxworld/ensure_tables_are_dropped_aft…
Browse files Browse the repository at this point in the history
…er_test

Drop custom tables after each test.
  • Loading branch information
senny committed Mar 20, 2014
2 parents 582cbff + 79405a0 commit 2ca3f33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
@@ -1,9 +1,12 @@
# encoding: utf-8 # encoding: utf-8
require "cases/helper" require "cases/helper"
require 'support/ddl_helper'


module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
class PostgreSQLAdapterTest < ActiveRecord::TestCase class PostgreSQLAdapterTest < ActiveRecord::TestCase
include DdlHelper

def setup def setup
@connection = ActiveRecord::Base.connection @connection = ActiveRecord::Base.connection
end end
Expand Down Expand Up @@ -369,12 +372,8 @@ def insert(ctx, data)
ctx.exec_insert(sql, 'SQL', binds) ctx.exec_insert(sql, 'SQL', binds)
end end


def with_example_table(definition = nil) def with_example_table(definition = 'id serial primary key, number integer, data character varying(255)', &block)
definition ||= 'id serial primary key, number integer, data character varying(255)' super(@connection, 'ex', definition, &block)
@connection.exec_query("create table ex(#{definition})")
yield
ensure
@connection.exec_query('drop table if exists ex')
end end


def connection_without_insert_returning def connection_without_insert_returning
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/support/ddl_helper.rb
@@ -0,0 +1,8 @@
module DdlHelper
def with_example_table(connection, table_name, definition = nil)
connection.exec_query("CREATE TABLE #{table_name}(#{definition})")
yield
ensure
connection.exec_query("DROP TABLE #{table_name}")
end
end

0 comments on commit 2ca3f33

Please sign in to comment.