2019-08-07 15:52:38 +02:00
|
|
|
describe Users::ActivateController, type: :controller do
|
2018-10-30 18:24:29 +01:00
|
|
|
describe '#new' do
|
2019-08-07 15:52:38 +02:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:token) { user.send(:set_reset_password_token) }
|
2018-10-30 18:24:29 +01:00
|
|
|
|
|
|
|
before { allow(controller).to receive(:trust_device) }
|
|
|
|
|
|
|
|
context 'when the token is ok' do
|
|
|
|
before { get :new, params: { token: token } }
|
|
|
|
|
|
|
|
it { expect(controller).to have_received(:trust_device) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the token is bad' do
|
|
|
|
before { get :new, params: { token: 'bad' } }
|
|
|
|
|
|
|
|
it { expect(controller).not_to have_received(:trust_device) }
|
|
|
|
end
|
|
|
|
end
|
2019-08-11 19:22:03 +02:00
|
|
|
|
|
|
|
describe '#create' do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let(:token) { user.send(:set_reset_password_token) }
|
|
|
|
let(:password) { 'another-password-ok?' }
|
|
|
|
|
|
|
|
before { post :create, params: { user: { reset_password_token: token, password: password } } }
|
|
|
|
|
|
|
|
context 'when the token is ok' do
|
|
|
|
it { expect(user.reload.valid_password?(password)).to be true }
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedures_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the token is bad' do
|
|
|
|
let(:token) { 'bad' }
|
|
|
|
|
|
|
|
it { expect(user.reload.valid_password?(password)).to be false }
|
|
|
|
it { expect(response).to redirect_to(users_activate_path(token: token)) }
|
|
|
|
end
|
|
|
|
end
|
2018-10-30 18:24:29 +01:00
|
|
|
end
|