Refactor out handle_failure method in PollMailbox

This commit is contained in:
riking 2014-08-01 11:03:55 -07:00
parent d7df4e5979
commit c0b2b9b341
2 changed files with 47 additions and 40 deletions

View File

@ -24,7 +24,13 @@ module Jobs
mail_string = mail.pop
Email::Receiver.new(mail_string).process
rescue => e
message_template = nil
handle_failure(mail_string, e)
ensure
mail.delete
end
end
def handle_failure(mail_string, e)
template_args = {}
case e
when Email::Receiver::UserNotSufficientTrustLevelError
@ -62,9 +68,6 @@ module Jobs
else
Discourse.handle_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string))
end
ensure
mail.delete
end
end
def poll_pop3s

View File

@ -63,6 +63,10 @@ describe Jobs::PollMailbox do
end
end
def expect_success
Jobs::PollMailbox.expects(:handle_failure).never
end
describe "processing email B" do
let(:category) { Fabricate(:category) }
let(:user) { Fabricate(:user) }
@ -83,6 +87,7 @@ describe Jobs::PollMailbox do
let(:expected_post) { fixture_file('emails/valid_incoming.cooked') }
it "posts a new topic with the correct content" do
expect_success
poller.handle_mail(email)
@ -111,8 +116,7 @@ describe Jobs::PollMailbox do
end
pending "creates a new post with the correct content" do
RejectionMailer.expects(:send_rejection).never
Discourse.expects(:handle_exception).never
expect_success
poller.handle_mail(email)