2015-12-15 15:17:12 +01:00
|
|
|
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 } }
|
2015-12-15 15:17:12 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
describe '#create' do
|
2017-06-21 14:20:22 +02:00
|
|
|
subject { post :create, params: { user: user } }
|
2015-12-15 15:17:12 +01:00
|
|
|
|
2016-01-04 16:09:04 +01:00
|
|
|
context 'when user is correct' do
|
2016-01-19 17:19:38 +01:00
|
|
|
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!)
|
2015-12-15 15:17:12 +01:00
|
|
|
|
2016-01-04 16:09:04 +01:00
|
|
|
subject
|
|
|
|
end
|
2016-02-09 15:47:36 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-01-19 17:19:38 +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
|
2015-12-15 15:17:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|