Skip to content

Commit 79405a0

Browse files
committed
Extract with_example_table into helper method.
This setups the helper method which other tests can benefit from.
1 parent f522aeb commit 79405a0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# encoding: utf-8
22
require "cases/helper"
3+
require 'support/ddl_helper'
34

45
module ActiveRecord
56
module ConnectionAdapters
67
class PostgreSQLAdapterTest < ActiveRecord::TestCase
8+
include DdlHelper
9+
710
def setup
811
@connection = ActiveRecord::Base.connection
912
end
@@ -369,12 +372,8 @@ def insert(ctx, data)
369372
ctx.exec_insert(sql, 'SQL', binds)
370373
end
371374

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

380379
def connection_without_insert_returning
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module DdlHelper
2+
def with_example_table(connection, table_name, definition = nil)
3+
connection.exec_query("CREATE TABLE #{table_name}(#{definition})")
4+
yield
5+
ensure
6+
connection.exec_query("DROP TABLE #{table_name}")
7+
end
8+
end

0 commit comments

Comments
 (0)