aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/request_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r--spec/controllers/request_controller_spec.rb132
1 files changed, 126 insertions, 6 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 856b4c804..950682ca7 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -300,30 +300,68 @@ describe RequestController, "when viewing an individual response for reply/follo
end
end
-describe RequestController, "when classifying an individual response" do
- integrate_views
+describe RequestController, "when classifying an information request" do
+
fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
+ def post_rejected_status
+ post :describe_state, :incoming_message => { :described_state => "rejected" },
+ :id => info_requests(:fancy_dog_request).id,
+ :last_info_request_event_id => info_request_events(:silly_comment_event).id,
+ :submitted_describe_state => 1
+ end
+
it "should require login" do
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1
+ post_rejected_status
post_redirect = PostRedirect.get_last_post_redirect
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
- it "should not classify response if logged in as wrong user" do
+ it "should not classify the reqest if logged in as the wrong user" do
session[:user_id] = users(:silly_name_user).id
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1
+ post_rejected_status
response.should render_template('user/wrong_user')
end
+
+ describe 'when logged in as an admin user' do
+
+ before do
+ @admin_user = users(:admin_user)
+ session[:user_id] = @admin_user.id
+ @dog_request = info_requests(:fancy_dog_request)
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ end
+
+ it 'should update the status of the request if the request requires admin' do
+ @dog_request.stub!(:calculate_status).and_return('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected')
+ post_rejected_status
+ end
+
+ it 'should show the message "The request status has been updated"' do
+ post_rejected_status
+ flash[:notice].should == '<p>The request status has been updated</p>'
+ end
+
+ it 'should redirect to the page that shows the request' do
+ post_rejected_status
+ response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
+ end
+ end
+
it "should successfully classify response if logged in as user controlling request" do
info_requests(:fancy_dog_request).awaiting_description.should == true
session[:user_id] = users(:bob_smith_user).id
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:silly_comment_event).id, :submitted_describe_state => 1
+ post :describe_state, :incoming_message => { :described_state => "rejected" },
+ :id => info_requests(:fancy_dog_request).id,
+ :last_info_request_event_id => info_request_events(:silly_comment_event).id,
+ :submitted_describe_state => 1
response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => info_requests(:fancy_dog_request).url_title)
info_requests(:fancy_dog_request).reload
info_requests(:fancy_dog_request).awaiting_description.should == false
info_requests(:fancy_dog_request).described_state.should == 'rejected'
+ info_requests(:fancy_dog_request).get_last_response_event.should == info_request_events(:useless_incoming_message_event)
info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'rejected'
end
@@ -344,6 +382,88 @@ describe RequestController, "when classifying an individual response" do
mail.body.should =~ /as needing admin/
mail.from_addrs.to_s.should == users(:bob_smith_user).name_and_email
end
+
+ describe 'when redirecting after a successful status update by the request owner' do
+
+ before do
+ @request_owner = users(:bob_smith_user)
+ session[:user_id] = @request_owner.id
+ @dog_request = info_requests(:fancy_dog_request)
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ end
+
+ def post_status(status)
+ post :describe_state, :incoming_message => { :described_state => status },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description,
+ :submitted_describe_state => 1
+ end
+
+ def expect_redirect(status, redirect_path)
+ post_status(status)
+ response.should redirect_to("http://test.host/#{redirect_path}")
+ end
+
+ it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1)
+ expect_redirect("waiting_response", "request/#{@dog_request.url_title}")
+ flash[:notice].should match(/should get a response/)
+ end
+
+ it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
+ expect_redirect('waiting_response', "request/#{@dog_request.url_title}")
+ flash[:notice].should match(/should have got a response/)
+ end
+
+ it 'should redirect to the "request url" when status is updated to "not held"' do
+ expect_redirect('not_held', "request/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "request url" when status is updated to "successful"' do
+ expect_redirect('successful', "request/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "unhappy url" when status is updated to "rejected"' do
+ expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "unhappy url" when status is updated to "partially successful"' do
+ expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "response url" when status is updated to "waiting clarification" and there is a last response' do
+ incoming_message = mock_model(IncomingMessage)
+ @dog_request.stub!(:get_last_response).and_return(incoming_message)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}")
+ end
+
+ it 'should redirect to the "response no followup url" when status is updated to "waiting clarification" and there are no events needing description' do
+ @dog_request.stub!(:get_last_response).and_return(nil)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response")
+ end
+
+ it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do
+ expect_redirect('gone_postal', "request/#{@dog_request.id}/response/1?gone_postal=1")
+ end
+
+ it 'should redirect to the "request url" when status is updated to "internal review"' do
+ expect_redirect('internal_review', "request/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "help general url" when status is updated to "requires admin"' do
+ expect_redirect('requires_admin', "help/contact")
+ end
+
+ it 'should redirect to the "help general url" when status is updated to "error message"' do
+ expect_redirect('error_message', "help/contact")
+ end
+
+ it 'should redirect to the "request url" when status is updated to "user_withdrawn"' do
+ expect_redirect('user_withdrawn', "request/#{@dog_request.url_title}")
+ end
+
+ end
end
describe RequestController, "when sending a followup message" do