FIX: If there is an exception when parsing one email, don't stop all

work, return an error code and continue.
This commit is contained in:
Robin Ward 2014-02-12 12:08:34 -05:00
parent 62592215f4
commit 318e692290
2 changed files with 13 additions and 1 deletions

View file

@ -6,7 +6,7 @@ module Email
class Receiver
def self.results
@results ||= Enum.new(:unprocessable, :missing, :processed)
@results ||= Enum.new(:unprocessable, :missing, :processed, :error)
end
attr_reader :body, :reply_key, :email_log
@ -46,6 +46,8 @@ module Email
create_reply
Email::Receiver.results[:processed]
rescue
Email::Receiver.results[:error]
end
private

View file

@ -9,6 +9,16 @@ describe Email::Receiver do
SiteSetting.stubs(:reply_by_email_address).returns("reply+%{reply_key}@appmail.adventuretime.ooo")
end
describe "exception raised" do
it "returns error if it encountered an error processing" do
receiver = Email::Receiver.new("some email")
def receiver.parse_body
raise "ERROR HAPPENED!"
end
expect(receiver.process).to eq(Email::Receiver.results[:error])
end
end
describe 'invalid emails' do
it "returns unprocessable if the message is blank" do
expect(Email::Receiver.new("").process).to eq(Email::Receiver.results[:unprocessable])