2016-04-01 05:33:25 +08:00
|
|
|
require 'rails_helper'
|
2013-06-04 04:12:24 +08:00
|
|
|
|
|
|
|
describe Admin::EmailController do
|
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(Admin::EmailController < Admin::AdminController).to eq(true)
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:user) { log_in(:admin) }
|
|
|
|
|
|
|
|
context '.index' do
|
|
|
|
before do
|
2013-06-12 07:00:13 +08:00
|
|
|
subject.expects(:action_mailer_settings).returns({
|
|
|
|
username: 'username',
|
|
|
|
password: 'secret'
|
|
|
|
})
|
|
|
|
|
2013-06-04 04:12:24 +08:00
|
|
|
xhr :get, :index
|
|
|
|
end
|
|
|
|
|
2013-06-12 07:00:13 +08: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-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
2014-02-15 07:50:08 +08:00
|
|
|
context '.sent' do
|
2013-06-04 04:12:24 +08:00
|
|
|
before do
|
2014-02-15 07:50:08 +08:00
|
|
|
xhr :get, :sent
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-10 01:04:02 +08:00
|
|
|
it { is_expected.to be_success }
|
2014-02-15 07:50:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.skipped' do
|
|
|
|
before do
|
|
|
|
xhr :get, :skipped
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { response }
|
2015-01-10 01:04:02 +08:00
|
|
|
it { is_expected.to be_success }
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.test' do
|
|
|
|
it 'raises an error without the email parameter' do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect { xhr :post, :test }.to raise_error(ActionController::ParameterMissing)
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an email address' do
|
|
|
|
it 'enqueues a test email job' do
|
2014-01-10 05:31:26 +08:00
|
|
|
job_mock = mock
|
|
|
|
Jobs::TestEmail.expects(:new).returns(job_mock)
|
|
|
|
job_mock.expects(:execute).with(to_address: 'eviltrout@test.domain')
|
2013-06-04 04:12:24 +08: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-10 01:04:02 +08:00
|
|
|
expect { xhr :get, :preview_digest }.to raise_error(ActionController::ParameterMissing)
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "previews the digest" do
|
2016-04-01 05:33:25 +08:00
|
|
|
xhr :get, :preview_digest, last_seen_at: 1.week.ago, username: user.username
|
2013-06-04 04:12:24 +08:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|