diff options
Diffstat (limited to 'spec')
24 files changed, 329 insertions, 177 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 8e9d17fbe..e9a0f0be4 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -1,18 +1,6 @@ # coding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -def normalise_whitespace(s) - s = s.gsub(/\A\s+|\s+\Z/, "") - s = s.gsub(/\s+/, " ") - return s -end - -RSpec::Matchers.define :be_equal_modulo_whitespace_to do |expected| - match do |actual| - normalise_whitespace(actual) == normalise_whitespace(expected) - end -end - describe ApiController, "when using the API" do describe 'checking API keys' do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index def9dfc7e..23f19f389 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -17,92 +17,6 @@ describe RequestController, "when listing recent requests" do response.should render_template('list') end - it "should filter requests" do - get :list, :view => 'all' - assigns[:list_results].map(&:info_request).should =~ InfoRequest.all - - # default sort order is the request with the most recently created event first - assigns[:list_results].map(&:info_request).should == InfoRequest.all( - :order => "(select max(info_request_events.created_at) from info_request_events where info_request_events.info_request_id = info_requests.id) DESC") - - get :list, :view => 'successful' - assigns[:list_results].map(&:info_request).should =~ InfoRequest.all( - :conditions => "id in ( - select info_request_id - from info_request_events - where not exists ( - select * - from info_request_events later_events - where later_events.created_at > info_request_events.created_at - and later_events.info_request_id = info_request_events.info_request_id - and later_events.described_state is not null - ) - and info_request_events.described_state in ('successful', 'partially_successful') - )") - end - - it "should filter requests by date" do - # The semantics of the search are that it finds any InfoRequest - # that has any InfoRequestEvent created in the specified range - - get :list, :view => 'all', :request_date_before => '13/10/2007' - assigns[:list_results].map(&:info_request).should =~ InfoRequest.all( - :conditions => "id in (select info_request_id from info_request_events where created_at < '2007-10-13'::date)") - - get :list, :view => 'all', :request_date_after => '13/10/2007' - assigns[:list_results].map(&:info_request).should =~ InfoRequest.all( - :conditions => "id in (select info_request_id from info_request_events where created_at > '2007-10-13'::date)") - - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:list_results].map(&:info_request).should =~ InfoRequest.all( - :conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)") - end - - it "should list internal_review requests as unresolved ones" do - get :list, :view => 'awaiting' - - # This doesn’t precisely duplicate the logic of the actual - # query, but it is close enough to give the same result with - # the current set of test data. - assigns[:list_results].should =~ InfoRequestEvent.all( - :conditions => "described_state in ( - 'waiting_response', 'waiting_clarification', - 'internal_review', 'gone_postal', 'error_message', 'requires_admin' - ) and not exists ( - select * - from info_request_events later_events - where later_events.created_at > info_request_events.created_at - and later_events.info_request_id = info_request_events.info_request_id - )") - - - get :list, :view => 'awaiting' - assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == false - - event = info_request_events(:useless_incoming_message_event) - event.described_state = event.calculated_state = "internal_review" - event.save! - rebuild_xapian_index - - get :list, :view => 'awaiting' - assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == true - end - - it "should assign the first page of results" do - xap_results = mock(ActsAsXapian::Search, - :results => (1..25).to_a.map { |m| { :model => m } }, - :matches_estimated => 1000000) - - ActsAsXapian::Search.should_receive(:new). - with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)", - :sort_by_prefix => "created_at", :offset => 0, :limit => 25, :sort_by_ascending => true, - :collapse_by_prefix => "request_collapse"). - and_return(xap_results) - get :list, :view => 'all' - assigns[:list_results].size.should == 25 - assigns[:show_no_more_than].should == RequestController::MAX_RESULTS - end - it "should return 404 for pages we don't want to serve up" do xap_results = mock(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 399f48acb..14731f090 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -58,7 +58,7 @@ describe ServicesController, "when returning a message for people in other count FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK") get :other_country_message response.should be_success - response.body.should == 'Hello! We have an <a href="/help/alaveteli?country_name=Deutschland">important message</a> for visitors outside Deutschland <span class="close-button">X</span>' + response.body.should == 'Hello! We have an <a href="/help/alaveteli?country_name=Deutschland">important message</a> for visitors outside Deutschland' end it "should default to no message if the country_from_ip domain doesn't exist" do AlaveteliConfiguration.stub!(:gaze_url).and_return('http://12123sdf14qsd.com') diff --git a/spec/fixtures/files/email-folding-example-1.txt.expected b/spec/fixtures/files/email-folding-example-1.txt.expected index 801542288..45dabf156 100644 --- a/spec/fixtures/files/email-folding-example-1.txt.expected +++ b/spec/fixtures/files/email-folding-example-1.txt.expected @@ -8,3 +8,10 @@ On behalf of James Hall, Chief Executive Identity and Passport Service <<9032 C Pollard final response.doc>> +FOLDED_QUOTED_SECTION + +FOLDED_QUOTED_SECTION + + +FOLDED_QUOTED_SECTION + diff --git a/spec/fixtures/files/email-folding-example-10.txt b/spec/fixtures/files/email-folding-example-10.txt index 0fabb7f9c..a0773e6ff 100644 --- a/spec/fixtures/files/email-folding-example-10.txt +++ b/spec/fixtures/files/email-folding-example-10.txt @@ -3,13 +3,13 @@ Department of Health, please visit the 'Contact us' page on the Department’s website. ----------------------------------------------------------------------------------------- - - Apologies that you were not able to read our previous response of 4 - October. Please find the text of that email below. - + + Apologies that you were not able to read our previous response of 4 + October. Please find the text of that email below. + Our ref: DE00000642471 -Dear Ms Peters Rock, +Dear Ms Peters Rock, You requested your correspondence to be treated under the Freedom of Information Act. However, as your correspondence asked for general @@ -19,7 +19,7 @@ correspondence under the provisions of the Act. I am sorry I cannot be more helpful. -Yours sincerely, +Yours sincerely, Simon Dove Customer Service Centre Department of Health diff --git a/spec/fixtures/files/email-folding-example-10.txt.expected b/spec/fixtures/files/email-folding-example-10.txt.expected index e4f704c0e..5b609dc12 100644 --- a/spec/fixtures/files/email-folding-example-10.txt.expected +++ b/spec/fixtures/files/email-folding-example-10.txt.expected @@ -3,13 +3,13 @@ Department of Health, please visit the 'Contact us' page on the Department’s website. ----------------------------------------------------------------------------------------- - - Apologies that you were not able to read our previous response of 4 - October. Please find the text of that email below. - + + Apologies that you were not able to read our previous response of 4 + October. Please find the text of that email below. + Our ref: DE00000642471 -Dear Ms Peters Rock, +Dear Ms Peters Rock, You requested your correspondence to be treated under the Freedom of Information Act. However, as your correspondence asked for general @@ -19,7 +19,8 @@ correspondence under the provisions of the Act. I am sorry I cannot be more helpful. -Yours sincerely, +Yours sincerely, Simon Dove Customer Service Centre Department of Health +FOLDED_QUOTED_SECTION diff --git a/spec/fixtures/files/email-folding-example-11.txt b/spec/fixtures/files/email-folding-example-11.txt new file mode 100644 index 000000000..635d7aa4f --- /dev/null +++ b/spec/fixtures/files/email-folding-example-11.txt @@ -0,0 +1,45 @@ + Hello Example, + + This is a reply to your test request Nov 28. + + Regards. + + On Thu, Nov 28, 2013 at 9:08 AM, Example User + <[1]request-x-xxx@xxx.com> wrote: + + Dear Test Authority, + + This is the request body. + + Yours faithfully, + + Example User + + ------------------------------------------------------------------- + + Please use this email address for all replies to this request: + [2]request-x-xxx@xxx.com + + Is [3]testauthority@example.com the wrong address for Freedom of + Information requests to AYG Test Authority? If so, please contact us + using this form: + [4]http://example.com/help/contact + + Disclaimer: This message and any reply that you make will be published + on the internet. Our privacy and copyright policies: + [5]http://example.com/help/officers + + If you find this service useful as an FOI officer, please ask your web + manager to link to us from your organisation's FOI page. + + ------------------------------------------------------------------- + +References + + Visible links + 1. mailto:request-x-xxx@xxx.com + 2. mailto:request-x-xxx@xxx.com + 3. mailto:testauthority@example.com + 4. http://example.com/help/contact + 5. http://example.com/help/officers + diff --git a/spec/fixtures/files/email-folding-example-11.txt.expected b/spec/fixtures/files/email-folding-example-11.txt.expected new file mode 100644 index 000000000..e336062c7 --- /dev/null +++ b/spec/fixtures/files/email-folding-example-11.txt.expected @@ -0,0 +1,8 @@ + Hello Example, + + This is a reply to your test request Nov 28. + + Regards. + + +FOLDED_QUOTED_SECTION diff --git a/spec/fixtures/files/email-folding-example-2.txt.expected b/spec/fixtures/files/email-folding-example-2.txt.expected index e52fbe443..df578390d 100644 --- a/spec/fixtures/files/email-folding-example-2.txt.expected +++ b/spec/fixtures/files/email-folding-example-2.txt.expected @@ -2,3 +2,4 @@ Preface to the message which we are not interested in ----------------------------------------------------------------------------------------- Important message about cheese +FOLDED_QUOTED_SECTION diff --git a/spec/fixtures/files/email-folding-example-3.txt.expected b/spec/fixtures/files/email-folding-example-3.txt.expected index e2cca4933..accb40150 100644 --- a/spec/fixtures/files/email-folding-example-3.txt.expected +++ b/spec/fixtures/files/email-folding-example-3.txt.expected @@ -3,3 +3,10 @@ Reference : T3241/8 Thank you for your e-mail enquiry of 12th February. A reply is attached. +FOLDED_QUOTED_SECTION + +FOLDED_QUOTED_SECTION + + +FOLDED_QUOTED_SECTION + diff --git a/spec/fixtures/files/email-folding-example-5.txt.expected b/spec/fixtures/files/email-folding-example-5.txt.expected index fbb0f0f50..46d7f731a 100644 --- a/spec/fixtures/files/email-folding-example-5.txt.expected +++ b/spec/fixtures/files/email-folding-example-5.txt.expected @@ -1,11 +1,11 @@ Hi Simon -My apologies for timescale of response. The data forwarded is a public -register, and is updated on a frequent and regular basis; your request -unfortunately coincided with annual leave and a monthly update of the -spreadsheet. As the definition of an HMO under the Housing Act 2004 -differs to that under planning legislation, I have forwarded this and -your original request on to Andy England, Development Control Manager to +My apologies for timescale of response. The data forwarded is a public +register, and is updated on a frequent and regular basis; your request +unfortunately coincided with annual leave and a monthly update of the +spreadsheet. As the definition of an HMO under the Housing Act 2004 +differs to that under planning legislation, I have forwarded this and +your original request on to Andy England, Development Control Manager to respond independantly. If I can be of further assistance please contact me diff --git a/spec/fixtures/files/email-folding-example-7.txt.expected b/spec/fixtures/files/email-folding-example-7.txt.expected index 0ef8fd82b..cb6961038 100644 --- a/spec/fixtures/files/email-folding-example-7.txt.expected +++ b/spec/fixtures/files/email-folding-example-7.txt.expected @@ -13,4 +13,5 @@ Telephone +44 (0) 116 2222222 Extn 5221 VM No. 8035 Fax + 44 (0) 116 2485217 -<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>>
\ No newline at end of file +<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>> +FOLDED_QUOTED_SECTION diff --git a/spec/fixtures/files/email-folding-example-8.txt.expected b/spec/fixtures/files/email-folding-example-8.txt.expected index b5dc10c0d..e8c08f4ca 100644 --- a/spec/fixtures/files/email-folding-example-8.txt.expected +++ b/spec/fixtures/files/email-folding-example-8.txt.expected @@ -3,4 +3,5 @@ I will be out of the office starting 11/04/2008 and will not return until I will respond to your message when I return. If you have any urgent queries please ring 02085419088 for Legal Business Support queries or -contact Eileen Perren for FOI or DP queries
\ No newline at end of file +contact Eileen Perren for FOI or DP queries +FOLDED_QUOTED_SECTION diff --git a/spec/fixtures/files/email-folding-example-9.txt.expected b/spec/fixtures/files/email-folding-example-9.txt.expected index 2d2381a34..d222e9438 100644 --- a/spec/fixtures/files/email-folding-example-9.txt.expected +++ b/spec/fixtures/files/email-folding-example-9.txt.expected @@ -7,3 +7,9 @@ Yours sincerely MICHAEL HEGARTY FOI Officer +FOLDED_QUOTED_SECTION + +FOLDED_QUOTED_SECTION + + +FOLDED_QUOTED_SECTION diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index b29419ef3..2259db6c2 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -20,6 +20,45 @@ describe LinkToHelper do end + describe 'when displaying a user link for a request' do + + context "for external requests" do + before do + @info_request = mock_model(InfoRequest, :external_user_name => nil, + :is_external? => true) + end + + it 'should return the text "Anonymous user" with a link to the privacy help pages when there is no external username' do + request_user_link(@info_request).should == '<a href="/help/privacy#anonymous">Anonymous user</a>' + end + + it 'should return a link with an alternative text if requested' do + request_user_link(@info_request, 'other text').should == '<a href="/help/privacy#anonymous">other text</a>' + end + + it 'should display an absolute link if requested' do + request_user_link_absolute(@info_request).should == '<a href="http://test.host/help/privacy#anonymous">Anonymous user</a>' + end + end + + context "for normal requests" do + + before do + @info_request = FactoryGirl.build(:info_request) + end + + it 'should display a relative link by default' do + request_user_link(@info_request).should == '<a href="/user/example_user">Example User</a>' + end + + it 'should display an absolute link if requested' do + request_user_link_absolute(@info_request).should == '<a href="http://test.host/user/example_user">Example User</a>' + end + + end + + end + describe 'when displaying a user admin link for a request' do it 'should return the text "An anonymous user (external)" in the case where there is no external username' do 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/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index c0a7e5340..c27870afc 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -165,7 +165,7 @@ describe IncomingMessage, " when dealing with incoming mail" do message = File.read(file) parsed = IncomingMessage.remove_quoted_sections(message) expected = File.read("#{file}.expected") - parsed.should include(expected) + parsed.should be_equal_modulo_whitespace_to expected end end @@ -462,7 +462,7 @@ describe IncomingMessage, " when censoring data" do data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed" end - it 'should handle multibyte characters correctly', :focus => true do + it 'should handle multibyte characters correctly' do orig_data = 'á' data = orig_data.dup @regex_censor_rule = CensorRule.new() diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index dcc94e967..ade75e2cc 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -1177,4 +1177,100 @@ describe InfoRequest do request_events.map(&:info_request).select{|x|x.url_title =~ /^spam/}.length.should == 1 end end + + describe InfoRequest, "when constructing a list of requests by query" do + + before(:each) do + get_fixtures_xapian_index + end + + def apply_filters(filters) + results = InfoRequest.request_list(filters, page=1, per_page=100, max_results=100) + results[:results].map(&:info_request) + end + + it "should filter requests" do + apply_filters(:latest_status => 'all').should =~ InfoRequest.all + + # default sort order is the request with the most recently created event first + apply_filters(:latest_status => 'all').should == InfoRequest.all( + :order => "(SELECT max(info_request_events.created_at) + FROM info_request_events + WHERE info_request_events.info_request_id = info_requests.id) + DESC") + + apply_filters(:latest_status => 'successful').should =~ InfoRequest.all( + :conditions => "id in ( + SELECT info_request_id + FROM info_request_events + WHERE NOT EXISTS ( + SELECT * + FROM info_request_events later_events + WHERE later_events.created_at > info_request_events.created_at + AND later_events.info_request_id = info_request_events.info_request_id + AND later_events.described_state IS NOT null + ) + AND info_request_events.described_state IN ('successful', 'partially_successful') + )") + + end + + it "should filter requests by date" do + # The semantics of the search are that it finds any InfoRequest + # that has any InfoRequestEvent created in the specified range + filters = {:latest_status => 'all', :request_date_before => '13/10/2007'} + apply_filters(filters).should =~ InfoRequest.all( + :conditions => "id IN (SELECT info_request_id + FROM info_request_events + WHERE created_at < '2007-10-13'::date)") + + filters = {:latest_status => 'all', :request_date_after => '13/10/2007'} + apply_filters(filters).should =~ InfoRequest.all( + :conditions => "id IN (SELECT info_request_id + FROM info_request_events + WHERE created_at > '2007-10-13'::date)") + + filters = {:latest_status => 'all', + :request_date_after => '13/10/2007', + :request_date_before => '01/11/2007'} + apply_filters(filters).should =~ InfoRequest.all( + :conditions => "id IN (SELECT info_request_id + FROM info_request_events + WHERE created_at BETWEEN '2007-10-13'::date + AND '2007-11-01'::date)") + end + + + it "should list internal_review requests as unresolved ones" do + + # This doesn’t precisely duplicate the logic of the actual + # query, but it is close enough to give the same result with + # the current set of test data. + results = apply_filters(:latest_status => 'awaiting') + results.should =~ InfoRequest.all( + :conditions => "id IN (SELECT info_request_id + FROM info_request_events + WHERE described_state in ( + 'waiting_response', 'waiting_clarification', + 'internal_review', 'gone_postal', 'error_message', 'requires_admin' + ) and not exists ( + select * + from info_request_events later_events + where later_events.created_at > info_request_events.created_at + and later_events.info_request_id = info_request_events.info_request_id + ))") + + + results.include?(info_requests(:fancy_dog_request)).should == false + + event = info_request_events(:useless_incoming_message_event) + event.described_state = event.calculated_state = "internal_review" + event.save! + rebuild_xapian_index + results = apply_filters(:latest_status => 'awaiting') + results.include?(info_requests(:fancy_dog_request)).should == true + end + + + end end diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index 0e157e2c5..e70f474a0 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -10,12 +10,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe ProfilePhoto, "when constructing a new photo" do +describe ProfilePhoto, "when constructing a new photo" do - before do + before do @mock_user = mock_model(User) end - + it 'should take no image as invalid' do profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user) profile_photo.valid?.should == false @@ -26,7 +26,15 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.valid?.should == false end - it 'should accept and convert a PNG to right size' do + it 'should translate a no image error message' do + I18n.with_locale(:es) do + profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user) + profile_photo.valid?.should == false + profile_photo.errors[:data].should == ['Por favor elige el fichero que contiene tu foto'] + end + end + + it 'should accept and convert a PNG to right size' do data = load_file_fixture("parrot.png") profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user) profile_photo.valid?.should == true @@ -35,7 +43,7 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 96 end - it 'should accept and convert a JPEG to right format and size' do + it 'should accept and convert a JPEG to right format and size' do data = load_file_fixture("parrot.jpg") profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user) profile_photo.valid?.should == true @@ -44,7 +52,7 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 96 end - it 'should accept a draft PNG and not resize it' do + it 'should accept a draft PNG and not resize it' do data = load_file_fixture("parrot.png") profile_photo = ProfilePhoto.new(:data => data, :draft => true) profile_photo.valid?.should == true @@ -53,6 +61,6 @@ describe ProfilePhoto, "when constructing a new photo" do profile_photo.image.rows.should == 289 end - + end 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..dc5a0d6eb 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 @@ -215,3 +220,16 @@ Spork.each_run do FactoryGirl.reload # This code will be run each time you run your specs. end + +def normalise_whitespace(s) + s = s.gsub(/\A\s+|\s+\Z/, "") + s = s.gsub(/\s+/, " ") + return s +end + +RSpec::Matchers.define :be_equal_modulo_whitespace_to do |expected| + match do |actual| + normalise_whitespace(actual) == normalise_whitespace(expected) + end +end + diff --git a/spec/views/request/list.html.erb_spec.rb b/spec/views/request/list.html.erb_spec.rb deleted file mode 100644 index 521d946bc..000000000 --- a/spec/views/request/list.html.erb_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) - -describe "request/list" do - - before do - assign :page, 1 - assign :per_page, 10 - end - - def make_mock_event - return mock_model(InfoRequestEvent, - :info_request => mock_model(InfoRequest, - :title => 'Title', - :url_title => 'title', - :display_status => 'awaiting_response', - :calculate_status => 'awaiting_response', - :public_body => mock_model(PublicBody, :name => 'Test Quango', :url_name => 'testquango'), - :user => mock_model(User, :name => 'Test User', :url_name => 'testuser'), - :is_external? => false - ), - :incoming_message => nil, :is_incoming_message? => false, - :outgoing_message => nil, :is_outgoing_message? => false, - :comment => nil, :is_comment? => false, - :event_type => 'sent', - :created_at => Time.now - 4.days, - :search_text_main => '' - ) - end - - it "should be successful" do - assign :list_results, [ make_mock_event, make_mock_event ] - assign :matches_estimated, 2 - assign :show_no_more_than, 100 - render - response.should have_selector("div.request_listing") - response.should_not have_selector("p", :content => "No requests of this sort yet") - end - - it "should cope with no results" do - assign :list_results, [ ] - assign :matches_estimated, 0 - assign :show_no_more_than, 0 - render - response.should have_selector("p", :content => "No requests of this sort yet") - response.should_not have_selector("div.request_listing") - end - -end - |