Merge pull request #4187 from betagouv/add_admin_creation_spec

add admin creation spec
This commit is contained in:
LeSim 2019-08-12 14:50:41 +02:00 committed by GitHub
commit af847f47fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 20 deletions

View file

@ -2,7 +2,8 @@ class Administrateurs::ActivateController < ApplicationController
include TrustedDeviceConcern
def new
@administrateur = Administrateur.find_inactive_by_token(params[:token])
@token = params[:token]
@administrateur = Administrateur.find_inactive_by_token(@token)
if @administrateur
# the administrateur activates its account from an email

View file

@ -3,4 +3,20 @@
- content_for :footer do
= render partial: "root/footer"
= render 'shared/password/new', object: @administrateur, controller: 'administrateurs/activate', test_password_strength: administrateurs_password_test_strength_path
.container.devise-container
.one-column-centered
= form_for @administrateur, url: { controller: 'administrateurs/activate', action: :create }, html: { class: "form" } do |f|
%br
%h1
Choix du mot de passe
= f.hidden_field :reset_password_token, value: @token
= f.label :email, "Email"
= f.text_field :email, disabled: true
= f.label :password do
Mot de passe
= render partial: 'shared/password/edit_password', locals: { form: f, controller: 'administrateurs/passwords' }
= f.submit 'Continuer', class: 'button large primary expand', id: "submit-password", data: { disable_with: "Envoi..." }

View file

@ -1,18 +0,0 @@
.container.devise-container
.one-column-centered
- controller_action = defined?(action) ? action : :create
= form_for object, url: { controller: controller, action: controller_action }, html: { class: "form" } do |f|
%br
%h1
Choix du mot de passe
= f.hidden_field :reset_password_token, value: object.reset_password_token
= f.label :email, "Email"
= f.text_field :email, disabled: true
= f.label :password do
Mot de passe
= render partial: 'shared/password/edit_password', locals: { form: f, controller: controller }
= f.submit 'Continuer', class: 'button large primary expand', id: "submit-password", data: { disable_with: "Envoi..." }

View file

@ -0,0 +1,24 @@
require 'spec_helper'
feature 'As an administrateur', js: true do
let(:administration) { create(:administration) }
let(:admin_email) { 'new_admin@gouv.fr' }
before do
perform_enqueued_jobs do
administration.invite_admin(admin_email)
end
end
scenario 'I can register' do
confirmation_email = open_email(admin_email)
token_params = confirmation_email.body.match(/token=[^"]+/)
visit "admin/activate?#{token_params}"
fill_in :administrateur_password, with: 'démarches-simplifiées-pwd'
click_button 'Continuer'
expect(page).to have_content 'Mot de passe enregistré'
end
end