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

81 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
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
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 }
before do
@token = user.send(:set_reset_password_token)
administrateur # make sure it's created
end
it "also signs instructeur in" do
2018-01-15 19:02:12 +01:00
put :update, params: {
user: {
reset_password_token: @token,
password: "mot de passe super secret",
password_confirmation: "mot de passe super secret"
2018-01-15 19:02:12 +01:00
}
}
expect(subject.current_user).to eq(user)
expect(subject.current_instructeur.email).to eq(administrateur.email)
end
it "also signs administrateur in" do
2018-01-15 19:02:12 +01:00
put :update, params: {
user: {
reset_password_token: @token,
password: "mot de passe super secret",
password_confirmation: "mot de passe super secret"
2018-01-15 19:02:12 +01:00
}
}
expect(subject.current_user).to eq(user)
expect(subject.current_administrateur).to eq(administrateur)
end
it "marks user's email as verified" do
expect do
put :update, params: {
user: {
reset_password_token: @token,
password: "mot de passe super secret",
password_confirmation: "mot de passe super secret"
}
}
end.to change { user.reload.email_verified_at }
.from(nil).to(anything)
end
end
end
describe '#reset_link_sent' do
let(:email) { 'test@example.com' }
it 'displays the page' do
signed_email = controller.message_verifier.generate(email, purpose: :reset_password)
get 'reset_link_sent', params: { email: signed_email }
expect(response).to have_http_status(:ok)
expect(response).to render_template('reset_link_sent')
expect(assigns(:email)).to eq email
end
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
end
end