aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb10
-rw-r--r--app/models/info_request.rb12
-rw-r--r--spec/controllers/request_controller_spec.rb11
-rw-r--r--spec/models/info_request_spec.rb203
4 files changed, 220 insertions, 16 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 42693f867..d8f8db3cf 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -417,12 +417,22 @@ class RequestController < ApplicationController
end
# Make the state change
+ event = info_request.log_event("status_update",
+ { :user_id => authenticated_user.id,
+ :old_described_state => info_request.described_state,
+ :described_state => described_state,
+ })
+
info_request.set_described_state(described_state, authenticated_user, message)
# If you're not the *actual* requester. e.g. you are playing the
# classification game, or you're doing this just because you are an
# admin user (not because you also own the request).
if !info_request.is_actual_owning_user?(authenticated_user)
+ # Create a classification event for league tables
+ RequestClassification.create!(:user_id => authenticated_user.id,
+ :info_request_event_id => event.id)
+
# Don't give advice on what to do next, as it isn't their request
if session[:request_game]
flash[:notice] = _('Thank you for updating the status of the request \'<a href="{{url}}">{{info_request_title}}</a>\'. There are some more requests below for you to classify.',:info_request_title=>CGI.escapeHTML(info_request.title), :url=>CGI.escapeHTML(request_path(info_request)))
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 46c247fa9..8f15a4ea4 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -584,16 +584,6 @@ public
end
unless set_by.nil? || is_actual_owning_user?(set_by) || described_state == 'attention_requested'
- # Log the status change by someone other than the requester
- event = log_event("status_update",
- { :user_id => set_by.id,
- :old_described_state => old_described_state,
- :described_state => described_state,
- })
- # Create a classification event for league tables
- RequestClassification.create!(:user_id => set_by.id,
- :info_request_event_id => event.id)
-
RequestMailer.old_unclassified_updated(self).deliver if !is_external?
end
end
@@ -646,7 +636,7 @@ public
event.save!
end
curr_state = nil
- elsif !curr_state.nil? && (event.event_type == 'followup_sent' || event.event_type == 'sent') && !event.described_state.nil? && (event.described_state == 'waiting_response' || event.described_state == 'internal_review')
+ elsif !curr_state.nil? && (event.event_type == 'followup_sent' || event.event_type == 'sent' || event.event_type == "status_update")
# Followups can set the status to waiting response / internal
# review. Initial requests ('sent') set the status to waiting response.
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c73576c50..387b040d6 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1519,8 +1519,8 @@ describe RequestController, "when classifying an information request" do
post_status('rejected')
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
@@ -1573,11 +1573,12 @@ describe RequestController, "when classifying an information request" do
@dog_request.awaiting_description.should == false
@dog_request.described_state.should == 'rejected'
@dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
- @dog_request.get_last_response_event.calculated_state.should == 'rejected'
+ @dog_request.info_request_events.last.event_type.should == "status_update"
+ @dog_request.info_request_events.last.calculated_state.should == 'rejected'
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index f9ca44657..0ba8abd75 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -606,4 +606,207 @@ describe InfoRequest do
@info_request.user_json_for_api.should == {:name => 'Anonymous user'}
end
end
+ describe "#set_described_state and #log_event" do
+ context "a request" do
+ let(:request) { InfoRequest.create!(:title => "my request",
+ :public_body => public_bodies(:geraldine_public_body),
+ :user => users(:bob_smith_user)) }
+
+ context "a series of events on a request" do
+ it "should have sensible events after the initial request has been made" do
+ # An initial request is sent
+ # The logic that changes the status when a message is sent is mixed up
+ # in OutgoingMessage#send_message. So, rather than extract it (or call it)
+ # let's just duplicate what it does here for the time being.
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 1
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a response is received to a request" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ # This is normally done in InfoRequest#receive
+ request.awaiting_description = true
+ request.log_event("response", {})
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ # TODO: Should calculated_status in this situation be "waiting_classification"?
+ # This would allow searches like "latest_status: waiting_classification" to be
+ # available to the user in "Advanced search"
+ events[1].calculated_state.should be_nil
+ end
+
+ it "should have sensible events after a request is classified by the requesting user" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ # This is normally done in RequestController#describe_state
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a normal followup is sent" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ # This is normally done in OutgoingMessage#send_message
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 4
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a user classifies the request after a follow up" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 5
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should be_nil
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ events[4].event_type.should == "status_update"
+ events[4].described_state.should == "waiting_response"
+ events[4].calculated_state.should == "waiting_response"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ end
+
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+ # The user marks the request as rejected
+ request.log_event("status_update", {})
+ request.set_described_state("rejected")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "rejected"
+ events[2].calculated_state.should == "rejected"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # The user marks the request as successful (I know silly but someone did
+ # this in https://www.whatdotheyknow.com/request/family_support_worker_redundanci)
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "status_update"
+ events[1].described_state.should == "successful"
+ events[1].calculated_state.should == "successful"
+ end
+ end
+ end
+ end
end