demarches-normaliennes/spec/controllers/users/registrations_controller_spec.rb

50 lines
1.4 KiB
Ruby
Raw Normal View History

describe Users::RegistrationsController, type: :controller do
let(:email) { 'test@octo.com' }
let(:password) { 'password' }
2017-06-21 14:20:22 +02:00
let(:user) { { email: email, password: password } }
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
describe '#create' do
subject do
post :create, params: { user: user }
end
2016-01-04 16:09:04 +01:00
context 'when user is correct' do
it 'sends confirmation instruction' do
2018-05-26 00:06:40 +02:00
message = double()
expect(DeviseUserMailer).to receive(:confirmation_instructions).and_return(message)
expect(message).to receive(:deliver_later)
2016-01-04 16:09:04 +01:00
subject
end
end
context 'when user is not correct' do
2017-06-21 14:20:22 +02:00
let(:user) { { email: '', password: password } }
2016-01-04 16:09:04 +01:00
it 'not sends confirmation instruction' do
expect(DeviseUserMailer).not_to receive(:confirmation_instructions)
2016-01-04 16:09:04 +01:00
subject
end
end
context 'when the user already exists' do
let!(:existing_user) { create(:user, email: email, password: password) }
before do
2018-06-07 15:07:14 +02:00
allow(UserMailer).to receive(:new_account_warning).and_return(double(deliver_later: 'deliver'))
subject
end
it { expect(response).to redirect_to(root_path) }
it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) }
it { expect(UserMailer).to have_received(:new_account_warning) }
end
end
end