invite: fix prefilling the invited user email
This commit is contained in:
parent
bfa2a4b89d
commit
e5f4056fe2
6 changed files with 52 additions and 6 deletions
|
@ -3,7 +3,7 @@ class Users::Dossiers::InvitesController < UsersController
|
||||||
session["user_return_to"] = request.fullpath
|
session["user_return_to"] = request.fullpath
|
||||||
|
|
||||||
if params[:email].present? && User.find_by(email: params[:email]).nil?
|
if params[:email].present? && User.find_by(email: params[:email]).nil?
|
||||||
return redirect_to new_user_registration_path(user_email: params[:email])
|
return redirect_to new_user_registration_path(user: { email: params[:email] })
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
|
@ -9,9 +9,13 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# GET /resource/sign_up
|
# GET /resource/sign_up
|
||||||
# def new
|
def new
|
||||||
# super
|
# Allow pre-filling the user email from a query parameter
|
||||||
# end
|
build_resource({ email: sign_up_params[:email] })
|
||||||
|
|
||||||
|
yield resource if block_given?
|
||||||
|
respond_with resource
|
||||||
|
end
|
||||||
|
|
||||||
# POST /resource
|
# POST /resource
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
.column.auth-form
|
.column.auth-form
|
||||||
= devise_error_messages!
|
= devise_error_messages!
|
||||||
= form_for User.new, url: user_registration_path, html: { class: "form" } do |f|
|
= form_for resource, url: user_registration_path, html: { class: "form" } do |f|
|
||||||
%h1 Créez-vous un compte
|
%h1 Créez-vous un compte
|
||||||
|
|
||||||
= f.label :email, "Email"
|
= f.label :email, "Email"
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe Users::Dossiers::InvitesController, type: :controller do
|
||||||
|
|
||||||
context 'when email is not affected at an user' do
|
context 'when email is not affected at an user' do
|
||||||
let(:email) { 'new_user@octo.com' }
|
let(:email) { 'new_user@octo.com' }
|
||||||
it { is_expected.to redirect_to new_user_registration_path(user_email: email) }
|
it { is_expected.to redirect_to new_user_registration_path(user: { email: email }) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,22 @@ describe Users::RegistrationsController, type: :controller do
|
||||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#new' do
|
||||||
|
subject! { get :new }
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:ok) }
|
||||||
|
it { expect(response).to render_template(:new) }
|
||||||
|
|
||||||
|
context 'when an email address is provided' do
|
||||||
|
render_views true
|
||||||
|
subject! { get :new, params: { user: { email: 'test@exemple.fr' } } }
|
||||||
|
|
||||||
|
it 'prefills the form with the email address' do
|
||||||
|
expect(response.body).to include('test@exemple.fr')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
subject do
|
subject do
|
||||||
post :create, params: { user: user }
|
post :create, params: { user: user }
|
||||||
|
|
|
@ -24,6 +24,32 @@ feature 'Invitations' do
|
||||||
expect(page).to have_field('Libelle du champ', with: 'Some edited value')
|
expect(page).to have_field('Libelle du champ', with: 'Some edited value')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when inviting someone without an existing account' do
|
||||||
|
let(:invite) { create(:invite_user, dossier: dossier, user: nil) }
|
||||||
|
let(:user_password) { 'l33tus3r' }
|
||||||
|
|
||||||
|
scenario 'an invited user can register using the registration link sent in the invitation email' do
|
||||||
|
# Click the invitation link
|
||||||
|
visit users_dossiers_invite_path(invite.id, params: { email: invite.email })
|
||||||
|
|
||||||
|
# Create the account
|
||||||
|
expect(page).to have_current_path(new_user_registration_path, ignore_query: true)
|
||||||
|
expect(page).to have_field('user_email', with: invite.email)
|
||||||
|
fill_in 'user_password', with: user_password
|
||||||
|
click_on 'Créer un compte'
|
||||||
|
|
||||||
|
expect(page).to have_content('lien de confirmation')
|
||||||
|
|
||||||
|
# Confirm the email
|
||||||
|
user = User.find_by(email: invite.email)
|
||||||
|
visit Rails.application.routes.url_helpers.user_confirmation_path(confirmation_token: user.confirmation_token)
|
||||||
|
submit_login_form(user.email, user_password)
|
||||||
|
|
||||||
|
# The user should be redirected to the dossier they was invited on
|
||||||
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'an invited user can see and edit the draft', js: true do
|
scenario 'an invited user can see and edit the draft', js: true do
|
||||||
visit users_dossiers_invite_path(invite)
|
visit users_dossiers_invite_path(invite)
|
||||||
expect(page).to have_current_path(new_user_session_path)
|
expect(page).to have_current_path(new_user_session_path)
|
||||||
|
|
Loading…
Reference in a new issue