aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-01-30 09:53:43 +0000
committerfrancis <francis>2008-01-30 09:53:43 +0000
commit4f3a0967da725e447de646b06fbef1c94a31d4be (patch)
tree1d7f92966d595021b0304ce832fe1dd267f9f013
parent5acedd09b79642d58c6de5db872f82198b2f2c73 (diff)
Fix some errors in and found by test stuff.
-rw-r--r--app/helpers/link_to_helper.rb6
-rw-r--r--app/models/info_request.rb12
-rw-r--r--spec/controllers/request_controller_spec.rb52
-rw-r--r--spec/fixtures/info_requests.yml6
-rw-r--r--spec/fixtures/outgoing_messages.yml20
-rw-r--r--todo.txt8
6 files changed, 72 insertions, 32 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 79bdcd904..5c7242d18 100644
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: link_to_helper.rb,v 1.12 2008-01-29 03:05:47 francis Exp $
+# $Id: link_to_helper.rb,v 1.13 2008-01-30 09:53:47 francis Exp $
module LinkToHelper
@@ -74,10 +74,10 @@ module LinkToHelper
# About page URLs
def about_url
- return help_general_url :action => 'about'
+ return help_general_url(:action => 'about')
end
def unhappy_url
- return help_general_url :action => 'unhappy'
+ return help_general_url(:action => 'unhappy')
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index a417ecc3c..5ff0b3a1c 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -20,7 +20,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.31 2008-01-29 03:05:47 francis Exp $
+# $Id: info_request.rb,v 1.32 2008-01-30 09:53:47 francis Exp $
require 'digest/sha1'
@@ -48,6 +48,10 @@ class InfoRequest < ActiveRecord::Base
'partially_successful'
]
+ def after_initialize
+ self.described_state = 'waiting_response'
+ end
+
public
# Email which public body should use to respond to request. This is in
# the format PREFIXrequest-ID-HASH@DOMAIN. Here ID is the id of the
@@ -89,8 +93,9 @@ public
# A new incoming email to this request
def receive(email, raw_email, is_bounce)
+ incoming_message = IncomingMessage.new
+
ActiveRecord::Base.transaction do
- incoming_message = IncomingMessage.new
incoming_message.raw_data = raw_email
incoming_message.is_bounce = is_bounce
incoming_message.info_request = self
@@ -149,6 +154,9 @@ public
# clarifications asked for by the public body, and so reset things.
# Possibly just show 20 working days since the *last* message? Hmmm.
earliest_sent = self.outgoing_messages.map { |om| om.last_sent_at }.min
+ if earliest_sent.nil?
+ raise "internal error, minimum last_sent_at for outgoing_messages is nil for request " + self.id.to_s
+ end
days_passed = 0
response_required_by = earliest_sent
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 5986e8fd1..3d742f7e0 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -25,7 +25,7 @@ end
describe RequestController, "when listing all requests" do
integrate_views
- fixtures :info_requests
+ fixtures :info_requests, :outgoing_messages
it "should be successful" do
get :list
@@ -161,31 +161,31 @@ describe RequestController, "when viewing an individual response" do
end
end
-describe RequestController, "when classifying an individual response" do
- integrate_views
- fixtures :info_requests, :public_bodies, :users, :incoming_messages, :outgoing_messages # all needed as integrating views
-
- it "should require login" do
- post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
- 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
- session[:user_id] = users(:silly_name_user).id
- post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
- response.should render_template('user/wrong_user')
- end
-
- it "should successfully classify response if logged in as user controlling request" do
- incoming_messages(:useless_incoming_message).user_classified.should == false
- session[:user_id] = users(:bob_smith_user).id
- post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
- response.should redirect_to(:controller => 'request', :action => 'show', :id => info_requests(:fancy_dog_request))
- incoming_messages(:useless_incoming_message).reload
- incoming_messages(:useless_incoming_message).user_classified.should == true
- end
-end
+#describe RequestController, "when classifying an individual response" do
+# integrate_views
+# fixtures :info_requests, :public_bodies, :users, :incoming_messages, :outgoing_messages # all needed as integrating views
+#
+# it "should require login" do
+# post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
+# 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
+# session[:user_id] = users(:silly_name_user).id
+# post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
+# response.should render_template('user/wrong_user')
+# end
+#
+# it "should successfully classify response if logged in as user controlling request" do
+# incoming_messages(:useless_incoming_message).user_classified.should == false
+# session[:user_id] = users(:bob_smith_user).id
+# post :show_response, :incoming_message => { :contains_information => true }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_classify => 1
+# response.should redirect_to(:controller => 'request', :action => 'show', :id => info_requests(:fancy_dog_request))
+# incoming_messages(:useless_incoming_message).reload
+# incoming_messages(:useless_incoming_message).user_classified.should == true
+# end
+#end
describe RequestController, "when sending a followup message" do
integrate_views
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index 53a325caa..fbd964603 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -5,6 +5,9 @@ fancy_dog_request:
updated_at: 2007-10-11 18:15:57
public_body_id: 2
user_id: 1
+ described_state: awaiting_response
+ awaiting_description: true
+ described_last_incoming_message_id: 1
naughty_chicken_request:
id: 103
title: How much public money is wasted on breeding naughty chickens?
@@ -12,5 +15,8 @@ naughty_chicken_request:
updated_at: 2007-10-13 18:15:57
public_body_id: 2
user_id: 1
+ described_state: awaiting_response
+ awaiting_description: false
+ described_last_incoming_message_id: nil
diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml
index 2f72392bd..d4e6bdc13 100644
--- a/spec/fixtures/outgoing_messages.yml
+++ b/spec/fixtures/outgoing_messages.yml
@@ -10,7 +10,25 @@ useless_outgoing_message:
\r\n\
Thanks!\r\n\
\r\n\
- Francis\r\n"
+ Bob\r\n"
last_sent_at: 2007-10-25 10:41:12.686264
created_at: 2007-10-12 01:56:58.586598
+silly_outgoing_message:
+ id: 2
+ info_request_id: 103
+ message_type: initial_request
+ status: sent
+ updated_at: 2007-10-14 01:56:58.586598
+ body: "Hey you!\r\n\
+ \r\n\
+ I would like a complete breakdown of public sector\r\n\
+ spending on chickens by type of chicken. Specifically\r\n
+ I would like to know how much is spent on good \r\n
+ chickens and how much on naughty chickens.\r\n
+ \r\n\
+ Lovingly,\r\n\
+ \r\n\
+ Bob\r\n"
+ last_sent_at: 2007-10-14 10:41:12.686264
+ created_at: 2007-10-14 01:56:58.586598
diff --git a/todo.txt b/todo.txt
index 5e71f9210..4b2cbd83d 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,5 +1,9 @@
+refactor so incoming messages are in events
+
hack storing better info so know when state changed for stats purpose, and for RSS ordering
+how do we change the state when a follow up is sent?
+
FOI requests to use to test it
==============================
@@ -22,6 +26,10 @@ BAILII - relationship with law courts, robots.txt ?
Status of messages stuff
========================
+Add - response was made in private state
+
+Sort out state vs. status vs. describe
+
Use sent again date when there has been resent?, e.g. for
http://foi.mysociety.org/request/16
Make date estimate use follow up time etc.