diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-11-04 14:55:38 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-12-18 14:01:52 +0000 |
commit | 148eb5e7e36a3e069d73a85188298d26bee1b220 (patch) | |
tree | 0060a5885e2089f8a2fa0fe8031e835df78700cd | |
parent | 8916380169bcde8493230ea69adb9fcdf1522e6c (diff) |
Make marking an event as a clarification a RESTful route
-rw-r--r-- | app/controllers/admin_info_request_event_controller.rb | 24 | ||||
-rw-r--r-- | app/controllers/admin_request_controller.rb | 15 | ||||
-rw-r--r-- | app/views/admin_request/show.html.erb | 3 | ||||
-rw-r--r-- | config/routes.rb | 8 | ||||
-rw-r--r-- | spec/controllers/admin_info_request_event_controller_spec.rb | 41 | ||||
-rw-r--r-- | spec/factories/info_request_events.rb | 12 |
6 files changed, 85 insertions, 18 deletions
diff --git a/app/controllers/admin_info_request_event_controller.rb b/app/controllers/admin_info_request_event_controller.rb new file mode 100644 index 000000000..17d147582 --- /dev/null +++ b/app/controllers/admin_info_request_event_controller.rb @@ -0,0 +1,24 @@ +# app/controllers/admin_info_request_event_controller.rb: +# Controller for FOI request event manipulation from the admin interface. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +class AdminInfoRequestEventController < AdminController + + # used so due dates get fixed + def update + @info_request_event = InfoRequestEvent.find(params[:id]) + if @info_request_event.event_type != 'response' + raise Exception("can only mark responses as requires clarification") + end + @info_request_event.described_state = 'waiting_clarification' + @info_request_event.calculated_state = 'waiting_clarification' + # TODO: deliberately don't update described_at so doesn't reenter search? + @info_request_event.save! + + flash[:notice] = "Old response marked as having been a clarification" + redirect_to admin_request_url(@info_request_event.info_request) + end + +end diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 30abc5067..9ccbd2d6f 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -182,21 +182,6 @@ class AdminRequestController < AdminController render :text => @raw_email.data end - # used so due dates get fixed - def mark_event_as_clarification - info_request_event = InfoRequestEvent.find(params[:info_request_event_id]) - if info_request_event.event_type != 'response' - raise Exception("can only mark responses as requires clarification") - end - info_request_event.described_state = 'waiting_clarification' - info_request_event.calculated_state = 'waiting_clarification' - # TODO: deliberately don't update described_at so doesn't reenter search? - info_request_event.save! - - flash[:notice] = "Old response marked as having been a clarification" - redirect_to admin_request_url(info_request_event.info_request) - end - def hide ActiveRecord::Base.transaction do subject = params[:subject] diff --git a/app/views/admin_request/show.html.erb b/app/views/admin_request/show.html.erb index 65c4a1f4a..9b04ebe5e 100644 --- a/app/views/admin_request/show.html.erb +++ b/app/views/admin_request/show.html.erb @@ -192,8 +192,7 @@ <tr> <td> <% if info_request_event.described_state != 'waiting_clarification' and info_request_event.event_type == 'response' %> - <%= form_tag admin_request_clarification_path, :class => "form form-inline admin-table-form admin-inline-form" do %> - <%= hidden_field_tag 'info_request_event_id', info_request_event.id, :id => nil %> + <%= form_tag admin_info_request_event_path(info_request_event), :method => 'put', :class => "form form-inline admin-table-form admin-inline-form" do %> <%= submit_tag "Was clarification request", :class => "btn btn-mini btn-primary" %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index a594f73c0..40af4e7d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,7 +223,6 @@ Alaveteli::Application.routes.draw do end end match '/admin/request/download_raw_email/:id' => 'admin_request#download_raw_email', :as => :admin_request_download_raw_email - match '/admin/request/mark_event_as_clarification' => 'admin_request#mark_event_as_clarification', :as => :admin_request_clarification #### #### AdminComment controller @@ -242,6 +241,13 @@ Alaveteli::Application.routes.draw do end #### + #### AdminInfoRequestEvent controller + scope '/admin', :as => 'admin' do + resources :info_request_events, + :controller => 'admin_info_request_event', + :only => [:update] + end + #### AdminIncomingMessage controller match '/admin/incoming/destroy' => 'admin_incoming_message#destroy', :as => :admin_incoming_destroy match '/admin/incoming/redeliver' => 'admin_incoming_message#redeliver', :as => :admin_incoming_redeliver diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb new file mode 100644 index 000000000..23300a0b8 --- /dev/null +++ b/spec/controllers/admin_info_request_event_controller_spec.rb @@ -0,0 +1,41 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminInfoRequestEventController do + + describe :update do + + describe 'when handling valid data' do + + before do + @info_request_event = FactoryGirl.create(:info_request_event) + put :update, :id => @info_request_event + end + + it 'gets the info request event' do + assigns[:info_request_event].should == @info_request_event + end + + it 'sets the described and calculated states on the event' do + event = InfoRequestEvent.find(@info_request_event.id) + event.described_state.should == 'waiting_clarification' + event.calculated_state.should == 'waiting_clarification' + end + + it 'shows a success notice' do + flash[:notice].should == 'Old response marked as having been a clarification' + end + + it 'redirects to the request admin page' do + response.should redirect_to(admin_request_url(@info_request_event.info_request)) + end + end + + it 'raises an exception if the event is not a response' do + @info_request_event = FactoryGirl.create(:sent_event) + lambda{ put :update, :id => @info_request_event }.should raise_error + end + + end + +end diff --git a/spec/factories/info_request_events.rb b/spec/factories/info_request_events.rb new file mode 100644 index 000000000..cdd303ad6 --- /dev/null +++ b/spec/factories/info_request_events.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + + factory :info_request_event do + info_request + event_type 'response' + params_yaml '' + factory :sent_event do + event_type 'sent' + end + end + +end |