aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/general_controller.rb4
-rw-r--r--app/models/info_request_event.rb19
-rw-r--r--app/views/request/_correspondence.rhtml4
-rw-r--r--db/migrate/052_include_event_foreign_references.rb25
-rw-r--r--db/schema.rb12
-rw-r--r--spec/fixtures/info_request_events.yml3
-rw-r--r--spec/models/request_mailer_spec.rb1
7 files changed, 56 insertions, 12 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 9b9e311e7..7dbfa6b53 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: general_controller.rb,v 1.17 2008-04-01 16:40:37 francis Exp $
+# $Id: general_controller.rb,v 1.18 2008-04-15 23:53:10 francis Exp $
class GeneralController < ApplicationController
@@ -56,6 +56,8 @@ class GeneralController < ApplicationController
query = params[:query]
sortby = params[:sortby]
perform_search(query, sortby)
+
+ #render :controller => "help", :action => "about"
end
# For debugging
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 6e8ce0231..f7897ed9d 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -18,13 +18,14 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request_event.rb,v 1.35 2008-04-09 16:53:59 francis Exp $
+# $Id: info_request_event.rb,v 1.36 2008-04-15 23:53:10 francis Exp $
class InfoRequestEvent < ActiveRecord::Base
belongs_to :info_request
validates_presence_of :info_request
- belongs_to :info_request_event_id
+ belongs_to :outgoing_message
+ belongs_to :incoming_message
validates_presence_of :event_type
validates_inclusion_of :event_type, :in => [
@@ -105,6 +106,14 @@ class InfoRequestEvent < ActiveRecord::Base
# We store YAML version of parameters in the database
def params=(params)
+ # XXX should really set these explicitly, and stop storing them in
+ # here, but keep it for compatibility with old way for now
+ if not params[:incoming_message_id].nil?
+ self.incoming_message_id = params[:incoming_message_id]
+ end
+ if not params[:outgoing_message_id].nil?
+ self.outgoing_message_id = params[:outgoing_message_id]
+ end
self.params_yaml = params.to_yaml
end
def params
@@ -113,7 +122,8 @@ class InfoRequestEvent < ActiveRecord::Base
# Find related incoming message
# XXX search for the find below and call this function more instead
- def incoming_message
+ # XXX deprecated, remove it
+ def incoming_message_via_params
if not ['response'].include?(self.event_type)
return nil
end
@@ -127,7 +137,8 @@ class InfoRequestEvent < ActiveRecord::Base
# Find related outgoing message
# XXX search for the find below and call this function more instead
- def outgoing_message
+ # XXX deprecated, remove it
+ def outgoing_message_via_params
if not [ 'edit_outgoing', 'sent', 'resent', 'followup_sent' ].include?(self.event_type)
return nil
end
diff --git a/app/views/request/_correspondence.rhtml b/app/views/request/_correspondence.rhtml
index 8f91631f2..cf7864041 100644
--- a/app/views/request/_correspondence.rhtml
+++ b/app/views/request/_correspondence.rhtml
@@ -1,7 +1,7 @@
<%
@last_email = nil
if !info_request_event.nil? && info_request_event.event_type == 'response'
- incoming_message = IncomingMessage.find(info_request_event.params[:incoming_message_id])
+ incoming_message = info_request_event.incoming_message
end
if not incoming_message.nil?
@@ -25,7 +25,7 @@ if not incoming_message.nil?
</div>
<%
elsif info_request_event.event_type == 'sent' || info_request_event.event_type == 'followup_sent'
- outgoing_message = OutgoingMessage.find(info_request_event.params[:outgoing_message_id])
+ outgoing_message = info_request_event.outgoing_message
%>
<div class="correspondence" id="outgoing-<%=outgoing_message.id.to_s%>">
<% if @previous_date.nil? or (@previous_date != info_request_event.created_at.to_date) %>
diff --git a/db/migrate/052_include_event_foreign_references.rb b/db/migrate/052_include_event_foreign_references.rb
new file mode 100644
index 000000000..faa853ef4
--- /dev/null
+++ b/db/migrate/052_include_event_foreign_references.rb
@@ -0,0 +1,25 @@
+class IncludeEventForeignReferences < ActiveRecord::Migration
+ def self.up
+ add_column :info_request_events, :incoming_message_id, :integer
+ add_column :info_request_events, :outgoing_message_id, :integer
+ for event in InfoRequestEvent.find(:all)
+ #STDERR.puts "event " + event.id.to_s
+ incoming_message = event.incoming_message_via_params
+ if not incoming_message.nil?
+ event.incoming_message_id = incoming_message.id
+ end
+ outgoing_message = event.outgoing_message_via_params
+ if not outgoing_message.nil?
+ event.outgoing_message_id = outgoing_message.id
+ end
+ event.save!
+ end
+ execute "ALTER TABLE info_request_events ADD CONSTRAINT fk_info_request_events_incoming_message_id FOREIGN KEY (incoming_message_id) REFERENCES incoming_messages(id)"
+ execute "ALTER TABLE info_request_events ADD CONSTRAINT fk_info_request_events_outgoing_message_id FOREIGN KEY (outgoing_message_id) REFERENCES outgoing_messages(id)"
+ end
+
+ def self.down
+ remove_column :info_request_events, :outgoing_message_id
+ remove_column :info_request_events, :incoming_message_id
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5e1982b16..331f7adbe 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 51) do
+ActiveRecord::Schema.define(:version => 52) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
@@ -19,13 +19,15 @@ ActiveRecord::Schema.define(:version => 51) do
end
create_table "info_request_events", :force => true do |t|
- t.integer "info_request_id", :null => false
- t.text "event_type", :null => false
- t.text "params_yaml", :null => false
- t.datetime "created_at", :null => false
+ t.integer "info_request_id", :null => false
+ t.text "event_type", :null => false
+ t.text "params_yaml", :null => false
+ t.datetime "created_at", :null => false
t.string "described_state"
t.string "calculated_state"
t.datetime "last_described_at"
+ t.integer "incoming_message_id"
+ t.integer "outgoing_message_id"
end
create_table "info_requests", :force => true do |t|
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index 095f18f52..894e9cc7a 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -6,6 +6,7 @@ useless_outgoing_message_event:
event_type: sent
created_at: 2007-10-12 01:56:58.586598
described_state:
+ outgoing_message_id: 1
silly_outgoing_message_event:
params_yaml: "--- \n\
:outgoing_message_id: 2\n"
@@ -14,6 +15,7 @@ silly_outgoing_message_event:
event_type: sent
created_at: 2007-10-14 10:41:12.686264
described_state:
+ outgoing_message_id: 2
useless_incoming_message_event:
params_yaml: "--- \n\
:incoming_message_id: 1\n"
@@ -22,3 +24,4 @@ useless_incoming_message_event:
event_type: response
created_at: 2007-11-13 18:09:20.042061
described_state:
+ incoming_message_id: 1
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index c5a500f8f..8c7eaefe2 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -12,6 +12,7 @@ describe RequestMailer, " when receiving incoming mail" do
ir.incoming_messages.size.should == 1 # in the fixture
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
ir.incoming_messages.size.should == 2 # one more arrives
+ ir.info_request_events[-1].incoming_message_id.should_not be_nil
end
it "should bounce email to admin when the email is not to any information request" do