From ad8772fde14c57f05e2585c8c02034e053a86319 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 3 Dec 2013 09:43:32 +0000 Subject: Add new_batch action Give it basic access control, and add some conditionals to the 'new' template around bits that use @info_request.public_body so that they render something different if @batch is assigned. --- spec/controllers/request_controller_spec.rb | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index d29552b15..2e928eb3b 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2509,6 +2509,72 @@ describe RequestController, "when caching fragments" do end +describe RequestController, "#new_batch", :focus => true do + + context "when batch requests is enabled" do + + before do + AlaveteliConfiguration.stub!(:allow_batch_requests).and_return(true) + end + + context "when the current user can make batch requests" do + + before do + @user = FactoryGirl.create(:user, :can_make_batch_requests => true) + end + + it 'should be successful' do + get :new_batch, {}, {:user_id => @user.id} + response.should be_success + end + + it 'should render the "new" template' do + get :new_batch, {}, {:user_id => @user.id} + response.should render_template('request/new') + end + + end + + context "when the current user can't make batch requests" do + + render_views + + before do + @user = FactoryGirl.create(:user) + end + + it 'should return a 403 with an appropriate message' do + get :new_batch, {}, {:user_id => @user.id} + response.code.should == '403' + response.body.should match("Users cannot usually make batch requests to multiple authorities at once") + end + + end + + context 'when there is no logged-in user' do + + it 'should return a redirect to the login page' do + get :new_batch + post_redirect = PostRedirect.get_last_post_redirect + response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) + end + end + + + end + + context "when batch requests is not enabled" do + + it 'should return a 404' do + Rails.application.config.stub!(:consider_all_requests_local).and_return(false) + get :new_batch + response.code.should == '404' + end + + end + +end + describe RequestController, "#select_authorities" do context "when batch requests is enabled" do -- cgit v1.2.3