demarches-normaliennes/spec/controllers/administrateurs/activate_controller_spec.rb

48 lines
1.6 KiB
Ruby
Raw Normal View History

2018-10-30 18:24:29 +01:00
describe Administrateurs::ActivateController, type: :controller do
describe '#new' do
let(:admin) { create(:administrateur) }
2019-08-09 11:41:36 +02:00
let(:token) { admin.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
describe '#create' do
let!(:administrateur) { create(:administrateur) }
let(:token) { administrateur.user.send(:set_reset_password_token) }
let(:password) { 'Another-password-ok!@#123?' }
before { post :create, params: { administrateur: { reset_password_token: token, password: password } } }
context 'when the token is ok' do
it { expect(administrateur.user.reload.valid_password?(password)).to be true }
it { expect(response).to redirect_to(admin_procedures_path) }
end
context 'when the password is not strong' do
let(:password) { 'another-password-ok?' }
it { expect(administrateur.user.reload.valid_password?(password)).to be false }
it { expect(response).to redirect_to(admin_activate_path(token: token)) }
end
context 'when the token is bad' do
let(:token) { 'bad' }
it { expect(administrateur.user.reload.valid_password?(password)).to be false }
it { expect(response).to redirect_to(admin_activate_path(token: token)) }
end
end
2018-10-30 18:24:29 +01:00
end