aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api_controller_spec.rb3
-rw-r--r--spec/models/info_request_spec.rb53
2 files changed, 53 insertions, 3 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 66b8e33f0..8e9d17fbe 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -83,6 +83,9 @@ describe ApiController, "when using the API" do
new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"].strip
new_request.public_body_id.should == public_bodies(:geraldine_public_body).id
+ new_request.info_request_events.size.should == 1
+ new_request.info_request_events[0].event_type.should == 'sent'
+ new_request.info_request_events[0].calculated_state.should == 'waiting_response'
end
def _create_request
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index c9ee57c74..3451e018f 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -670,7 +670,7 @@ describe InfoRequest do
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[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -698,7 +698,7 @@ describe InfoRequest do
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[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -731,7 +731,7 @@ describe InfoRequest do
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[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -807,6 +807,53 @@ describe InfoRequest do
events[1].described_state.should == "successful"
events[1].calculated_state.should == "successful"
end
+
+ it "should have sensible event states" 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 user marks the request as successful
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ 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 == "successful"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "successful"
+ events[2].calculated_state.should == "successful"
+ end
+ end
+
+ context "another series of events on a request", :focus => true do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An admin sets the status of the request to 'gone postal' using
+ # the admin interface
+ request.log_event("edit", {})
+ request.set_described_state("gone_postal")
+
+ 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 == "edit"
+ events[1].described_state.should == "gone_postal"
+ events[1].calculated_state.should == "gone_postal"
+ end
end
end
end