mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 06:15:28 +08:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
75 lines
1.7 KiB
Ruby
75 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Admin::EmailController do
|
|
|
|
it "is a subclass of AdminController" do
|
|
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
|
|
|
|
context '.sent' do
|
|
before do
|
|
xhr :get, :sent
|
|
end
|
|
|
|
subject { response }
|
|
it { is_expected.to be_success }
|
|
end
|
|
|
|
context '.skipped' do
|
|
before do
|
|
xhr :get, :skipped
|
|
end
|
|
|
|
subject { response }
|
|
it { is_expected.to be_success }
|
|
end
|
|
|
|
context '.test' do
|
|
it 'raises an error without the email parameter' do
|
|
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
|
|
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
|