Skip to content

Commit

Permalink
Merge pull request #14550 from tgxworld/fix_failing_enum_test_random_…
Browse files Browse the repository at this point in the history
…order

Allow postgresql enum_test to be run in random order.
  • Loading branch information
senny committed Apr 2, 2014
2 parents 442d722 + 9896c5f commit 7934124
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions activerecord/test/cases/adapters/postgresql/domain_test.rb
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
require "cases/helper"
require 'support/postgresql_helper'
require 'active_record/base'
require 'active_record/connection_adapters/postgresql_adapter'

class PostgresqlDomainTest < ActiveRecord::TestCase
include PostgresqlHelper

class PostgresqlDomain < ActiveRecord::Base
self.table_name = "postgresql_domains"
end

def setup
# reset connection to bust all cached statement plans
connection_spec = ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(connection_spec)

@connection = ActiveRecord::Base.connection
@connection.transaction do
@connection.execute "CREATE DOMAIN custom_money as numeric(8,2)"
Expand All @@ -28,6 +27,7 @@ def setup
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_domains'
@connection.execute 'DROP DOMAIN IF EXISTS custom_money'
reset_pg_session
end

def test_column
Expand Down
14 changes: 9 additions & 5 deletions activerecord/test/cases/adapters/postgresql/enum_test.rb
@@ -1,18 +1,16 @@
# -*- coding: utf-8 -*-
require "cases/helper"
require 'support/postgresql_helper'
require 'active_record/base'
require 'active_record/connection_adapters/postgresql_adapter'

class PostgresqlEnumTest < ActiveRecord::TestCase
include PostgresqlHelper

class PostgresqlEnum < ActiveRecord::Base
self.table_name = "postgresql_enums"
end

teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_enums'
@connection.execute 'DROP TYPE IF EXISTS mood'
end

def setup
@connection = ActiveRecord::Base.connection
@connection.transaction do
Expand All @@ -27,6 +25,12 @@ def setup
@connection.send(:reload_type_map)
end

teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_enums'
@connection.execute 'DROP TYPE IF EXISTS mood'
reset_pg_session
end

def test_column
column = PostgresqlEnum.columns_hash["current_mood"]
assert_equal :enum, column.type
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/support/postgresql_helper.rb
@@ -0,0 +1,8 @@
module PostgresqlHelper
# Make sure to drop all cached query plans to prevent invalid reference errors like:
# cache lookup failed for type XYZ
def reset_pg_session
original_connection = ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection(original_connection)
end
end

0 comments on commit 7934124

Please sign in to comment.