diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 132 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 12 | ||||
-rw-r--r-- | spec/views/request/_after_actions.rhtml_spec.rb | 61 | ||||
-rw-r--r-- | spec/views/request/_describe_state.rhtml_spec.rb | 49 | ||||
-rw-r--r-- | spec/views/request/show.rhtml_spec.rb | 111 |
5 files changed, 351 insertions, 14 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5b7b08a7d..dc14feff9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -103,24 +103,24 @@ describe User, "when checking abilities" do end -describe User, 'when asked if a user has the ability to edit "requires admin" requests' do +describe User, 'when asked if a user owns every request' do before do @mock_user = mock_model(User) end it 'should return false if no user is passed' do - User.requires_admin_power?(nil).should be_false + User.owns_every_request?(nil).should be_false end it 'should return true if the user has "requires admin" power' do - @mock_user.stub!(:requires_admin_power?).and_return true - User.requires_admin_power?(@mock_user).should be_true + @mock_user.stub!(:owns_every_request?).and_return true + User.owns_every_request?(@mock_user).should be_true end it 'should return false if the user does not have "requires admin" power' do - @mock_user.stub!(:requires_admin_power?).and_return false - User.requires_admin_power?(@mock_user).should be_false + @mock_user.stub!(:owns_every_request?).and_return false + User.owns_every_request?(@mock_user).should be_false end end diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb new file mode 100644 index 000000000..7893d2e49 --- /dev/null +++ b/spec/views/request/_after_actions.rhtml_spec.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'when displaying actions that can be taken with regard to a request' do + + before do + @mock_body = mock_model(PublicBody, :name => 'test public body', + :url_name => 'test_public_body') + @mock_user = mock_model(User, :name => 'test user', + :url_name => 'test_user') + @mock_request = mock_model(InfoRequest, :title => 'test request', + :user => @mock_user, + :public_body => @mock_body, + :url_title => 'test_request') + assigns[:info_request] = @mock_request + end + + def do_render + render :partial => 'request/after_actions' + end + + def expect_owner_link(text) + do_render + response.should have_tag('div#owner_actions') do + with_tag('a', :text => text) + end + end + + it 'should display a link for the request owner to update the status of the request' do + expect_owner_link('Update the status of this request') + end + + it 'should display a link for the request owner to request a review' do + expect_owner_link('Request an internal review') + end + + describe 'when there is no last response' do + + before do + assigns[:last_response] = nil + end + + it 'should display a link for the request owner to send a follow up' do + expect_owner_link('Send follow up to test public body') + end + + end + + describe 'when there is a last response' do + + before do + assigns[:last_response] = mock_model(IncomingMessage, + :valid_to_reply_to? => false) + end + + it 'should display a link for the request owner to reply to the last response' do + expect_owner_link('Reply to test public body') + end + + end + +end
\ No newline at end of file diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.rhtml_spec.rb index 306f70060..ebb1d5a91 100644 --- a/spec/views/request/_describe_state.rhtml_spec.rb +++ b/spec/views/request/_describe_state.rhtml_spec.rb @@ -6,6 +6,11 @@ describe 'when showing the form for describing the state of a request' do do_render response.should have_tag("input[type=radio][value=#{value}]") end + + def expect_no_radio_button(value) + do_render + response.should_not have_tag("input[type=radio][value=#{value}]") + end def do_render render :partial => 'request/describe_state', :locals => {:id_suffix => '1'} @@ -17,17 +22,22 @@ describe 'when showing the form for describing the state of a request' do assigns[:info_request] = @mock_request end - describe 'if showing the form to a regular user' do + describe 'if the user is a regular user' do before do assigns[:is_owning_user] = false end + it 'should not show the form' do + do_render + response.should_not have_tag('form') + end + it 'should give a link to login' do do_render response.should have_tag('a', :text => 'sign in') end - + end describe 'if showing the form to the user owning the request' do @@ -49,7 +59,31 @@ describe 'when showing the form for describing the state of a request' do it 'should show a radio button to set the status to "waiting clarification"' do expect_radio_button('waiting_clarification') end + + it 'should not show a radio button to set the status to "internal_review"' do + expect_no_radio_button('internal_review') + end + + end + describe 'when the user has asked to update the status of the request' do + + before do + assigns[:update_status] = true + end + + it 'should show a radio button to set the status to "internal_review"' do + expect_radio_button('internal_review') + end + + it 'should show a radio button to set the status to "requires_admin"' do + expect_radio_button('requires_admin') + end + + it 'should show a radio button to set the status to "user_withdrawn"' do + expect_radio_button('user_withdrawn') + end + end describe 'when the request is in internal review' do @@ -68,6 +102,9 @@ describe 'when showing the form for describing the state of a request' do end end + + describe 'when request is awaiting a description and the user has not asked to update the status' do + end it 'should show a radio button to set the status to "gone postal"' do expect_radio_button('gone_postal') @@ -93,5 +130,13 @@ describe 'when showing the form for describing the state of a request' do expect_radio_button('error_message') end + it 'should not show a radio button to set the status to "requires_admin"' do + expect_no_radio_button('requires_admin') + end + + it 'should not show a radio button to set the status to "user_withdrawn"' do + expect_no_radio_button('user_withdrawn') + end + end end
\ No newline at end of file diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb new file mode 100644 index 000000000..f4222e354 --- /dev/null +++ b/spec/views/request/show.rhtml_spec.rb @@ -0,0 +1,111 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'when viewing an information request' do + + before do + @mock_body = mock_model(PublicBody, :name => 'test body', + :url_name => 'test_body') + @mock_user = mock_model(User, :name => 'test user', + :url_name => 'test_user') + @mock_request = mock_model(InfoRequest, :title => 'test request', + :awaiting_description => false, + :law_used_with_a => '', + :public_body => @mock_body, + :user => @mock_user, + :calculate_status => 'waiting_response', + :date_response_required_by => Date.today) + end + + def do_render + assigns[:info_request] = @mock_request + assigns[:info_request_events] = [] + assigns[:status] = @mock_request.calculate_status + template.stub!(:render) + render 'request/show' + end + + it 'should show the sidebar' do + template.should_receive(:render).with(:partial => 'sidebar') + do_render + end + + it 'should show the actions people can take' do + template.should_receive(:render).with(:partial => 'after_actions') + do_render + end + + describe 'when a status update has been requested' do + + before do + assigns[:update_status] = true + end + + it 'should show the first form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_1") + end + + end + + describe 'when it is awaiting a description' do + + before do + @mock_request.stub!(:awaiting_description).and_return(true) + end + + it 'should show the first form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_1") + end + + it 'should show the second form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_2") + end + + end + + describe 'when the user is the request owner' do + + before do + assigns[:is_owning_user] = true + end + + describe 'when the request status is "waiting clarification"' do + + before do + @mock_request.stub!(:calculate_status).and_return('waiting_clarification') + end + + describe 'when there is a last response' do + + before do + @mock_response = mock_model(IncomingMessage) + @mock_request.stub!(:get_last_response).and_return(@mock_response) + end + + it 'should show a link to follow up the last response with clarification' do + do_render + expected_url = "http://test.host/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" + puts response.body + response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + end + + end + + describe 'when there is no last response' do + + before do + @mock_request.stub!(:get_last_response).and_return(nil) + end + + it 'should show a link to follow up the request without reference to a specific response' do + do_render + expected_url = "http://test.host/request/#{@mock_request.id}/response#followup" + response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + end + end + end + + end +end
\ No newline at end of file |