2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-10-01 03:04:02 -04:00
|
|
|
require_dependency 'jobs/regular/process_post'
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
describe Jobs::PollMailbox do
|
|
|
|
|
2016-01-18 18:57:55 -05:00
|
|
|
let(:poller) { Jobs::PollMailbox.new }
|
2013-06-13 18:11:10 -04:00
|
|
|
|
2014-04-09 13:26:19 -04:00
|
|
|
describe ".execute" do
|
|
|
|
|
2014-08-26 19:52:35 -04:00
|
|
|
it "does no polling if pop3_polling_enabled is false" do
|
2016-01-18 18:57:55 -05:00
|
|
|
SiteSetting.expects(:pop3_polling_enabled).returns(false)
|
2014-08-26 19:52:35 -04:00
|
|
|
poller.expects(:poll_pop3).never
|
2014-04-09 13:26:19 -04:00
|
|
|
poller.execute({})
|
|
|
|
end
|
|
|
|
|
2016-01-18 18:57:55 -05: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-09 13:26:19 -04:00
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-08-26 19:52:35 -04:00
|
|
|
describe ".poll_pop3" do
|
2014-04-09 13:26:19 -04:00
|
|
|
|
2014-06-30 18:16:16 -04:00
|
|
|
it "logs an error on pop authentication error" do
|
2016-01-18 18:57:55 -05:00
|
|
|
Net::POP3.any_instance.expects(:start).raises(Net::POPAuthenticationError.new)
|
2015-02-09 15:47:46 -05:00
|
|
|
Discourse.expects(:handle_job_exception)
|
2014-08-26 19:52:35 -04:00
|
|
|
poller.poll_pop3
|
2014-04-09 13:26:19 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:00:27 -04: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-01-18 18:57:55 -05:00
|
|
|
it "does not call enable_ssl when the setting is disabled" do
|
2014-08-26 20:00:27 -04: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-09 13:26:19 -04:00
|
|
|
end
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|