diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-02-01 22:04:58 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-02-01 22:04:58 +0000 |
commit | ea04caec95cea132143997a1870ae8dd1fc0db5c (patch) | |
tree | f199e3f4187091a7a7c78f7fd6901529658174f7 /lib | |
parent | 59b5b15d56600ffc26d657dfea134ffcfc879725 (diff) | |
parent | a76010c99459559a29901ed75b847384248c7c6e (diff) |
Merge branch 'release/0.5' into develop
Diffstat (limited to 'lib')
-rw-r--r-- | lib/patches/fixtures_constraint_disabling.rb | 21 | ||||
-rw-r--r-- | lib/public_body_categories.rb | 7 |
2 files changed, 24 insertions, 4 deletions
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 + diff --git a/lib/public_body_categories.rb b/lib/public_body_categories.rb index 21a021d39..796b1d53d 100644 --- a/lib/public_body_categories.rb +++ b/lib/public_body_categories.rb @@ -20,7 +20,7 @@ class PublicBodyCategories end def PublicBodyCategories.get - load_categories() if @@CATEGORIES.nil? + load_categories if @@CATEGORIES.empty? @@CATEGORIES[I18n.locale.to_s] || @@CATEGORIES[I18n.default_locale.to_s] || PublicBodyCategories.new([]) end @@ -30,10 +30,9 @@ class PublicBodyCategories end private - @@CATEGORIES = nil + @@CATEGORIES = {} def PublicBodyCategories.load_categories() - @@CATEGORIES = {} if @@CATEGORIES.nil? I18n.available_locales.each do |locale| begin load "public_body_categories_#{locale}.rb" @@ -41,4 +40,4 @@ class PublicBodyCategories end end end -end
\ No newline at end of file +end |