aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/raw_email.rb25
-rw-r--r--db/migrate/082_change_raw_email_to_binary.rb15
-rw-r--r--db/schema.rb13
-rw-r--r--spec/fixtures/raw_emails.yml2
-rw-r--r--spec/models/outgoing_mailer_spec.rb8
5 files changed, 52 insertions, 11 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index 7e7db2b62..921c04034 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -19,6 +19,31 @@ class RawEmail < ActiveRecord::Base
# deliberately don't strip_attributes, so keeps raw email properly
has_one :incoming_message
+
+
+ # We keep the old data_text field (which is of type text) for backwards
+ # compatibility. We use the new data_binary field because only it works
+ # properly in recent versions of PostgreSQL (get seg faults escaping
+ # some binary strings).
+
+ def data=(d)
+ write_attribute(:data_binary, d)
+ end
+
+ def data
+ d = read_attribute(:data_binary)
+ if !d.nil?
+ return d
+ end
+
+ d = read_attribute(:data_text)
+ if !d.nil?
+ return d
+ end
+
+ raise "internal error, double nil value in RawEmail"
+ end
+
end
diff --git a/db/migrate/082_change_raw_email_to_binary.rb b/db/migrate/082_change_raw_email_to_binary.rb
new file mode 100644
index 000000000..2bcceee88
--- /dev/null
+++ b/db/migrate/082_change_raw_email_to_binary.rb
@@ -0,0 +1,15 @@
+class ChangeRawEmailToBinary < ActiveRecord::Migration
+ def self.up
+ change_column :raw_emails, :data, :binary, :null => true
+ rename_column(:raw_emails, :data, :data_text)
+ add_column :raw_emails, :data_binary, :binary
+ end
+
+ def self.down
+ raise "safer not to have reverse migration scripts, and we never use them"
+ end
+end
+
+
+
+
diff --git a/db/schema.rb b/db/schema.rb
index 50adde788..c0782ac1d 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 => 81) do
+ActiveRecord::Schema.define(:version => 82) do
create_table "acts_as_xapian_jobs", :force => true do |t|
t.string "model", :null => false
@@ -193,17 +193,18 @@ ActiveRecord::Schema.define(:version => 81) do
end
create_table "raw_emails", :force => true do |t|
- t.text "data", :null => false
+ t.text "data_text"
+ t.binary "data_binary"
end
create_table "track_things", :force => true do |t|
- t.integer "tracking_user_id", :null => false
- t.string "track_query", :null => false
+ t.integer "tracking_user_id", :null => false
+ t.string "track_query", :null => false
t.integer "info_request_id"
t.integer "tracked_user_id"
t.integer "public_body_id"
- t.string "track_medium", :null => false
- t.string "track_type", :null => false
+ t.string "track_medium", :null => false
+ t.string "track_type", :default => "internal_error", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml
index 46f7ec09a..4930e9966 100644
--- a/spec/fixtures/raw_emails.yml
+++ b/spec/fixtures/raw_emails.yml
@@ -1,6 +1,6 @@
useless_raw_email:
id: 1
- data: |
+ data_binary: |
From: "FOI Person" <foiperson@localhost>
To: "Bob Smith" <bob@localhost>
Date: Tue, 13 Nov 2007 11:39:55 +0000
diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb
index 8317d12d8..de59b09b2 100644
--- a/spec/models/outgoing_mailer_spec.rb
+++ b/spec/models/outgoing_mailer_spec.rb
@@ -20,7 +20,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
- im.raw_email.data.sub!("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")
+ im.raw_email.data = im.raw_email.data.sub("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "foiperson@localhost"
@@ -32,7 +32,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
- im.raw_email.data.sub!("FOI Person", "FOI [ Person")
+ im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI [ Person")
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI [ Person\" <foiperson@localhost>"
@@ -44,7 +44,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
- im.raw_email.data.sub!("FOI Person", "FOI \\\" Person")
+ im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI \\\" Person")
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI \\\" Person\" <foiperson@localhost>"
@@ -56,7 +56,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
- im.raw_email.data.sub!("FOI Person", "FOI @ Person")
+ im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI @ Person")
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI @ Person\" <foiperson@localhost>"