aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-05-28 14:00:57 +0100
committerRobin Houston <robin.houston@gmail.com>2012-06-06 19:34:58 +0100
commit141fcea3f05725848f1dbe17ffbda32bd64367a0 (patch)
treebb152b4275edda71ce74d0641476a773ab0f9aaa
parent6d5d9c89c944c6d5964c775859d3e642ab13dc0d (diff)
Fail less bafflingly
Fail in a less baffling way if the raw email is associated with an incoming message or an info request that has not yet been saved to the database.
-rw-r--r--app/models/raw_email.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index e15f499e9..3bb794684 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -21,6 +21,10 @@ class RawEmail < ActiveRecord::Base
def directory
request_id = self.incoming_message.info_request.id.to_s
+ if request_id.empty?
+ raise "Failed to find the id number of the associated request: has it been saved?"
+ end
+
if ENV["RAILS_ENV"] == "test"
return File.join(Rails.root, 'files/raw_email_test')
else
@@ -31,7 +35,11 @@ class RawEmail < ActiveRecord::Base
end
def filepath
- File.join(self.directory, self.incoming_message.id.to_s)
+ incoming_message_id = self.incoming_message.id.to_s
+ if incoming_message_id.empty?
+ raise "Failed to find the id number of the associated incoming message: has it been saved?"
+ end
+ File.join(self.directory, incoming_message_id)
end
def data=(d)