From 7c6eb09daf0ad55c0286995529a82076d29fdbc8 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 31 Jan 2012 10:04:47 +0000 Subject: Avoid need to be db superuser to run tests Add a patch from louisecrow (https://github.com/mysociety/fixmytransport/blob/master/lib/patches/fixtures_constraint_disabling.rb) that makes it possible to run the tests without being a database superuser. --- lib/patches/fixtures_constraint_disabling.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/patches/fixtures_constraint_disabling.rb (limited to 'lib/patches/fixtures_constraint_disabling.rb') diff --git a/lib/patches/fixtures_constraint_disabling.rb b/lib/patches/fixtures_constraint_disabling.rb new file mode 100644 index 000000000..7d97e81f7 --- /dev/null +++ b/lib/patches/fixtures_constraint_disabling.rb @@ -0,0 +1,21 @@ +# An alternative way of disabling foreign keys in fixture loading in Postgres and +# does not require superuser permissions +# http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error +require 'active_record/connection_adapters/postgresql_adapter' +module ActiveRecord + module ConnectionAdapters + class PostgreSQLAdapter < AbstractAdapter + def disable_referential_integrity(&block) + transaction { + begin + execute "SET CONSTRAINTS ALL DEFERRED" + yield + ensure + execute "SET CONSTRAINTS ALL IMMEDIATE" + end + } + end + end + end +end + -- cgit v1.2.3