aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb12
-rw-r--r--app/models/outgoing_message.rb7
-rw-r--r--spec/controllers/request_controller_spec.rb23
-rw-r--r--todo.txt5
4 files changed, 32 insertions, 15 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 159663691..447ff6c1a 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -23,7 +23,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.124 2008-07-21 00:48:05 francis Exp $
+# $Id: info_request.rb,v 1.125 2008-07-30 13:31:00 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -225,8 +225,14 @@ public
# XXX this *should* also check outgoing message joined to is an initial
# request (rather than follow up)
def InfoRequest.find_by_existing_request(title, public_body_id, body)
- # Exclude spaces from the body comparison
- return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and regexp_replace(outgoing_messages.body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')", title, public_body_id, body ], :include => [ :outgoing_messages ] )
+ # XXX can add other databases here which have regexp_replace
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ # Exclude spaces from the body comparison using regexp_replace
+ return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and regexp_replace(outgoing_messages.body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')", title, public_body_id, body ], :include => [ :outgoing_messages ] )
+ else
+ # For other databases (e.g. SQLite) not the end of the world being space-sensitive for this check
+ return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] )
+ end
end
# A new incoming email to this request
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 0b8276ca3..b5e9f7786 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -21,7 +21,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: outgoing_message.rb,v 1.56 2008-07-17 10:32:01 francis Exp $
+# $Id: outgoing_message.rb,v 1.57 2008-07-30 13:31:00 francis Exp $
class OutgoingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -55,10 +55,13 @@ class OutgoingMessage < ActiveRecord::Base
if ret.nil?
return ret
end
- ret.strip!
+ ret = ret.strip
ret = ret.gsub(/(?:\n\s*){2,}/, "\n\n") # remove excess linebreaks that unnecessarily space it out
ret
end
+ def raw_body
+ read_attribute(:body)
+ end
def body_without_salutation
ret = self.body
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 0705c978d..59ce51efa 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -162,21 +162,26 @@ describe RequestController, "when creating a new request" do
it "should give an error if the same request is submitted twice" do
session[:user_id] = users(:bob_smith_user).id
+ # We use raw_body here, so white space is the same
post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
:title => info_requests(:fancy_dog_request).title },
- :outgoing_message => { :body => info_requests(:fancy_dog_request).outgoing_messages[0].body},
+ :outgoing_message => { :body => info_requests(:fancy_dog_request).outgoing_messages[0].raw_body},
:submitted_new_request => 1, :preview => 0, :mouse_house => 1
response.should render_template('new')
end
it "should give an error if the same request is submitted twice with extra whitespace in the body" do
- session[:user_id] = users(:bob_smith_user).id
-
- post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
- :title => info_requests(:fancy_dog_request).title },
- :outgoing_message => { :body => "\n" + info_requests(:fancy_dog_request).outgoing_messages[0].body + " "},
- :submitted_new_request => 1, :preview => 0, :mouse_house => 1
- response.should render_template('new')
+ # This only works for PostgreSQL databases which have regexp_replace -
+ # see model method InfoRequest.find_by_existing_request for more info
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ session[:user_id] = users(:bob_smith_user).id
+
+ post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
+ :title => info_requests(:fancy_dog_request).title },
+ :outgoing_message => { :body => "\n" + info_requests(:fancy_dog_request).outgoing_messages[0].body + " "},
+ :submitted_new_request => 1, :preview => 0, :mouse_house => 1
+ response.should render_template('new')
+ end
end
it "should let you submit another request with the same title" do
@@ -361,7 +366,7 @@ describe RequestController, "clarification required alerts" do
ir.set_described_state('waiting_clarification')
# this is pretty horrid, but will do :) need to make it waiting
# clarification more than 3 days ago for the alerts to go out.
- ActiveRecord::Base.connection.update "update info_requests set updated_at = now() - '5 day'::interval where id = " + ir.id.to_s
+ ActiveRecord::Base.connection.update "update info_requests set updated_at = '" + (Time.now - 5.days).strftime("%Y-%m-%d %H:%M:%S") + "' where id = " + ir.id.to_s
ir.reload
RequestMailer.alert_not_clarified_request
diff --git a/todo.txt b/todo.txt
index 3a48cb2f4..ef3c9aa47 100644
--- a/todo.txt
+++ b/todo.txt
@@ -59,6 +59,9 @@ http://www.whatdotheyknow.com/request/unusual_markings_in_the_uk_skies
Later
=====
+When indexing .docx do you need to index docProps/custom.xml and docProps/app.xml
+as well as word/document.xml ? (thread on xapian-discuss does so)
+
Something to check which tags are used but aren't in PublicBody category lists
When described state is edited in admin interface, automatically reset the flag
@@ -133,7 +136,7 @@ register for.
Offer search on 404s
Preview when sending followups - especially people need to see quoting/subject
-When sending "my response is late"
+Spell checking for followups
For followups, have radio button to say is it a new request or followup?