aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/public_body_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/public_body_spec.rb')
-rw-r--r--spec/models/public_body_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 23842ccff..dc09bdfa6 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -213,6 +213,15 @@ describe PublicBody, " when saving" do
public_body.name.should == "Mark's Public Body"
end
+ it 'should update the right translation when in a locale with an underscore' do
+ AlaveteliLocalization.set_locales('he_IL', 'he_IL')
+ public_body = public_bodies(:humpadink_public_body)
+ translation_count = public_body.translations.size
+ public_body.name = 'Renamed'
+ public_body.save!
+ public_body.translations.size.should == translation_count
+ end
+
it 'should not create a new version when nothing has changed' do
@public_body.versions.size.should == 0
set_default_attributes(@public_body)
@@ -291,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
@@ -473,6 +513,20 @@ describe PublicBody, " when loading CSV files" do
PublicBody.count.should == original_count
end
+
+ it "should be able to load CSV from a file as well as a string" do
+ # Essentially the same code is used for import_csv_from_file
+ # as import_csv, so this is just a basic check that
+ # import_csv_from_file can load from a file at all. (It would
+ # be easy to introduce a regression that broke this, because
+ # of the confusing change in behaviour of CSV.parse between
+ # Ruby 1.8 and 1.9.)
+ original_count = PublicBody.count
+ filename = file_fixture_name('fake-authority-type-with-field-names.csv')
+ PublicBody.import_csv_from_file(filename, '', 'replace', false, 'someadmin')
+ PublicBody.count.should == original_count + 3
+ end
+
end
describe PublicBody do
@@ -604,3 +658,12 @@ describe PublicBody, "when calculating statistics" do
end
end
+
+describe PublicBody, 'when asked for popular bodies' do
+
+ it 'should return bodies correctly when passed the hyphenated version of the locale' do
+ AlaveteliConfiguration.stub!(:frontpage_publicbody_examples).and_return('')
+ PublicBody.popular_bodies('he-IL').should == [public_bodies(:humpadink_public_body)]
+ end
+
+end