aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb35
-rw-r--r--spec/controllers/request_controller_spec.rb50
2 files changed, 62 insertions, 23 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index ccf824e75..b9be333c8 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -232,14 +232,35 @@ class RequestController < ApplicationController
:body => params[:outgoing_message][:body],
:user => authenticated_user)
@public_bodies = PublicBody.where({:id => params[:public_body_ids]}).all
+ unrequestable = []
@public_bodies.each do |public_body|
- info_request = InfoRequest.create_from_attributes(params[:info_request],
- params[:outgoing_message],
- authenticated_user)
- info_request.public_body_id = public_body.id
- info_request.info_request_batch = @info_request_batch
- info_request.save!
- info_request.outgoing_messages.first.send_message
+ if public_body.is_requestable?
+ info_request = InfoRequest.create_from_attributes(params[:info_request],
+ params[:outgoing_message],
+ authenticated_user)
+ info_request.public_body_id = public_body.id
+ info_request.info_request_batch = @info_request_batch
+ info_request.save!
+ info_request.outgoing_messages.first.send_message
+ else
+ unrequestable << public_body.name
+ end
+ end
+
+ flash[:notice] = _("<p>Your {{law_used_full}} requests have been <strong>sent</strong>!</p>
+ <p><strong>We will email you</strong> when there is a response to any of them, or after {{late_number_of_days}} working days if the authorities still haven't
+ replied by then.</p>
+ <p>If you write about these requests (for example in a forum or a blog) please link to this page.</p>",
+ :law_used_full=>@info_request.law_used_full,
+ :late_number_of_days => AlaveteliConfiguration::reply_late_after_days)
+ if ! unrequestable.empty?
+ error_messages = []
+ error_messages << _('Unfortunately, we do not have a working address for {{public_body_names}}.',
+ :public_body_names => unrequestable.join(","))
+ error_messages << _('You may be able to find one on their website, or by phoning them up and asking. If you manage
+ to find one, then please <a href="{{help_url}}">send it to us</a>.',
+ :help_url => help_contact_path)
+ flash[:error] = error_messages.map{ |message| "<p>#{message}</p>"}.join(" ").html_safe
end
redirect_to info_request_batch_path(@info_request_batch)
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c61e0c780..be5a97776 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -2565,24 +2565,42 @@ describe RequestController, "#new_batch", :focus => true do
response.should render_template('new')
end
- it 'should create an info request batch and redirect to the new batch on success' do
- params = @default_post_params.merge(:preview => 0)
- post :new_batch, params, { :user_id => @user.id }
- new_info_request_batch = assigns[:info_request_batch]
- new_info_request_batch.should_not be_nil
- response.should redirect_to(info_request_batch_path(new_info_request_batch))
- end
+ context "on success" do
- it 'should prevent double submission of a batch request' do
- params = @default_post_params.merge(:preview => 0)
- post :new_batch, params, { :user_id => @user.id }
- new_info_request_batch = assigns[:info_request_batch]
- response.should redirect_to(info_request_batch_path(new_info_request_batch))
- post :new_batch, params, { :user_id => @user.id }
- response.should render_template('new')
- assigns[:existing_batch].should_not be_nil
- end
+ def make_request
+ @params = @default_post_params.merge(:preview => 0)
+ post :new_batch, @params, { :user_id => @user.id }
+ end
+
+ it 'should create an info request batch and redirect to the new batch on success' do
+ make_request
+ new_info_request_batch = assigns[:info_request_batch]
+ new_info_request_batch.should_not be_nil
+ response.should redirect_to(info_request_batch_path(new_info_request_batch))
+ end
+ it 'should prevent double submission of a batch request' do
+ make_request
+ post :new_batch, @params, { :user_id => @user.id }
+ response.should render_template('new')
+ assigns[:existing_batch].should_not be_nil
+ end
+
+ it 'should display a success notice' do
+ make_request
+ notice_text = "<p>Your Freedom of Information requests have been <strong>sent</strong>!</p>"
+ flash[:notice].should match notice_text
+ end
+
+ it 'should display notes about any bodies that could not be included' do
+ @other_public_body.request_email = ''
+ @other_public_body.save!
+ make_request
+ error_text = "Unfortunately, we do not have a working address for #{@other_public_body.name}."
+ flash[:error].should match error_text
+ end
+
+ end
context "when the user is banned" do