discourse/spec/controllers/admin/email_controller_spec.rb

75 lines
1.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
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)
end
let!(:user) { log_in(:admin) }
context '.index' do
before do
subject.expects(:action_mailer_settings).returns({
username: 'username',
password: 'secret'
})
xhr :get, :index
end
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
end
2014-02-14 18:50:08 -05:00
context '.sent' do
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
end
subject { response }
2015-01-09 12:04:02 -05:00
it { is_expected.to be_success }
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)
end
context 'with an email address' do
it 'enqueues a test email job' do
job_mock = mock
Jobs::TestEmail.expects(:new).returns(job_mock)
job_mock.expects(:execute).with(to_address: 'eviltrout@test.domain')
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)
end
it "previews the digest" do
xhr :get, :preview_digest, last_seen_at: 1.week.ago, username: user.username
expect(response).to be_success
end
end
end