aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/public_body_controller_spec.rb74
-rw-r--r--spec/controllers/request_controller_spec.rb2
-rw-r--r--spec/models/info_request_spec.rb7
-rw-r--r--spec/models/public_body_spec.rb46
4 files changed, 104 insertions, 25 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 92130f3d0..2d1b1466f 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -1,6 +1,8 @@
# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'nokogiri'
+
describe PublicBodyController, "when showing a body" do
render_views
@@ -78,24 +80,80 @@ describe PublicBodyController, "when listing bodies" do
response.should be_success
end
- it "should list all bodies from default locale, even when there are no translations for selected locale" do
- I18n.with_locale(:en) do
- @english_only = PublicBody.new(:name => 'English only',
- :short_name => 'EO',
- :request_email => 'english@flourish.org',
- :last_edit_editor => 'test',
- :last_edit_comment => '')
- @english_only.save
+ def make_single_language_example(locale)
+ result = nil
+ I18n.with_locale(locale) do
+ case locale
+ when :en
+ result = PublicBody.new(:name => 'English only',
+ :short_name => 'EO')
+ when :es
+ result = PublicBody.new(:name => 'Español Solamente',
+ :short_name => 'ES')
+ else
+ raise StandardError.new "Unknown locale #{locale}"
+ end
+ result.request_email = "#{locale}@example.org"
+ result.last_edit_editor = 'test'
+ result.last_edit_comment = ''
+ result.save
end
+ result
+ end
+
+ it "with no fallback, should only return bodies from the current locale" do
+ @english_only = make_single_language_example :en
+ @spanish_only = make_single_language_example :es
+ get :list, {:locale => 'es'}
+ assigns[:public_bodies].include?(@english_only).should == false
+ assigns[:public_bodies].include?(@spanish_only).should == true
+ end
+
+ it "if fallback is requested, should list all bodies from default locale, even when there are no translations for selected locale" do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ @english_only = make_single_language_example :en
get :list, {:locale => 'es'}
assigns[:public_bodies].include?(@english_only).should == true
end
+ it 'if fallback is requested, should still list public bodies only with translations in the current locale' do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ @spanish_only = make_single_language_example :es
+ get :list, {:locale => 'es'}
+ assigns[:public_bodies].include?(@spanish_only).should == true
+ end
+
+ it "if fallback is requested, make sure that there are no duplicates listed" do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ get :list, {:locale => 'es'}
+ pb_ids = assigns[:public_bodies].map { |pb| pb.id }
+ unique_pb_ids = pb_ids.uniq
+ pb_ids.sort.should === unique_pb_ids.sort
+ end
+
it 'should show public body names in the selected locale language if present' do
get :list, {:locale => 'es'}
response.should contain('El Department for Humpadinking')
end
+ it 'should not show the internal admin authority' do
+ PublicBody.internal_admin_body
+ get :list, {:locale => 'en'}
+ response.should_not contain('Internal admin authority')
+ end
+
+ it 'should order on the translated name, even with the fallback' do
+ # The names of each public body is in:
+ # <span class="head"><a>Public Body Name</a></span>
+ # ... eo extract all of those, and check that they are ordered:
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ get :list, {:locale => 'es'}
+ parsed = Nokogiri::HTML(response.body)
+ public_body_names = parsed.xpath '//span[@class="head"]/a/text()'
+ public_body_names = public_body_names.map { |pb| pb.to_s }
+ public_body_names.should == public_body_names.sort
+ end
+
it 'should show public body names in the selected locale language if present for a locale with underscores' do
AlaveteliLocalization.set_locales('he_IL en', 'en')
get :list, {:locale => 'he_IL'}
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 2c605a139..9c4e16c67 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -174,7 +174,7 @@ describe RequestController, "when changing things that appear on the request pag
ir.save!
PurgeRequest.all().first.model_id.should == ir.id
end
- it "should not create more than one entry for any given resourcce" do
+ it "should not create more than one entry for any given resource" do
ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
ir.save!
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 3f2e02189..ab36a201c 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -896,8 +896,9 @@ describe InfoRequest do
describe 'when changing a described_state' do
- it "should change the counts on its PublicBody" do
+ it "should change the counts on its PublicBody without saving a new version" do
pb = public_bodies(:geraldine_public_body)
+ old_version_count = pb.versions.count
old_successful_count = pb.info_requests_successful_count
old_not_held_count = pb.info_requests_not_held_count
ir = InfoRequest.new(:external_url => 'http://www.example.com',
@@ -909,15 +910,19 @@ describe InfoRequest do
pb.info_requests_successful_count.should == (old_successful_count + 1)
ir.described_state = 'not_held'
ir.save!
+ pb.reload
pb.info_requests_successful_count.should == old_successful_count
pb.info_requests_not_held_count.should == (old_not_held_count + 1)
ir.described_state = 'successful'
ir.save!
+ pb.reload
pb.info_requests_successful_count.should == (old_successful_count + 1)
pb.info_requests_not_held_count.should == old_not_held_count
ir.destroy
+ pb.reload
pb.info_requests_successful_count.should == old_successful_count
pb.info_requests_successful_count.should == old_not_held_count
+ pb.versions.count.should == old_version_count
end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 90affaaaa..3578c0e9c 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -136,36 +136,32 @@ describe PublicBody, " when saving" do
@public_body = PublicBody.new
end
+ def set_default_attributes(public_body)
+ public_body.name = "Testing Public Body"
+ public_body.short_name = "TPB"
+ public_body.request_email = "request@localhost"
+ public_body.last_edit_editor = "*test*"
+ public_body.last_edit_comment = "This is a test"
+ end
+
it "should not be valid without setting some parameters" do
@public_body.should_not be_valid
end
it "should not be valid with misformatted request email" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
+ set_default_attributes(@public_body)
@public_body.request_email = "requestBOOlocalhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
@public_body.should_not be_valid
@public_body.should have(1).errors_on(:request_email)
end
it "should save" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
+ set_default_attributes(@public_body)
@public_body.save!
end
it "should update first_letter" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
-
+ set_default_attributes(@public_body)
@public_body.first_letter.should be_nil
@public_body.save!
@public_body.first_letter.should == 'T'
@@ -178,6 +174,26 @@ describe PublicBody, " when saving" do
public_body.name.should == "Mark's Public Body"
end
+
+ it 'should not create a new version when nothing has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ end
+
+ it 'should create a new version if something has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.name = 'Test'
+ @public_body.save!
+ @public_body.versions.size.should == 2
+ end
+
end
describe PublicBody, "when searching" do