2016-04-01 05:33:25 +08:00
|
|
|
require 'rails_helper'
|
2013-10-01 15:04:02 +08:00
|
|
|
require_dependency 'jobs/regular/process_post'
|
2013-06-14 06:11:10 +08:00
|
|
|
|
|
|
|
describe Jobs::PollMailbox do
|
|
|
|
|
2016-04-01 05:33:25 +08:00
|
|
|
let(:poller) { Jobs::PollMailbox.new }
|
2013-06-14 06:11:10 +08:00
|
|
|
|
2014-04-10 01:26:19 +08:00
|
|
|
describe ".execute" do
|
|
|
|
|
2014-08-27 07:52:35 +08:00
|
|
|
it "does no polling if pop3_polling_enabled is false" do
|
2016-04-01 05:33:25 +08:00
|
|
|
SiteSetting.expects(:pop3_polling_enabled).returns(false)
|
2014-08-27 07:52:35 +08:00
|
|
|
poller.expects(:poll_pop3).never
|
2014-04-10 01:26:19 +08:00
|
|
|
poller.execute({})
|
|
|
|
end
|
|
|
|
|
2016-04-01 05:33:25 +08:00
|
|
|
it "polls when pop3_polling_enabled is true" do
|
|
|
|
SiteSetting.expects(:pop3_polling_enabled).returns(true)
|
|
|
|
poller.expects(:poll_pop3).once
|
|
|
|
poller.execute({})
|
2014-04-10 01:26:19 +08:00
|
|
|
end
|
2013-06-14 06:11:10 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-08-27 07:52:35 +08:00
|
|
|
describe ".poll_pop3" do
|
2014-04-10 01:26:19 +08:00
|
|
|
|
2014-07-01 06:16:16 +08:00
|
|
|
it "logs an error on pop authentication error" do
|
2016-04-01 05:33:25 +08:00
|
|
|
Net::POP3.any_instance.expects(:start).raises(Net::POPAuthenticationError.new)
|
2015-02-10 04:47:46 +08:00
|
|
|
Discourse.expects(:handle_job_exception)
|
2014-08-27 07:52:35 +08:00
|
|
|
poller.poll_pop3
|
2014-04-10 01:26:19 +08:00
|
|
|
end
|
|
|
|
|
2014-08-27 08:00:27 +08:00
|
|
|
it "calls enable_ssl when the setting is enabled" do
|
|
|
|
SiteSetting.pop3_polling_ssl = true
|
|
|
|
Net::POP3.any_instance.stubs(:start)
|
|
|
|
Net::POP3.any_instance.expects(:enable_ssl)
|
|
|
|
poller.poll_pop3
|
|
|
|
end
|
|
|
|
|
2016-04-01 05:33:25 +08:00
|
|
|
it "does not call enable_ssl when the setting is disabled" do
|
2014-08-27 08:00:27 +08:00
|
|
|
SiteSetting.pop3_polling_ssl = false
|
|
|
|
Net::POP3.any_instance.stubs(:start)
|
|
|
|
Net::POP3.any_instance.expects(:enable_ssl).never
|
|
|
|
poller.poll_pop3
|
|
|
|
end
|
2014-04-10 01:26:19 +08:00
|
|
|
end
|
|
|
|
|
2013-06-14 06:11:10 +08:00
|
|
|
end
|