2016-10-13 18:26:08 +02:00
|
|
|
describe Users::PasswordsController, type: :controller do
|
|
|
|
before do
|
|
|
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update" do
|
2016-10-18 15:49:04 +02:00
|
|
|
context "unified login" do
|
2018-01-25 10:50:06 +01:00
|
|
|
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'mot de passe complexe') }
|
2019-08-08 16:55:51 +02:00
|
|
|
let(:user) { administrateur.instructeur.user }
|
2016-10-13 18:26:08 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
@token = user.send(:set_reset_password_token)
|
2016-12-07 17:35:45 +01:00
|
|
|
administrateur # make sure it's created
|
2016-10-13 18:26:08 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it "also signs instructeur in" do
|
2018-01-15 19:02:12 +01:00
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
reset_password_token: @token,
|
2018-01-25 10:50:06 +01:00
|
|
|
password: "mot de passe super secret",
|
2018-10-01 14:06:08 +02:00
|
|
|
password_confirmation: "mot de passe super secret"
|
2018-01-15 19:02:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-13 18:26:08 +02:00
|
|
|
expect(subject.current_user).to eq(user)
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(subject.current_instructeur.email).to eq(administrateur.email)
|
2016-10-13 18:26:08 +02:00
|
|
|
end
|
2016-12-07 17:35:45 +01:00
|
|
|
|
|
|
|
it "also signs administrateur in" do
|
2018-01-15 19:02:12 +01:00
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
reset_password_token: @token,
|
2018-01-25 10:50:06 +01:00
|
|
|
password: "mot de passe super secret",
|
2018-10-01 14:06:08 +02:00
|
|
|
password_confirmation: "mot de passe super secret"
|
2018-01-15 19:02:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 17:35:45 +01:00
|
|
|
expect(subject.current_user).to eq(user)
|
|
|
|
expect(subject.current_administrateur).to eq(administrateur)
|
|
|
|
end
|
2016-10-13 18:26:08 +02:00
|
|
|
end
|
|
|
|
end
|
2021-04-22 12:07:35 +02:00
|
|
|
|
|
|
|
describe '#reset_link_sent' do
|
|
|
|
let(:email) { 'test@example.com' }
|
|
|
|
|
|
|
|
it 'displays the page' do
|
2024-02-27 18:46:06 +01:00
|
|
|
signed_email = controller.message_verifier.generate(email, purpose: :reset_password)
|
|
|
|
|
|
|
|
get 'reset_link_sent', params: { email: signed_email }
|
2021-04-22 12:07:35 +02:00
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(response).to render_template('reset_link_sent')
|
|
|
|
expect(assigns(:email)).to eq email
|
|
|
|
end
|
2024-02-27 18:46:06 +01:00
|
|
|
|
|
|
|
context 'when signed email is invalid' do
|
|
|
|
it "does not fail" do
|
|
|
|
get 'reset_link_sent', params: { email: "invalid.message" }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(response).to render_template('reset_link_sent')
|
|
|
|
expect(assigns(:email)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2021-04-22 12:07:35 +02:00
|
|
|
end
|
2016-10-13 18:26:08 +02:00
|
|
|
end
|