Refactor out handle_failure method in PollMailbox
This commit is contained in:
parent
d7df4e5979
commit
c0b2b9b341
|
@ -24,7 +24,13 @@ module Jobs
|
||||||
mail_string = mail.pop
|
mail_string = mail.pop
|
||||||
Email::Receiver.new(mail_string).process
|
Email::Receiver.new(mail_string).process
|
||||||
rescue => e
|
rescue => e
|
||||||
message_template = nil
|
handle_failure(mail_string, e)
|
||||||
|
ensure
|
||||||
|
mail.delete
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_failure(mail_string, e)
|
||||||
template_args = {}
|
template_args = {}
|
||||||
case e
|
case e
|
||||||
when Email::Receiver::UserNotSufficientTrustLevelError
|
when Email::Receiver::UserNotSufficientTrustLevelError
|
||||||
|
@ -62,9 +68,6 @@ module Jobs
|
||||||
else
|
else
|
||||||
Discourse.handle_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string))
|
Discourse.handle_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string))
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
mail.delete
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def poll_pop3s
|
def poll_pop3s
|
||||||
|
|
|
@ -63,6 +63,10 @@ describe Jobs::PollMailbox do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expect_success
|
||||||
|
Jobs::PollMailbox.expects(:handle_failure).never
|
||||||
|
end
|
||||||
|
|
||||||
describe "processing email B" do
|
describe "processing email B" do
|
||||||
let(:category) { Fabricate(:category) }
|
let(:category) { Fabricate(:category) }
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
@ -83,6 +87,7 @@ describe Jobs::PollMailbox do
|
||||||
let(:expected_post) { fixture_file('emails/valid_incoming.cooked') }
|
let(:expected_post) { fixture_file('emails/valid_incoming.cooked') }
|
||||||
|
|
||||||
it "posts a new topic with the correct content" do
|
it "posts a new topic with the correct content" do
|
||||||
|
expect_success
|
||||||
|
|
||||||
poller.handle_mail(email)
|
poller.handle_mail(email)
|
||||||
|
|
||||||
|
@ -111,8 +116,7 @@ describe Jobs::PollMailbox do
|
||||||
end
|
end
|
||||||
|
|
||||||
pending "creates a new post with the correct content" do
|
pending "creates a new post with the correct content" do
|
||||||
RejectionMailer.expects(:send_rejection).never
|
expect_success
|
||||||
Discourse.expects(:handle_exception).never
|
|
||||||
|
|
||||||
poller.handle_mail(email)
|
poller.handle_mail(email)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue