From f1169d9d2509189a16f7b03fee5c76b9d023a347 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 1 Apr 2014 22:04:10 -0700 Subject: Add ConnectionHelper to refactor tests. --- activerecord/test/support/connection_helper.rb | 14 ++++++++++++++ activerecord/test/support/postgresql_helper.rb | 8 -------- 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 activerecord/test/support/connection_helper.rb delete mode 100644 activerecord/test/support/postgresql_helper.rb (limited to 'activerecord/test/support') diff --git a/activerecord/test/support/connection_helper.rb b/activerecord/test/support/connection_helper.rb new file mode 100644 index 0000000000..4a19e5df44 --- /dev/null +++ b/activerecord/test/support/connection_helper.rb @@ -0,0 +1,14 @@ +module ConnectionHelper + def run_without_connection + original_connection = ActiveRecord::Base.remove_connection + yield original_connection + ensure + ActiveRecord::Base.establish_connection(original_connection) + end + + # Used to drop all cache query plans in tests. + def reset_connection + original_connection = ActiveRecord::Base.remove_connection + ActiveRecord::Base.establish_connection(original_connection) + end +end diff --git a/activerecord/test/support/postgresql_helper.rb b/activerecord/test/support/postgresql_helper.rb deleted file mode 100644 index fa40a46499..0000000000 --- a/activerecord/test/support/postgresql_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -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 -- cgit v1.2.3