aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_public_body_change_requests_controller_spec.rb35
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb459
-rw-r--r--spec/controllers/api_controller_spec.rb24
-rw-r--r--spec/controllers/general_controller_spec.rb11
-rw-r--r--spec/controllers/public_body_change_requests_controller_spec.rb99
-rw-r--r--spec/controllers/request_controller_spec.rb86
-rw-r--r--spec/controllers/services_controller_spec.rb2
-rw-r--r--spec/factories.rb12
-rw-r--r--spec/fixtures/files/document-pdf.email110
-rw-r--r--spec/fixtures/files/email-folding-example-1.txt.expected7
-rw-r--r--spec/fixtures/files/email-folding-example-10.txt12
-rw-r--r--spec/fixtures/files/email-folding-example-10.txt.expected13
-rw-r--r--spec/fixtures/files/email-folding-example-11.txt45
-rw-r--r--spec/fixtures/files/email-folding-example-11.txt.expected8
-rw-r--r--spec/fixtures/files/email-folding-example-2.txt.expected1
-rw-r--r--spec/fixtures/files/email-folding-example-3.txt.expected7
-rw-r--r--spec/fixtures/files/email-folding-example-5.txt.expected12
-rw-r--r--spec/fixtures/files/email-folding-example-7.txt.expected3
-rw-r--r--spec/fixtures/files/email-folding-example-8.txt.expected3
-rw-r--r--spec/fixtures/files/email-folding-example-9.txt.expected6
-rw-r--r--spec/helpers/link_to_helper_spec.rb39
-rw-r--r--spec/lib/alaveteli_external_command.rb23
-rwxr-xr-xspec/lib/alaveteli_external_command_scripts/error.sh4
-rwxr-xr-xspec/lib/alaveteli_external_command_scripts/segfault.sh3
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb6
-rw-r--r--spec/mailers/request_mailer_spec.rb21
-rw-r--r--spec/models/incoming_message_spec.rb4
-rw-r--r--spec/models/info_request_spec.rb96
-rw-r--r--spec/models/profile_photo_spec.rb22
-rw-r--r--spec/models/public_body_change_request_spec.rb139
-rw-r--r--spec/models/public_body_spec.rb63
-rw-r--r--spec/spec_helper.rb18
-rw-r--r--spec/views/request/list.html.erb_spec.rb49
33 files changed, 1099 insertions, 343 deletions
diff --git a/spec/controllers/admin_public_body_change_requests_controller_spec.rb b/spec/controllers/admin_public_body_change_requests_controller_spec.rb
new file mode 100644
index 000000000..b478e851d
--- /dev/null
+++ b/spec/controllers/admin_public_body_change_requests_controller_spec.rb
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AdminPublicBodyChangeRequestsController, "editing a change request" do
+
+ it "should render the edit template" do
+ change_request = FactoryGirl.create(:add_body_request)
+ get :edit, :id => change_request.id
+ response.should render_template("edit")
+ end
+
+end
+
+describe AdminPublicBodyChangeRequestsController, 'updating a change request' do
+
+ before do
+ @change_request = FactoryGirl.create(:add_body_request)
+ post :update, { :id => @change_request.id,
+ :response => 'Thanks but no',
+ :subject => 'Your request' }
+ end
+
+ it 'should close the change request' do
+ PublicBodyChangeRequest.find(@change_request.id).is_open.should == false
+ end
+
+ it 'should send a response email to the user who requested the change' do
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should == 'Your request'
+ mail.to.should == [@change_request.get_user_email]
+ mail.body.should =~ /Thanks but no/
+ end
+end
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index fe5087d7c..095d23245 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe AdminPublicBodyController, "when administering public bodies" do
+describe AdminPublicBodyController, "when showing the index of public bodies" do
render_views
it "shows the index page" do
@@ -12,28 +12,255 @@ describe AdminPublicBodyController, "when administering public bodies" do
assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ]
end
+ it "searches for 'humpa' in another locale" do
+ get :index, {:query => "humpa", :locale => "es"}
+ assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ]
+ end
+
+end
+
+describe AdminPublicBodyController, "when showing a public body" do
+ render_views
+
it "shows a public body" do
get :show, :id => 2
end
- it "creates a new public body" do
+ it "sets a using_admin flag" do
+ get :show, :id => 2
+ session[:using_admin].should == 1
+ end
+
+ it "shows a public body in another locale" do
+ get :show, {:id => 2, :locale => "es" }
+ end
+
+end
+
+describe AdminPublicBodyController, 'when showing the form for a new public body' do
+
+ it 'should assign a new public body to the view' do
+ get :new
+ assigns[:public_body].should be_a(PublicBody)
+ end
+
+ context 'when passed a change request id as a param' do
+ render_views
+
+ it 'should populate the name, email address and last edit comment on the public body' do
+ change_request = FactoryGirl.create(:add_body_request)
+ get :new, :change_request_id => change_request.id
+ assigns[:public_body].name.should == change_request.public_body_name
+ assigns[:public_body].request_email.should == change_request.public_body_email
+ assigns[:public_body].last_edit_comment.should match('Notes: Please')
+ end
+
+ it 'should assign a default response text to the view' do
+ change_request = FactoryGirl.create(:add_body_request)
+ get :new, :change_request_id => change_request.id
+ assigns[:change_request_user_response].should match("Thanks for your suggestion to add A New Body")
+ end
+ end
+
+end
+
+describe AdminPublicBodyController, "when creating a public body" do
+ render_views
+
+ it "creates a new public body in one locale" do
+ n = PublicBody.count
+ post :create, { :public_body => { :name => "New Quango",
+ :short_name => "",
+ :tag_string => "blah",
+ :request_email => 'newquango@localhost',
+ :last_edit_comment => 'From test code' } }
+ PublicBody.count.should == n + 1
+
+ body = PublicBody.find_by_name("New Quango")
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
+ end
+
+ it "creates a new public body with multiple locales" do
n = PublicBody.count
- post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
+ post :create, {
+ :public_body => { :name => "New Quango",
+ :short_name => "",
+ :tag_string => "blah",
+ :request_email => 'newquango@localhost',
+ :last_edit_comment => 'From test code',
+ :translated_versions => [{ :locale => "es",
+ :name => "Mi Nuevo Quango",
+ :short_name => "",
+ :request_email => 'newquango@localhost' }]
+ }
+ }
PublicBody.count.should == n + 1
+
+ body = PublicBody.find_by_name("New Quango")
+ body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
+ I18n.with_locale(:en) do
+ body.name.should == "New Quango"
+ body.url_name.should == "new_quango"
+ body.first_letter.should == "N"
+ end
+ I18n.with_locale(:es) do
+ body.name.should == "Mi Nuevo Quango"
+ body.url_name.should == "mi_nuevo_quango"
+ body.first_letter.should == "M"
+ end
+
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
+ end
+
+ context 'when the body is being created as a result of a change request' do
+
+ before do
+ @change_request = FactoryGirl.create(:add_body_request)
+ post :create, { :public_body => { :name => "New Quango",
+ :short_name => "",
+ :tag_string => "blah",
+ :request_email => 'newquango@localhost',
+ :last_edit_comment => 'From test code' },
+ :change_request_id => @change_request.id,
+ :subject => 'Adding a new body',
+ :response => 'The URL will be [Authority URL will be inserted here]'}
+ end
+
+ it 'should send a response to the requesting user' do
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should == 'Adding a new body'
+ mail.to.should == [@change_request.get_user_email]
+ mail.body.should =~ /The URL will be http:\/\/test.host\/body\/new_quango/
+ end
+
+ it 'should mark the change request as closed' do
+ PublicBodyChangeRequest.find(@change_request.id).is_open.should be_false
+ end
+
end
+end
+
+describe AdminPublicBodyController, "when editing a public body" do
+ render_views
+
it "edits a public body" do
get :edit, :id => 2
end
+ it "edits a public body in another locale" do
+ get :edit, {:id => 3, :locale => :en}
+
+ # When editing a body, the controller returns all available translations
+ assigns[:public_body].find_translation_by_locale("es").name.should == 'El Department for Humpadinking'
+ assigns[:public_body].name.should == 'Department for Humpadinking'
+ response.should render_template('edit')
+ end
+
+ context 'when passed a change request id as a param' do
+ render_views
+
+ before do
+ @change_request = FactoryGirl.create(:update_body_request)
+ get :edit, :id => @change_request.public_body_id, :change_request_id => @change_request.id
+ end
+
+ it 'should populate the email address and last edit comment on the public body' do
+ change_request = FactoryGirl.create(:update_body_request)
+ get :edit, :id => change_request.public_body_id, :change_request_id => change_request.id
+ assigns[:public_body].request_email.should == @change_request.public_body_email
+ assigns[:public_body].last_edit_comment.should match('Notes: Please')
+ end
+
+ it 'should assign a default response text to the view' do
+ assigns[:change_request_user_response].should match("Thanks for your suggestion to update the email address")
+ end
+ end
+
+end
+
+describe AdminPublicBodyController, "when updating a public body" do
+ render_views
+
it "saves edits to a public body" do
public_bodies(:humpadink_public_body).name.should == "Department for Humpadinking"
- post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } }
+ post :update, { :id => 3, :public_body => { :name => "Renamed",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code' } }
request.flash[:notice].should include('successful')
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
pb.name.should == "Renamed"
end
+ it "saves edits to a public body in another locale" do
+ I18n.with_locale(:es) do
+ pb = PublicBody.find(id=3)
+ pb.name.should == "El Department for Humpadinking"
+ post :update, {
+ :id => 3,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code',
+ :translated_versions => {
+ 3 => {:locale => "es",
+ :name => "Renamed",
+ :short_name => "",
+ :request_email => 'edited@localhost'}
+ }
+ }
+ }
+ request.flash[:notice].should include('successful')
+ end
+
+ pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
+ I18n.with_locale(:es) do
+ pb.name.should == "Renamed"
+ end
+ I18n.with_locale(:en) do
+ pb.name.should == "Department for Humpadinking"
+ end
+ end
+
+ context 'when the body is being updated as a result of a change request' do
+
+ before do
+ @change_request = FactoryGirl.create(:update_body_request)
+ post :update, { :id => @change_request.public_body_id,
+ :public_body => { :name => "New Quango",
+ :short_name => "",
+ :request_email => 'newquango@localhost',
+ :last_edit_comment => 'From test code' },
+ :change_request_id => @change_request.id,
+ :subject => 'Body update',
+ :response => 'Done.'}
+ end
+
+ it 'should send a response to the requesting user' do
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should == 'Body update'
+ mail.to.should == [@change_request.get_user_email]
+ mail.body.should =~ /Done./
+ end
+
+ it 'should mark the change request as closed' do
+ PublicBodyChangeRequest.find(@change_request.id).is_open.should be_false
+ end
+
+ end
+end
+
+describe AdminPublicBodyController, "when destroying a public body" do
+ render_views
+
it "does not destroy a public body that has associated requests" do
id = public_bodies(:humpadink_public_body).id
n = PublicBody.count
@@ -49,10 +276,10 @@ describe AdminPublicBodyController, "when administering public bodies" do
PublicBody.count.should == n - 1
end
- it "sets a using_admin flag" do
- get :show, :id => 2
- session[:using_admin].should == 1
- end
+end
+
+describe AdminPublicBodyController, "when assigning public body tags" do
+ render_views
it "mass assigns tags" do
condition = "public_body_translations.locale = ?"
@@ -62,81 +289,81 @@ describe AdminPublicBodyController, "when administering public bodies" do
response.should redirect_to(:action=>'list')
PublicBody.find_by_tag("department").count.should == n
end
+end
- describe 'import_csv' do
+describe AdminPublicBodyController, "when importing a csv" do
+ render_views
- describe 'when handling a GET request' do
+ describe 'when handling a GET request' do
- it 'should get the page successfully' do
- get :import_csv
- response.should be_success
- end
+ it 'should get the page successfully' do
+ get :import_csv
+ response.should be_success
+ end
+ end
+
+ describe 'when handling a POST request' do
+
+ before do
+ PublicBody.stub!(:import_csv).and_return([[],[]])
+ @file_object = fixture_file_upload('/files/fake-authority-type.csv')
end
- describe 'when handling a POST request' do
+ it 'should handle a nil csv file param' do
+ post :import_csv, { :commit => 'Dry run' }
+ response.should be_success
+ end
- before do
- PublicBody.stub!(:import_csv).and_return([[],[]])
- @file_object = fixture_file_upload('/files/fake-authority-type.csv')
+ describe 'if there is a csv file param' do
+
+ it 'should try to get the contents and original name of a csv file param' do
+ @file_object.should_receive(:read).and_return('some contents')
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
end
- it 'should handle a nil csv file param' do
- post :import_csv, { :commit => 'Dry run' }
- response.should be_success
+ it 'should assign the original filename to the view' do
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
+ assigns[:original_csv_file].should == 'fake-authority-type.csv'
end
- describe 'if there is a csv file param' do
+ end
- it 'should try to get the contents and original name of a csv file param' do
- @file_object.should_receive(:read).and_return('some contents')
- post :import_csv, { :csv_file => @file_object,
- :commit => 'Dry run'}
- end
+ describe 'if there is no csv file param, but there are temporary_csv_file and
+ original_csv_file params' do
- it 'should assign the original filename to the view' do
- post :import_csv, { :csv_file => @file_object,
- :commit => 'Dry run'}
- assigns[:original_csv_file].should == 'fake-authority-type.csv'
- end
+ it 'should try and get the file contents from a temporary file whose name
+ is passed as a param' do
+ @controller.should_receive(:retrieve_csv_data).with('csv_upload-2046-12-31-394')
+ post :import_csv, { :temporary_csv_file => 'csv_upload-2046-12-31-394',
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ end
+ it 'should raise an error on an invalid temp file name' do
+ params = { :temporary_csv_file => 'bad_name',
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ expected_error = "Invalid filename in upload_csv: bad_name"
+ lambda{ post :import_csv, params }.should raise_error(expected_error)
end
- describe 'if there is no csv file param, but there are temporary_csv_file and
- original_csv_file params' do
-
- it 'should try and get the file contents from a temporary file whose name
- is passed as a param' do
- @controller.should_receive(:retrieve_csv_data).with('csv_upload-2046-12-31-394')
- post :import_csv, { :temporary_csv_file => 'csv_upload-2046-12-31-394',
- :original_csv_file => 'original_contents.txt',
- :commit => 'Dry run'}
- end
-
- it 'should raise an error on an invalid temp file name' do
- params = { :temporary_csv_file => 'bad_name',
- :original_csv_file => 'original_contents.txt',
- :commit => 'Dry run'}
- expected_error = "Invalid filename in upload_csv: bad_name"
- lambda{ post :import_csv, params }.should raise_error(expected_error)
- end
-
- it 'should raise an error if the temp file does not exist' do
- temp_name = "csv_upload-20461231-394"
- params = { :temporary_csv_file => temp_name,
- :original_csv_file => 'original_contents.txt',
- :commit => 'Dry run'}
- expected_error = "Missing file in upload_csv: csv_upload-20461231-394"
- lambda{ post :import_csv, params }.should raise_error(expected_error)
- end
-
- it 'should assign the temporary filename to the view' do
- post :import_csv, { :csv_file => @file_object,
- :commit => 'Dry run'}
- temporary_filename = assigns[:temporary_csv_file]
- temporary_filename.should match(/csv_upload-#{Time.now.strftime("%Y%m%d")}-\d{1,5}/)
- end
+ it 'should raise an error if the temp file does not exist' do
+ temp_name = "csv_upload-20461231-394"
+ params = { :temporary_csv_file => temp_name,
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ expected_error = "Missing file in upload_csv: csv_upload-20461231-394"
+ lambda{ post :import_csv, params }.should raise_error(expected_error)
+ end
+ it 'should assign the temporary filename to the view' do
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
+ temporary_filename = assigns[:temporary_csv_file]
+ temporary_filename.should match(/csv_upload-#{Time.now.strftime("%Y%m%d")}-\d{1,5}/)
end
end
@@ -266,103 +493,3 @@ describe AdminPublicBodyController, "when administering public bodies and paying
end
end
-describe AdminPublicBodyController, "when administering public bodies with i18n" do
- render_views
-
- it "shows the index page" do
- get :index
- end
-
- it "searches for 'humpa'" do
- get :index, {:query => "humpa", :locale => "es"}
- assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ]
- end
-
- it "shows a public body" do
- get :show, {:id => 2, :locale => "es" }
- end
-
- it "edits a public body" do
- get :edit, {:id => 3, :locale => :en}
-
- # When editing a body, the controller returns all available translations
- assigns[:public_body].find_translation_by_locale("es").name.should == 'El Department for Humpadinking'
- assigns[:public_body].name.should == 'Department for Humpadinking'
- response.should render_template('edit')
- end
-
- it "saves edits to a public body" do
- I18n.with_locale(:es) do
- pb = PublicBody.find(id=3)
- pb.name.should == "El Department for Humpadinking"
- post :update, {
- :id => 3,
- :public_body => {
- :name => "Department for Humpadinking",
- :short_name => "",
- :tag_string => "some tags",
- :request_email => 'edited@localhost',
- :last_edit_comment => 'From test code',
- :translated_versions => {
- 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'}
- }
- }
- }
- request.flash[:notice].should include('successful')
- end
-
- pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
- I18n.with_locale(:es) do
- pb.name.should == "Renamed"
- end
- I18n.with_locale(:en) do
- pb.name.should == "Department for Humpadinking"
- end
- end
-
- it "destroy a public body" do
- n = PublicBody.count
- post :destroy, { :id => public_bodies(:forlorn_public_body).id }
- PublicBody.count.should == n - 1
- end
-
-end
-
-describe AdminPublicBodyController, "when creating public bodies with i18n" do
- render_views
-
- it "creates a new public body in one locale" do
- n = PublicBody.count
- post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
- PublicBody.count.should == n + 1
-
- body = PublicBody.find_by_name("New Quango")
- response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
- end
-
- it "creates a new public body with multiple locales" do
- n = PublicBody.count
- post :create, {
- :public_body => {
- :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code',
- :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }]
- }
- }
- PublicBody.count.should == n + 1
-
- body = PublicBody.find_by_name("New Quango")
- body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
- I18n.with_locale(:en) do
- body.name.should == "New Quango"
- body.url_name.should == "new_quango"
- body.first_letter.should == "N"
- end
- I18n.with_locale(:es) do
- body.name.should == "Mi Nuevo Quango"
- body.url_name.should == "mi_nuevo_quango"
- body.first_letter.should == "M"
- end
-
- response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
- end
-end
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 8e9d17fbe..6b02bd5b4 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
@@ -282,6 +270,18 @@ describe ApiController, "when using the API" do
# check, which does not really test anything at all.
end
+ it 'should show information about an external request' do
+ info_request = info_requests(:external_request)
+ get :show_request,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :id => info_request.id
+
+ response.should be_success
+ assigns[:request].id.should == info_request.id
+ r = ActiveSupport::JSON.decode(response.body)
+ r["title"].should == info_request.title
+ end
+
it "should show an Atom feed of new request events" do
get :body_request_events,
:id => public_bodies(:geraldine_public_body).id,
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index e67cc9492..7590a5b42 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -42,6 +42,17 @@ describe GeneralController, 'when getting the blog feed' do
assigns[:blog_items].count.should == 1
end
+ context 'if no feed is configured' do
+
+ before do
+ AlaveteliConfiguration.stub!(:blog_feed).and_return('')
+ end
+
+ it 'should raise an ActiveRecord::RecordNotFound error' do
+ lambda{ get :blog }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
end
describe GeneralController, "when showing the frontpage" do
diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb
new file mode 100644
index 000000000..7b878b893
--- /dev/null
+++ b/spec/controllers/public_body_change_requests_controller_spec.rb
@@ -0,0 +1,99 @@
+# -*- coding: utf-8 -*-
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe PublicBodyChangeRequestsController, "making a new change request" do
+
+ it "should show the form" do
+ get :new
+ response.should render_template("new")
+ end
+
+end
+
+describe PublicBodyChangeRequestsController, "creating a change request" do
+
+ context 'when handling a request for a new authority' do
+
+ before do
+ @email = "test@example.com"
+ name = "Test User"
+ @change_request_params = {:user_email => @email,
+ :user_name => name,
+ :public_body_name => 'New Body',
+ :public_body_email => 'new_body@example.com',
+ :notes => 'Please',
+ :source => 'http://www.example.com'}
+ end
+
+ it "should send an email to the site contact address" do
+ post :create, {:public_body_change_request => @change_request_params}
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should =~ /Add authority - New Body/
+ mail.from.should include(@email)
+ mail.to.should include('postmaster@localhost')
+ mail.body.should include('new_body@example.com')
+ mail.body.should include('New Body')
+ mail.body.should include("Please")
+ mail.body.should include('http://test.host/admin/body/new?change_request_id=')
+ mail.body.should include('http://test.host/admin/change_request/edit/')
+ end
+
+ it 'should show a notice' do
+ post :create, {:public_body_change_request => @change_request_params}
+ expected_text = "Your request to add an authority has been sent. Thank you for getting in touch! We'll get back to you soon."
+ flash[:notice].should == expected_text
+ end
+
+ it 'should redirect to the frontpage' do
+ post :create, {:public_body_change_request => @change_request_params}
+ response.should redirect_to frontpage_url
+ end
+
+ end
+
+ context 'when handling a request for an update to an existing authority' do
+
+ before do
+ @email = "test@example.com"
+ name = "Test User"
+ @public_body = FactoryGirl.create(:public_body)
+ @change_request_params = {:user_email => @email,
+ :user_name => name,
+ :public_body_id => @public_body.id,
+ :public_body_email => 'new_body@example.com',
+ :notes => 'Please',
+ :source => 'http://www.example.com'}
+ end
+
+ it 'should send an email to the site contact address' do
+ post :create, {:public_body_change_request => @change_request_params}
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should =~ /Update email address - #{@public_body.name}/
+ mail.from.should include(@email)
+ mail.to.should include('postmaster@localhost')
+ mail.body.should include('new_body@example.com')
+ mail.body.should include(@public_body.name)
+ mail.body.should include("Please")
+ mail.body.should include("http://test.host/admin/body/edit/#{@public_body.id}?change_request_id=")
+ mail.body.should include('http://test.host/admin/change_request/edit/')
+ end
+
+ it 'should show a notice' do
+ post :create, {:public_body_change_request => @change_request_params}
+ expected_text = "Your request to update the address for #{@public_body.name} has been sent. Thank you for getting in touch! We'll get back to you soon."
+ flash[:notice].should == expected_text
+ end
+
+ it 'should redirect to the frontpage' do
+ post :create, {:public_body_change_request => @change_request_params}
+ response.should redirect_to frontpage_url
+ end
+
+ end
+
+
+end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c8d2dfb34..1e7df4536 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/factories.rb b/spec/factories.rb
index 3ea943030..8efc53033 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -145,6 +145,18 @@ FactoryGirl.define do
track_query 'Example Query'
end
+ factory :public_body_change_request do
+ user
+ source_url 'http://www.example.com'
+ notes 'Please'
+ public_body_email 'new@example.com'
+ factory :add_body_request do
+ public_body_name 'A New Body'
+ end
+ factory :update_body_request do
+ public_body
+ end
+ end
factory :info_request_batch do
title "Example title"
user
diff --git a/spec/fixtures/files/document-pdf.email b/spec/fixtures/files/document-pdf.email
new file mode 100644
index 000000000..f4fc6f0fe
--- /dev/null
+++ b/spec/fixtures/files/document-pdf.email
@@ -0,0 +1,110 @@
+From authority@example.org Tue Dec 3 11:13:02 2013
+Return-path: <authority@example.org>
+Envelope-to: requester@example.org
+Delivery-date: Tue, 03 Dec 2013 11:13:00 +0000
+From: Test Authority <authority@example.org>
+To: requester@example.org
+Subject: testing a PDF attachment with the wrong content-type
+Date: Tue, 03 Dec 2013 11:12:45 +0000
+Message-ID: <87li09xuasdfasdfpoija@blahblah>
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="=-=-="
+
+--=-=-=
+Content-Type: text/plain
+
+Here's a PDF attachement which has a document/pdf content-type,
+when it really should be application/pdf.
+
+
+--=-=-=
+Content-Type: application/pdf
+Content-Disposition: attachment; filename=tiny-example.pdf
+Content-Transfer-Encoding: base64
+Content-Description: a very small example PDF
+
+JVBERi0xLjUKJbXtrvsKMyAwIG9iago8PCAvTGVuZ3RoIDQgMCBSCiAgIC9GaWx0ZXIgL0ZsYXRl
+RGVjb2RlCj4+CnN0cmVhbQp4nCvkMlAAwaJ0Bf1EA4X0Yi6nEC5DA1M9IwNLYzNjsBwS18hIz9TI
+0tBSwdzIQs/Y3MLAzEQhJJdLP03XQBeoUCEkjStawyM1JydfUTM2xIvLNYQrkAsAJG8VmQplbmRz
+dHJlYW0KZW5kb2JqCjQgMCBvYmoKICAgOTIKZW5kb2JqCjIgMCBvYmoKPDwKICAgL0V4dEdTdGF0
+ZSA8PAogICAgICAvYTAgPDwgL0NBIDEgL2NhIDEgPj4KICAgPj4KICAgL0ZvbnQgPDwKICAgICAg
+L2YtMC0wIDUgMCBSCiAgID4+Cj4+CmVuZG9iago2IDAgb2JqCjw8IC9UeXBlIC9QYWdlCiAgIC9Q
+YXJlbnQgMSAwIFIKICAgL01lZGlhQm94IFsgMCAwIDU5NS4yNzU1NzQgODQxLjg4OTc3MSBdCiAg
+IC9Db250ZW50cyAzIDAgUgogICAvR3JvdXAgPDwKICAgICAgL1R5cGUgL0dyb3VwCiAgICAgIC9T
+IC9UcmFuc3BhcmVuY3kKICAgICAgL0kgdHJ1ZQogICAgICAvQ1MgL0RldmljZVJHQgogICA+Pgog
+ICAvUmVzb3VyY2VzIDIgMCBSCj4+CmVuZG9iago3IDAgb2JqCjw8IC9MZW5ndGggOCAwIFIKICAg
+L0ZpbHRlciAvRmxhdGVEZWNvZGUKICAgL0xlbmd0aDEgMzcxNgo+PgpzdHJlYW0KeJzlVnt0lMUV
+v/P9vtndZB/5drMbiUlww7ookJCQECCAzYJBBSrlETXYxgayxIjQJAQVTOOCFAREgwKLAtIUkSpE
+mlIkG2OtVN4xrZXH8Y0gFGkjRouoa5j0btCe0/boOW3/6On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DAgUgo+PgpzdGFydHhyZWYKNDMxMAolJUVP
+Rgo=
+--=-=-=--
+
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/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index bc027eaec..49a65dade 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -409,6 +409,12 @@ describe 'when getting attachment attributes' do
attributes[1][:body].length.should == 7769
end
+ it 'should treat a document/pdf attachment as application/pdf' do
+ mail = get_fixture_mail('document-pdf.email')
+ attributes = MailHandler.get_attachment_attributes(mail)
+ attributes[1][:content_type].should == "application/pdf"
+ end
+
it 'should produce a consistent set of url_part_numbers, content_types, within_rfc822_subjects
and filenames from an example mail with lots of attachments' do
mail = get_fixture_mail('many-attachments-date-header.email')
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 4e0765921..516d13127 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -332,6 +332,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
+describe RequestMailer, 'when generating a fake response for an upload' do
+
+ before do
+ @foi_officer = mock_model(User, :name_and_email => "FOI officer's name and email")
+ @request_user = mock_model(User)
+ @public_body = mock_model(PublicBody, :name => 'Test public body')
+ @info_request = mock_model(InfoRequest, :user => @request_user,
+ :email_subject_followup => 'Re: Freedom of Information - Test request',
+ :incoming_name_and_email => 'Someone <someone@example.org>')
+ end
+
+ it 'should should generate a "fake response" email with a reasonable subject line' do
+ fake_email = RequestMailer.fake_response(@info_request,
+ @foi_officer,
+ "The body of the email...",
+ "blah.txt",
+ "The content of blah.txt")
+ fake_email.subject.should == "Re: Freedom of Information - Test request"
+ end
+
+end
describe RequestMailer, 'when sending a new response email' do
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 0c6457b1a..9766f928f 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1196,4 +1196,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_change_request_spec.rb b/spec/models/public_body_change_request_spec.rb
new file mode 100644
index 000000000..0c4cea67b
--- /dev/null
+++ b/spec/models/public_body_change_request_spec.rb
@@ -0,0 +1,139 @@
+# == Schema Information
+#
+# Table name: public_body_change_requests
+#
+# id :integer not null, primary key
+# user_email :string(255)
+# user_name :string(255)
+# user_id :integer
+# public_body_name :text
+# public_body_id :integer
+# public_body_email :string(255)
+# source_url :text
+# notes :text
+# is_open :boolean default(TRUE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe PublicBodyChangeRequest, 'when validating' do
+
+ it 'should not be valid without a public body name' do
+ change_request = PublicBodyChangeRequest.new()
+ change_request.valid?.should be_false
+ change_request.errors[:public_body_name].should == ['Please enter the name of the authority']
+ end
+
+ it 'should not be valid without a user name if there is no user' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'New Body')
+ change_request.valid?.should be_false
+ change_request.errors[:user_name].should == ['Please enter your name']
+ end
+
+ it 'should not be valid without a user email address if there is no user' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'New Body')
+ change_request.valid?.should be_false
+ change_request.errors[:user_email].should == ['Please enter your email address']
+ end
+
+ it 'should be valid with a user and no name or email address' do
+ user = FactoryGirl.build(:user)
+ change_request = PublicBodyChangeRequest.new(:user => user,
+ :public_body_name => 'New Body')
+ change_request.valid?.should be_true
+ end
+
+ it 'should validate the format of a user email address entered' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'New Body',
+ :user_email => '@example.com')
+ change_request.valid?.should be_false
+ change_request.errors[:user_email].should == ["Your email doesn't look like a valid address"]
+ end
+
+ it 'should validate the format of a public body email address entered' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'New Body',
+ :public_body_email => '@example.com')
+ change_request.valid?.should be_false
+ change_request.errors[:public_body_email].should == ["The authority email doesn't look like a valid address"]
+ end
+
+end
+
+describe PublicBodyChangeRequest, 'get_user_name' do
+
+ it 'should return the user_name field if there is no user association' do
+ change_request = PublicBodyChangeRequest.new(:user_name => 'Test User')
+ change_request.get_user_name.should == 'Test User'
+ end
+
+ it 'should return the name of the associated user if there is one' do
+ user = FactoryGirl.build(:user)
+ change_request = PublicBodyChangeRequest.new(:user => user)
+ change_request.get_user_name.should == user.name
+ end
+
+end
+
+
+describe PublicBodyChangeRequest, 'get_user_email' do
+
+ it 'should return the user_email field if there is no user association' do
+ change_request = PublicBodyChangeRequest.new(:user_email => 'user@example.com')
+ change_request.get_user_email.should == 'user@example.com'
+ end
+
+ it 'should return the email of the associated user if there is one' do
+ user = FactoryGirl.build(:user)
+ change_request = PublicBodyChangeRequest.new(:user => user)
+ change_request.get_user_email.should == user.email
+ end
+
+end
+
+
+describe PublicBodyChangeRequest, 'get_public_body_name' do
+
+ it 'should return the public_body_name field if there is no public body association' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'Test Authority')
+ change_request.get_public_body_name.should == 'Test Authority'
+ end
+
+ it 'should return the name of the associated public body if there is one' do
+ public_body = FactoryGirl.build(:public_body)
+ change_request = PublicBodyChangeRequest.new(:public_body => public_body)
+ change_request.get_public_body_name.should == public_body.name
+ end
+
+end
+
+describe PublicBodyChangeRequest, 'when creating a comment for the associated public body' do
+
+ it 'should include requesting user, source_url and notes' do
+ change_request = PublicBodyChangeRequest.new(:user_name => 'Test User',
+ :user_email => 'test@example.com',
+ :source_url => 'http://www.example.com',
+ :notes => 'Some notes')
+ expected = "Requested by: Test User (test@example.com)\nSource URL: http://www.example.com\nNotes: Some notes"
+ change_request.comment_for_public_body.should == expected
+ end
+
+end
+
+describe PublicBodyChangeRequest, 'when creating a default subject for a response email' do
+
+ it 'should create an appropriate subject for a request to add a body' do
+ change_request = PublicBodyChangeRequest.new(:public_body_name => 'Test Body')
+ change_request.default_response_subject.should == 'Your request to add Test Body to Alaveteli'
+ end
+
+ it 'should create an appropriate subject for a request to update an email address' do
+ public_body = FactoryGirl.build(:public_body)
+ change_request = PublicBodyChangeRequest.new(:public_body => public_body)
+ change_request.default_response_subject.should == "Your request to update #{public_body.name} on Alaveteli"
+
+ end
+
+end
+
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
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
-