2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-06-03 16:12:24 -04:00
|
|
|
|
|
|
|
describe Admin::EmailController do
|
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Admin::EmailController < Admin::AdminController).to eq(true)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:user) { log_in(:admin) }
|
|
|
|
|
|
|
|
context '.index' do
|
|
|
|
before do
|
2013-06-11 19:00:13 -04:00
|
|
|
subject.expects(:action_mailer_settings).returns({
|
|
|
|
username: 'username',
|
|
|
|
password: 'secret'
|
|
|
|
})
|
|
|
|
|
2013-06-03 16:12:24 -04:00
|
|
|
xhr :get, :index
|
|
|
|
end
|
|
|
|
|
2013-06-11 19:00:13 -04:00
|
|
|
it 'does not include the password in the response' do
|
|
|
|
mail_settings = JSON.parse(response.body)['settings']
|
|
|
|
|
|
|
|
expect(
|
|
|
|
mail_settings.select { |setting| setting['name'] == 'password' }
|
|
|
|
).to be_empty
|
|
|
|
end
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
2014-02-14 18:50:08 -05:00
|
|
|
context '.sent' do
|
2013-06-03 16:12:24 -04:00
|
|
|
before do
|
2014-02-14 18:50:08 -05:00
|
|
|
xhr :get, :sent
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-09 12:04:02 -05:00
|
|
|
it { is_expected.to be_success }
|
2014-02-14 18:50:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.skipped' do
|
|
|
|
before do
|
|
|
|
xhr :get, :skipped
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-09 12:04:02 -05:00
|
|
|
it { is_expected.to be_success }
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.test' do
|
|
|
|
it 'raises an error without the email parameter' do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect { xhr :post, :test }.to raise_error(ActionController::ParameterMissing)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an email address' do
|
|
|
|
it 'enqueues a test email job' do
|
2014-01-09 16:31:26 -05:00
|
|
|
job_mock = mock
|
|
|
|
Jobs::TestEmail.expects(:new).returns(job_mock)
|
|
|
|
job_mock.expects(:execute).with(to_address: 'eviltrout@test.domain')
|
2013-06-03 16:12:24 -04:00
|
|
|
xhr :post, :test, email_address: 'eviltrout@test.domain'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '.preview_digest' do
|
|
|
|
it 'raises an error without the last_seen_at parameter' do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect { xhr :get, :preview_digest }.to raise_error(ActionController::ParameterMissing)
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "previews the digest" do
|
2015-10-30 14:05:54 -04:00
|
|
|
xhr :get, :preview_digest, last_seen_at: 1.week.ago, username: user.username
|
2013-06-03 16:12:24 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-24 00:06:28 -04:00
|
|
|
context '#handle_mail' do
|
|
|
|
before do
|
|
|
|
log_in_user(Fabricate(:admin))
|
|
|
|
SiteSetting.queue_jobs = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should enqueue the right job' do
|
|
|
|
expect { xhr :post, :handle_mail, email: email('cc') }
|
|
|
|
.to change { Jobs::ProcessEmail.jobs.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|