diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/alaveteli_external_command.rb | 23 | ||||
-rwxr-xr-x | spec/lib/alaveteli_external_command_scripts/error.sh | 4 | ||||
-rwxr-xr-x | spec/lib/alaveteli_external_command_scripts/segfault.sh | 3 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 31 | ||||
-rw-r--r-- | spec/spec_helper.rb | 5 |
5 files changed, 66 insertions, 0 deletions
diff --git a/spec/lib/alaveteli_external_command.rb b/spec/lib/alaveteli_external_command.rb new file mode 100644 index 000000000..18afeda33 --- /dev/null +++ b/spec/lib/alaveteli_external_command.rb @@ -0,0 +1,23 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +require 'alaveteli_external_command' + +script_dir = File.join(File.dirname(__FILE__), 'alaveteli_external_command_scripts') +segfault_script = File.join(script_dir, 'segfault.sh') +error_script = File.join(script_dir, 'error.sh') + +describe "when running external commands" do + + it "should detect a non-zero exit status" do + $stderr.should_receive(:puts).with(/Error from/) + t = AlaveteliExternalCommand.run(error_script) + assert_nil t + end + + it "should detect when an external command crashes" do + $stderr.should_receive(:puts).with(/exited abnormally/) + t = AlaveteliExternalCommand.run(segfault_script) + assert_nil t + end + +end diff --git a/spec/lib/alaveteli_external_command_scripts/error.sh b/spec/lib/alaveteli_external_command_scripts/error.sh new file mode 100755 index 000000000..65e74b3c6 --- /dev/null +++ b/spec/lib/alaveteli_external_command_scripts/error.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "this is my error message" >&1 +exit 1 diff --git a/spec/lib/alaveteli_external_command_scripts/segfault.sh b/spec/lib/alaveteli_external_command_scripts/segfault.sh new file mode 100755 index 000000000..f96ba5be8 --- /dev/null +++ b/spec/lib/alaveteli_external_command_scripts/segfault.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +kill -11 $$ diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index ed24ced52..dc09bdfa6 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -300,6 +300,37 @@ describe PublicBody, "when searching" do end end +describe PublicBody, "when asked for the internal_admin_body" do + before(:each) do + # Make sure that there's no internal_admin_body before each of + # these tests: + PublicBody.connection.delete("DELETE FROM public_bodies WHERE url_name = 'internal_admin_body'") + PublicBody.connection.delete("DELETE FROM public_body_translations WHERE url_name = 'internal_admin_body'") + end + + it "should create the internal_admin_body if it didn't exist" do + iab = PublicBody.internal_admin_body + iab.should_not be_nil + end + + it "should find the internal_admin_body even if the default locale has changed since it was created" do + with_default_locale("en") do + I18n.with_locale(:en) do + iab = PublicBody.internal_admin_body + iab.should_not be_nil + end + end + with_default_locale("es") do + I18n.with_locale(:es) do + iab = PublicBody.internal_admin_body + iab.should_not be_nil + end + end + end + +end + + describe PublicBody, " when dealing public body locales" do it "shouldn't fail if it internal_admin_body was created in a locale other than the default" do # first time, do it with the non-default locale diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1eeb8603b..52752dca5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -187,11 +187,16 @@ Spork.prefork do end end + # Reset the default locale, making sure that the previous default locale + # is also cleared from the fallbacks def with_default_locale(locale) original_default_locale = I18n.default_locale + original_fallbacks = I18n.fallbacks + I18n.fallbacks = nil I18n.default_locale = locale yield ensure + I18n.fallbacks = original_fallbacks I18n.default_locale = original_default_locale end |