diff options
author | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-03-31 21:53:43 -0700 |
---|---|---|
committer | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-04-01 21:34:11 -0700 |
commit | 9896c5fba9686524600d58e703e2aae80105043b (patch) | |
tree | 0c482459a8206758a93aba1c7d76deba70fa09d1 /activerecord | |
parent | 5fa65f94b8c16019d2ddd55f2e59b1bf1c87db89 (diff) | |
download | rails-9896c5fba9686524600d58e703e2aae80105043b.tar.gz rails-9896c5fba9686524600d58e703e2aae80105043b.tar.bz2 rails-9896c5fba9686524600d58e703e2aae80105043b.zip |
Allow postgresql enum_test to be run in random order.
Creating and dropping similar tables within the same connection causes postgresql to look up old values in the cache of tables which have already been dropped.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/domain_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/enum_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/support/postgresql_helper.rb | 8 |
3 files changed, 21 insertions, 9 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/domain_test.rb b/activerecord/test/cases/adapters/postgresql/domain_test.rb index fdf5ce974d..ba25a64fac 100644 --- a/activerecord/test/cases/adapters/postgresql/domain_test.rb +++ b/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)" @@ -28,6 +27,7 @@ class PostgresqlDomainTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/adapters/postgresql/enum_test.rb b/activerecord/test/cases/adapters/postgresql/enum_test.rb index ac78c2426e..fde01314a5 100644 --- a/activerecord/test/cases/adapters/postgresql/enum_test.rb +++ b/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 @@ -27,6 +25,12 @@ class PostgresqlEnumTest < ActiveRecord::TestCase @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 diff --git a/activerecord/test/support/postgresql_helper.rb b/activerecord/test/support/postgresql_helper.rb new file mode 100644 index 0000000000..fa40a46499 --- /dev/null +++ b/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 |