diff options
author | Henare Degan <henare.degan@gmail.com> | 2013-03-14 14:33:17 +1100 |
---|---|---|
committer | Henare Degan <henare.degan@gmail.com> | 2013-03-14 14:33:17 +1100 |
commit | 48c6f8077429dd86da27a52be20c97cc583f31a9 (patch) | |
tree | 78d74660677a3a63659260c982dabfade692749d /spec/controllers/request_controller_spec.rb | |
parent | 2f6af09899e2822121d060db55fdd78b15f099db (diff) | |
parent | d8a5de249bfeb41317d64e7efbaab71da1ede00d (diff) |
Merge remote-tracking branch 'mysociety/develop' into rails-3-develop
Conflicts:
Gemfile
Gemfile.lock
app/controllers/admin_request_controller.rb
app/controllers/admin_track_controller.rb
app/controllers/request_controller.rb
app/controllers/services_controller.rb
app/helpers/link_to_helper.rb
app/mailers/request_mailer.rb
app/models/application_mailer.rb
app/models/info_request.rb
app/views/admin_censor_rule/edit.html.erb
app/views/admin_censor_rule/new.html.erb
app/views/admin_public_body/_form.html.erb
app/views/admin_public_body/_locale_selector.html.erb
app/views/admin_public_body/_one_list.html.erb
app/views/admin_public_body/edit.html.erb
app/views/admin_public_body/list.html.erb
app/views/admin_public_body/new.html.erb
app/views/admin_request/_incoming_message_actions.html.erb
app/views/admin_request/edit.html.erb
app/views/admin_request/edit_comment.html.erb
app/views/admin_request/edit_outgoing.html.erb
app/views/admin_request/list.html.erb
app/views/admin_request/list_old_unclassified.html.erb
app/views/admin_request/show.html.erb
app/views/admin_track/_some_tracks.html.erb
app/views/admin_track/list.html.erb
app/views/admin_user/edit.html.erb
app/views/admin_user/list.html.erb
app/views/admin_user/show.html.erb
app/views/general/_footer.html.erb
app/views/general/exception_caught.html.erb
app/views/help/contact.html.erb
app/views/layouts/default.html.erb
app/views/public_body/_alphabet.html.erb
app/views/request/_request_listing_single.html.erb
app/views/request/_sidebar.html.erb
app/views/request/new.html.erb
app/views/request/show.html.erb
app/views/request_mailer/external_response.rhtml
app/views/request_mailer/fake_response.rhtml
config/environment.rb
config/environments/production.rb
config/routes.rb
spec/controllers/admin_censor_rule_controller_spec.rb
spec/controllers/request_controller_spec.rb
spec/controllers/track_controller_spec.rb
spec/helpers/link_to_helper_spec.rb
spec/mailers/request_mailer_spec.rb
spec/models/info_request_spec.rb
spec/spec_helper.rb
spec/views/public_body/show.html.erb_spec.rb
spec/views/request/show.html.erb_spec.rb
vendor/plugins/rails_xss/lib/rails_xss/erubis.rb
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 105 |
1 files changed, 81 insertions, 24 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 842b4e47c..396182f00 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -337,12 +337,12 @@ describe RequestController, "when showing one request" do it 'should not show the describe state form' do make_request - response.should_not have_selector('div.describe_state_form') + response.should_not have_tag('div.describe_state_form') end it 'should not ask the user to use the describe state form' do make_request - response.should_not have_selector('p#request_status', :content => "answer the question above") + response.should_not have_tag('p#request_status', :text => /answer the question above/) end end @@ -1251,8 +1251,7 @@ describe RequestController, "when classifying an information request" do end it 'should redirect to the request page' do - post :describe_state, :id => @external_request.id, - :submitted_describe_state => 1 + post :describe_state, :id => @external_request.id response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @external_request.url_title) @@ -1272,8 +1271,7 @@ describe RequestController, "when classifying an information request" do 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 + :last_info_request_event_id => @dog_request.last_event_id_needing_description end it "should require login" do @@ -1283,6 +1281,7 @@ describe RequestController, "when classifying an information request" do end it 'should ask whether the request is old and unclassified' do + session[:user_id] = users(:silly_name_user).id @dog_request.should_receive(:is_old_unclassified?) post_status('rejected') end @@ -1322,7 +1321,7 @@ describe RequestController, "when classifying an information request" do it 'should classify the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user), nil) post_status('rejected') end @@ -1350,6 +1349,26 @@ describe RequestController, "when classifying an information request" do flash[:notice].should == 'Thank you for updating this request!' end + context "playing the classification game" do + before :each do + session[:request_game] = true + end + + it "should continue the game after classifying a request" do + post_status("rejected") + flash[:notice].should =~ /There are some more requests below for you to classify/ + response.should redirect_to categorise_play_url + end + end + + it "should send a mail from the user who changed the state to requires_admin" do + post :describe_state, :incoming_message => { :described_state => "requires_admin", :message => "a message" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email + end end end @@ -1365,7 +1384,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1418,7 +1437,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1453,6 +1472,22 @@ describe RequestController, "when classifying an information request" do @dog_request.stub!(:each).and_return([@dog_request]) end + it "should let you know when you forget to select a status" do + post :describe_state, :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) + flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.") + end + + it "should not change the status if the request has changed while viewing it" do + @dog_request.stub!(:last_event_id_needing_description).and_return(2) + + post :describe_state, :incoming_message => { :described_state => "rejected" }, + :id => @dog_request.id, :last_info_request_event_id => 1 + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) + flash[:error].should =~ /The request has been updated since you originally loaded this page/ + end + it "should successfully classify response if logged in as user controlling request" do post_status('rejected') response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) @@ -1473,22 +1508,34 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end - it "should send email when classified as requires_admin" do - post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1 - response.should redirect_to(:controller => 'help', :action => 'contact') + it "should go to the page asking for more information when classified as requires_admin" do + post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to describe_state_message_url(:url_title => @dog_request.url_title, :described_state => "requires_admin") @dog_request.reload - @dog_request.awaiting_description.should == false - @dog_request.described_state.should == 'requires_admin' - @dog_request.get_last_response_event.calculated_state.should == 'requires_admin' + @dog_request.described_state.should_not == 'requires_admin' + + ActionMailer::Base.deliveries.should be_empty + end + + context "message is included when classifying as requires_admin" do + it "should send an email including the message" do + post :describe_state, + :incoming_message => { + :described_state => "requires_admin", + :message => "Something weird happened" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /as needing admin/ - mail.from_addrs.first.to_s.should == @request_owner.email + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as needing admin/ + mail.body.should =~ /Something weird happened/ + end end + it 'should say it is showing advice as to what to do next' do post_status('rejected') flash[:notice].should match(/Here is what to do now/) @@ -1598,12 +1645,22 @@ describe RequestController, "when classifying an information request" do expect_redirect('internal_review', request_url) end - it 'should redirect to the "help general url" when status is updated to "requires admin"' do - expect_redirect('requires_admin', "help/contact") + it 'should redirect to the "request url" when status is updated to "requires admin"' do + post :describe_state, :incoming_message => { + :described_state => 'requires_admin', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end - it 'should redirect to the "help general url" when status is updated to "error message"' do - expect_redirect('error_message', "help/contact") + it 'should redirect to the "request url" when status is updated to "error message"' do + post :describe_state, :incoming_message => { + :described_state => 'error_message', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do |