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

49 lines
1.2 KiB
Ruby
Raw Normal View History

require 'spec_helper'
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
2017-06-21 14:20:22 +02:00
subject { post :create, params: { user: user } }
2016-01-04 16:09:04 +01:00
context 'when user is correct' do
it 'sends welcome email' do
2016-01-04 16:09:04 +01:00
expect(WelcomeMailer).to receive(:welcome_email).and_return(WelcomeMailer)
expect(WelcomeMailer).to receive(:deliver_now!)
2016-01-04 16:09:04 +01:00
subject
end
describe '#check_invite!' do
let!(:invite) { create :invite, email: email }
let!(:invite2) { create :invite, email: email }
before do
subject
end
it 'the new user is connect at his two invite' do
expect(User.last.invites.size).to eq 2
end
end
2016-01-04 16:09:04 +01:00
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 welcome email' do
2016-01-04 16:09:04 +01:00
expect(WelcomeMailer).not_to receive(:welcome_email)
subject
end
end
end
end