commit
f9377a6594
26 changed files with 89 additions and 206 deletions
|
@ -22,7 +22,11 @@ module Manager
|
|||
def delete
|
||||
administrateur = Administrateur.find(params[:id])
|
||||
|
||||
administrateur.delete_and_transfer_services
|
||||
if !administrateur.can_be_deleted?
|
||||
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
||||
end
|
||||
administrateur.dossiers.each(&:delete_and_keep_track)
|
||||
administrateur.destroy
|
||||
|
||||
logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_administration.id}")
|
||||
flash[:notice] = "L'administrateur #{administrateur.id} est supprimé"
|
||||
|
|
|
@ -6,19 +6,5 @@ module Manager
|
|||
flash[:notice] = "Instructeur réinvité."
|
||||
redirect_to manager_instructeur_path(instructeur)
|
||||
end
|
||||
|
||||
def delete
|
||||
instructeur = Instructeur.find(params[:id])
|
||||
|
||||
if !instructeur.can_be_deleted?
|
||||
fail "Impossible de supprimer cet instructeur car il est administrateur ou il est le seul instructeur sur une démarche"
|
||||
end
|
||||
instructeur.destroy!
|
||||
|
||||
logger.info("L'instructeur #{instructeur.id} est supprimé par #{current_administration.id}")
|
||||
flash[:notice] = "L'instructeur #{instructeur.id} est supprimé"
|
||||
|
||||
redirect_to manager_instructeurs_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ module Manager
|
|||
def delete
|
||||
user = User.find(params[:id])
|
||||
if !user.can_be_deleted?
|
||||
fail "Impossible de supprimer cet utilisateur. Il a des dossiers en instruction ou il est administrateur."
|
||||
fail "Impossible de supprimer cet utilisateur car il a des dossiers en instruction"
|
||||
end
|
||||
user.delete_and_keep_track_dossiers(current_administration)
|
||||
|
||||
|
|
|
@ -70,17 +70,4 @@ class Administrateur < ApplicationRecord
|
|||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.none? && procedures.all? { |p| p.administrateurs.count > 1 }
|
||||
end
|
||||
|
||||
def delete_and_transfer_services
|
||||
if !can_be_deleted?
|
||||
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
||||
end
|
||||
dossiers.each(&:delete_and_keep_track)
|
||||
|
||||
procedures.each do |procedure|
|
||||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||
procedure.service.update(administrateur: next_administrateur)
|
||||
end
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,9 +17,9 @@ class Instructeur < ApplicationRecord
|
|||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :avis
|
||||
has_many :dossiers_from_avis, through: :avis, source: :dossier
|
||||
has_many :trusted_device_tokens, dependent: :destroy
|
||||
has_many :trusted_device_tokens
|
||||
|
||||
has_one :user, dependent: :nullify
|
||||
has_one :user
|
||||
|
||||
default_scope { eager_load(:user) }
|
||||
|
||||
|
@ -176,10 +176,6 @@ class Instructeur < ApplicationRecord
|
|||
trusted_device_token&.token_young?
|
||||
end
|
||||
|
||||
def can_be_deleted?
|
||||
user.administrateur.nil? && procedures.all? { |p| p.defaut_groupe_instructeur.instructeurs.count > 1 }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def annotations_hash(demande, annotations_privees, avis, messagerie)
|
||||
|
|
|
@ -97,7 +97,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_deleted?
|
||||
administrateur.nil? && instructeur.nil? && dossiers.state_instruction_commencee.empty?
|
||||
dossiers.state_instruction_commencee.empty?
|
||||
end
|
||||
|
||||
def delete_and_keep_track_dossiers(administration)
|
||||
|
@ -105,11 +105,12 @@ class User < ApplicationRecord
|
|||
raise "Cannot delete this user because instruction has started for some dossiers"
|
||||
end
|
||||
|
||||
if can_be_deleted?
|
||||
dossiers.each do |dossier|
|
||||
dossier.delete_and_keep_track(administration)
|
||||
end
|
||||
dossiers.unscoped.destroy_all
|
||||
destroy!
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
.site-banner-icon ⚠️
|
||||
.site-banner-text
|
||||
%strong
|
||||
En raison d’une grève nationale interprofessionnelle, une partie des personnels ne travaille pas.
|
||||
En raison d’une grève nationale interprofessionnelle, une partie du personnel de demarches-simplifiees.fr ne travaille pas.
|
||||
%br
|
||||
Les délais de réponse aux questions techniques pourront être perturbés pendant les prochains jours.
|
||||
|
|
|
@ -34,10 +34,7 @@ as well as a link to its edit page.
|
|||
|
||||
<div>
|
||||
<%= link_to 'Réinviter', reinvite_manager_instructeur_path(instructeur), method: :post, class: 'button' %>
|
||||
</div>
|
||||
<div>
|
||||
<%= button_to "Supprimer", delete_manager_instructeur_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'instructeur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet instructeur est administrateur ou a des démarches dont il est le seul instructeur et ne peut être supprimé" %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="main-content__body">
|
||||
|
|
|
@ -25,7 +25,7 @@ as well as a link to its edit page.
|
|||
</h1>
|
||||
|
||||
<div>
|
||||
<%= button_to "supprimer", delete_manager_user_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'utilisateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet utilisateur ne peut être supprimé. Il a des dossiers dont l'instruction a commencé ou il est administrateur ou instructeur" %>
|
||||
<%= button_to "supprimer", delete_manager_user_path(page.resource), method: :delete, disabled: !page.resource.can_be_deleted?, class: "button", data: { confirm: "Confirmez-vous la suppression de l'utilisateur ?" }, title: page.resource.can_be_deleted? ? "Supprimer" : "Cet utilisateur a des dossiers dont l'instruction a commencé et ne peut être supprimé" %>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -32,7 +32,6 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :instructeurs, only: [:index, :show] do
|
||||
post 'reinvite', on: :member
|
||||
delete 'delete', on: :member
|
||||
end
|
||||
|
||||
resources :dossiers, only: [:show]
|
||||
|
|
|
@ -8,14 +8,14 @@ describe API::V2::GraphqlController do
|
|||
dossier = create(:dossier,
|
||||
:en_construction,
|
||||
:with_all_champs,
|
||||
:for_individual,
|
||||
:with_individual,
|
||||
procedure: procedure)
|
||||
create(:commentaire, :with_file, dossier: dossier, email: 'test@test.com')
|
||||
dossier
|
||||
end
|
||||
let(:dossier1) { create(:dossier, :en_construction, :for_individual, procedure: procedure, en_construction_at: 1.day.ago) }
|
||||
let(:dossier2) { create(:dossier, :en_construction, :for_individual, procedure: procedure, en_construction_at: 3.days.ago) }
|
||||
let(:dossier_brouillon) { create(:dossier, :for_individual, procedure: procedure) }
|
||||
let(:dossier1) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 1.day.ago) }
|
||||
let(:dossier2) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 3.days.ago) }
|
||||
let(:dossier_brouillon) { create(:dossier, :with_individual, procedure: procedure) }
|
||||
let(:dossiers) { [dossier2, dossier1, dossier] }
|
||||
let(:instructeur) { create(:instructeur, followed_dossiers: dossiers) }
|
||||
|
||||
|
@ -288,8 +288,8 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
context "with entreprise" do
|
||||
let(:procedure) { create(:procedure, :published, administrateurs: [admin]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) }
|
||||
let(:procedure_for_entreprise) { create(:procedure, :published, administrateurs: [admin]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure_for_entreprise) }
|
||||
|
||||
let(:query) do
|
||||
"{
|
||||
|
@ -416,7 +416,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
describe 'dossierPasserEnInstruction' do
|
||||
let(:dossier) { create(:dossier, :en_construction, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierPasserEnInstruction(input: {
|
||||
|
@ -451,7 +451,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
context 'validation error' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||
|
||||
it "should fail" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
@ -464,7 +464,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
describe 'dossierClasserSansSuite' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierClasserSansSuite(input: {
|
||||
|
@ -501,7 +501,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
context 'validation error' do
|
||||
let(:dossier) { create(:dossier, :accepte, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) }
|
||||
|
||||
it "should fail" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
@ -514,7 +514,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
describe 'dossierRefuser' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierRefuser(input: {
|
||||
|
@ -551,7 +551,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
context 'validation error' do
|
||||
let(:dossier) { create(:dossier, :sans_suite, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :sans_suite, :with_individual, procedure: procedure) }
|
||||
|
||||
it "should fail" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
@ -564,7 +564,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
describe 'dossierAccepter' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierAccepter(input: {
|
||||
|
@ -634,7 +634,7 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
|
||||
context 'validation error' do
|
||||
let(:dossier) { create(:dossier, :refuse, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :refuse, :with_individual, procedure: procedure) }
|
||||
|
||||
it "should fail" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
|
|
@ -256,10 +256,10 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
get :show, params: { procedure_id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier]) }
|
||||
it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier]) }
|
||||
it { expect(assigns(:followed_dossiers)).to be_empty }
|
||||
it { expect(assigns(:termines_dossiers)).to be_empty }
|
||||
it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match_array([new_unfollow_dossier]) }
|
||||
it { expect(assigns(:archived_dossiers)).to be_empty }
|
||||
|
||||
context 'and dossiers without follower on each of the others groups' do
|
||||
|
@ -270,8 +270,8 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
get :show, params: { procedure_id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -284,9 +284,9 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
||||
it { expect(assigns(:followed_dossiers)).to match([new_followed_dossier]) }
|
||||
it { expect(assigns(:followed_dossiers)).to match_array([new_followed_dossier]) }
|
||||
it { expect(assigns(:termines_dossiers)).to be_empty }
|
||||
it { expect(assigns(:all_state_dossiers)).to match([new_followed_dossier]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match_array([new_followed_dossier]) }
|
||||
it { expect(assigns(:archived_dossiers)).to be_empty }
|
||||
|
||||
context 'and dossier with a follower on each of the others groups' do
|
||||
|
@ -313,8 +313,8 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
|
||||
it { expect(assigns(:a_suivre_dossiers)).to be_empty }
|
||||
it { expect(assigns(:followed_dossiers)).to be_empty }
|
||||
it { expect(assigns(:termines_dossiers)).to match([termine_dossier]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match([termine_dossier]) }
|
||||
it { expect(assigns(:termines_dossiers)).to match_array([termine_dossier]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match_array([termine_dossier]) }
|
||||
it { expect(assigns(:archived_dossiers)).to be_empty }
|
||||
|
||||
context 'and terminer dossiers on each of the others groups' do
|
||||
|
@ -325,8 +325,8 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
get :show, params: { procedure_id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(assigns(:termines_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:termines_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:all_state_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -341,7 +341,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
it { expect(assigns(:followed_dossiers)).to be_empty }
|
||||
it { expect(assigns(:termines_dossiers)).to be_empty }
|
||||
it { expect(assigns(:all_state_dossiers)).to be_empty }
|
||||
it { expect(assigns(:archived_dossiers)).to match([archived_dossier]) }
|
||||
it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier]) }
|
||||
|
||||
context 'and terminer dossiers on each of the others groups' do
|
||||
let!(:archived_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction), archived: true) }
|
||||
|
@ -351,7 +351,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
get :show, params: { procedure_id: procedure.id }
|
||||
end
|
||||
|
||||
it { expect(assigns(:archived_dossiers)).to match([archived_dossier, archived_dossier_on_gi_2]) }
|
||||
it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier, archived_dossier_on_gi_2]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -369,7 +369,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
context 'when statut is empty' do
|
||||
let(:statut) { nil }
|
||||
|
||||
it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) }
|
||||
it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier]) }
|
||||
it { expect(assigns(:statut)).to eq('a-suivre') }
|
||||
end
|
||||
|
||||
|
@ -377,21 +377,21 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
let(:statut) { 'a-suivre' }
|
||||
|
||||
it { expect(assigns(:statut)).to eq('a-suivre') }
|
||||
it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) }
|
||||
it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier]) }
|
||||
end
|
||||
|
||||
context 'when statut is suivis' do
|
||||
let(:statut) { 'suivis' }
|
||||
|
||||
it { expect(assigns(:statut)).to eq('suivis') }
|
||||
it { expect(assigns(:dossiers)).to match([new_followed_dossier]) }
|
||||
it { expect(assigns(:dossiers)).to match_array([new_followed_dossier]) }
|
||||
end
|
||||
|
||||
context 'when statut is traites' do
|
||||
let(:statut) { 'traites' }
|
||||
|
||||
it { expect(assigns(:statut)).to eq('traites') }
|
||||
it { expect(assigns(:dossiers)).to match([termine_dossier]) }
|
||||
it { expect(assigns(:dossiers)).to match_array([termine_dossier]) }
|
||||
end
|
||||
|
||||
context 'when statut is tous' do
|
||||
|
@ -405,7 +405,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
let(:statut) { 'archives' }
|
||||
|
||||
it { expect(assigns(:statut)).to eq('archives') }
|
||||
it { expect(assigns(:dossiers)).to match([archived_dossier]) }
|
||||
it { expect(assigns(:dossiers)).to match_array([archived_dossier]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
describe Manager::InstructeursController, type: :controller do
|
||||
let(:administration) { create(:administration) }
|
||||
|
||||
describe '#delete' do
|
||||
let!(:instructeur) { create(:instructeur) }
|
||||
|
||||
before { sign_in administration }
|
||||
|
||||
subject { delete :delete, params: { id: instructeur.id } }
|
||||
|
||||
it 'deletes the instructeur' do
|
||||
subject
|
||||
|
||||
expect(Instructeur.find_by(id: instructeur.id)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -170,7 +170,7 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the identite cannot be updated by the user' do
|
||||
let(:dossier) { create(:dossier, :for_individual, :en_instruction, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :with_individual, :en_instruction, user: user, procedure: procedure) }
|
||||
let(:individual_params) { { gender: 'M', nom: 'Mouse', prenom: 'Mickey' } }
|
||||
|
||||
it 'redirects to the dossiers list' do
|
||||
|
|
|
@ -25,6 +25,9 @@ FactoryBot.define do
|
|||
|
||||
trait :with_entreprise do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
if dossier.procedure.for_individual?
|
||||
raise 'Inconsistent factory: attempting to create a dossier :with_entreprise on a procedure that is `for_individual?`'
|
||||
end
|
||||
etablissement = create(:etablissement)
|
||||
dossier.etablissement = etablissement
|
||||
end
|
||||
|
@ -36,10 +39,17 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :for_individual do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
trait :with_individual do
|
||||
after(:build) do |dossier, evaluator|
|
||||
# If the procedure was implicitely created by the factory,
|
||||
# mark it automatically as for_individual.
|
||||
if evaluator.procedure.nil?
|
||||
dossier.procedure.update(for_individual: true)
|
||||
end
|
||||
if !dossier.procedure.for_individual?
|
||||
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
||||
end
|
||||
dossier.individual = create(:individual)
|
||||
dossier.save
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'features/users/dossier_shared_examples.rb'
|
|||
describe 'Dossier details:' do
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:simple_procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :for_individual, :with_commentaires, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_commentaires, user: user, procedure: procedure) }
|
||||
|
||||
before do
|
||||
visit_dossier dossier
|
||||
|
@ -17,7 +17,7 @@ describe 'Dossier details:' do
|
|||
end
|
||||
|
||||
describe "the user can see the mean time they are expected to wait" do
|
||||
let(:other_dossier) { create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) }
|
||||
let(:other_dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) }
|
||||
|
||||
context "when the dossier is in construction" do
|
||||
it "displays the estimated wait duration" do
|
||||
|
@ -28,7 +28,7 @@ describe 'Dossier details:' do
|
|||
end
|
||||
|
||||
context "when the dossier is in instruction" do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_commentaires, user: user, procedure: procedure) }
|
||||
|
||||
it "displays the estimated wait duration" do
|
||||
other_dossier
|
||||
|
|
|
@ -8,7 +8,7 @@ feature 'Invitations' do
|
|||
let(:invite) { create(:invite, user: invited_user, dossier: dossier) }
|
||||
|
||||
context 'when the dossier is a brouillon' do
|
||||
let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :with_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) }
|
||||
|
||||
scenario 'on the form, the owner of a dossier can invite another user to collaborate on the dossier', js: true do
|
||||
log_in(owner)
|
||||
|
@ -69,7 +69,7 @@ feature 'Invitations' do
|
|||
end
|
||||
|
||||
context 'when the dossier is en_construction' do
|
||||
let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: owner, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :with_individual, :en_construction, user: owner, procedure: procedure) }
|
||||
|
||||
scenario 'on dossier details, the owner of a dossier can invite another user to collaborate on the dossier', js: true do
|
||||
log_in(owner)
|
||||
|
|
|
@ -3,7 +3,7 @@ require "spec_helper"
|
|||
RSpec.describe NotificationMailer, type: :mailer do
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:simple_procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :for_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
|
||||
describe '.send_dossier_received' do
|
||||
let(:email_template) { create(:received_mail, subject: 'Email subject', body: 'Your dossier was processed. Thanks.') }
|
||||
|
|
|
@ -46,21 +46,6 @@ describe Administrateur, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#delete_and_transfer_services' do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let!(:autre_administrateur) { create(:administrateur) }
|
||||
let!(:procedure) { create(:procedure, :with_service, administrateurs: [administrateur, autre_administrateur]) }
|
||||
let(:service) { procedure.service }
|
||||
|
||||
it "delete and transfer services to other admin" do
|
||||
service.update(administrateur: administrateur)
|
||||
administrateur.delete_and_transfer_services
|
||||
|
||||
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
||||
expect(service.reload.administrateur).to eq(autre_administrateur)
|
||||
end
|
||||
end
|
||||
|
||||
# describe '#password_complexity' do
|
||||
# let(:email) { 'mail@beta.gouv.fr' }
|
||||
# let(:passwords) { ['pass', '12pass23', 'démarches ', 'démarches-simple', 'démarches-simplifiées-pwd'] }
|
||||
|
|
|
@ -573,7 +573,7 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe '#owner_name' do
|
||||
let!(:procedure) { create(:procedure) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
subject { dossier.owner_name }
|
||||
|
||||
context 'when there is no entreprise or individual' do
|
||||
|
@ -589,7 +589,8 @@ describe Dossier do
|
|||
end
|
||||
|
||||
context 'when there is an individual' do
|
||||
let(:dossier) { create(:dossier, :for_individual, procedure: procedure) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:dossier) { create(:dossier, :with_individual, procedure: procedure) }
|
||||
|
||||
it { is_expected.to eq("#{dossier.individual.nom} #{dossier.individual.prenom}") }
|
||||
end
|
||||
|
|
|
@ -424,40 +424,9 @@ describe Instructeur, type: :model do
|
|||
it { expect(instructeur_a.procedures.all.to_ary).to eq([procedure_a]) }
|
||||
end
|
||||
|
||||
describe "#can_be_deleted?" do
|
||||
subject { instructeur.can_be_deleted? }
|
||||
|
||||
context 'when the instructeur is an administrateur' do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let(:instructeur) { administrateur.instructeur }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context "when the instructeur's procedures have other instructeurs" do
|
||||
let(:instructeur_not_admin) { create(:instructeur) }
|
||||
let(:autre_instructeur) { create(:instructeur) }
|
||||
|
||||
it "can be deleted" do
|
||||
assign(procedure, instructeur_assigne: instructeur_not_admin)
|
||||
assign(procedure, instructeur_assigne: autre_instructeur)
|
||||
expect(autre_instructeur.can_be_deleted?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context "when the instructeur's procedures is the only one" do
|
||||
let(:instructeur_not_admin) { create :instructeur }
|
||||
let(:autre_procedure) { create :procedure }
|
||||
it "can be deleted" do
|
||||
assign(autre_procedure, instructeur_assigne: instructeur_not_admin)
|
||||
expect(instructeur_not_admin.can_be_deleted?).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
||||
create :assign_to, instructeur: instructeur_assigne, procedure: procedure_to_assign, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur
|
||||
def assign(procedure_to_assign)
|
||||
create :assign_to, instructeur: instructeur, procedure: procedure_to_assign, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur
|
||||
end
|
||||
end
|
||||
|
|
|
@ -224,24 +224,6 @@ describe User, type: :model do
|
|||
context 'when the user has no dossier in instruction' do
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the user is an administrateur' do
|
||||
it 'cannot be deleted' do
|
||||
administrateur = create(:administrateur)
|
||||
user = administrateur.user
|
||||
|
||||
expect(user.can_be_deleted?).to be_falsy
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is an instructeur' do
|
||||
it 'cannot be deleted' do
|
||||
instructeur = create(:instructeur)
|
||||
user = instructeur.user
|
||||
|
||||
expect(user.can_be_deleted?).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_and_keep_track_dossiers' do
|
||||
|
@ -259,7 +241,6 @@ describe User, type: :model do
|
|||
let!(:dossier_en_construction) { create(:dossier, :en_construction, user: user) }
|
||||
let!(:dossier_brouillon) { create(:dossier, user: user) }
|
||||
|
||||
context 'without a hidden dossier' do
|
||||
it "keep track of dossiers and delete user" do
|
||||
user.delete_and_keep_track_dossiers(administration)
|
||||
|
||||
|
@ -268,21 +249,5 @@ describe User, type: :model do
|
|||
expect(User.find_by(id: user.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a hidden dossier' do
|
||||
let!(:dossier_cache) do
|
||||
create(:dossier, :en_construction, user: user)
|
||||
end
|
||||
|
||||
it "keep track of dossiers and delete user" do
|
||||
dossier_cache.delete_and_keep_track(administration)
|
||||
user.delete_and_keep_track_dossiers(administration)
|
||||
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_present
|
||||
expect(User.find_by(id: user.id)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ describe ProcedureExportService do
|
|||
end
|
||||
|
||||
context 'with dossier' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
||||
|
||||
let(:nominal_headers) do
|
||||
[
|
||||
|
@ -286,7 +286,7 @@ describe ProcedureExportService do
|
|||
end
|
||||
|
||||
context 'with avis' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
||||
let!(:avis) { create(:avis, :with_answer, dossier: dossier) }
|
||||
|
||||
it 'should have headers' do
|
||||
|
@ -307,8 +307,8 @@ describe ProcedureExportService do
|
|||
context 'with repetitions' do
|
||||
let!(:dossiers) do
|
||||
[
|
||||
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure),
|
||||
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure)
|
||||
create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure),
|
||||
create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure)
|
||||
]
|
||||
end
|
||||
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
|
@ -341,7 +341,7 @@ describe ProcedureExportService do
|
|||
end
|
||||
|
||||
context 'with non unique labels' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) }
|
||||
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
|||
RSpec.describe 'commencer/show.html.haml', type: :view do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
let(:procedure) { create(:procedure, :with_service, :published) }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, :with_service) }
|
||||
|
||||
before do
|
||||
assign(:procedure, procedure)
|
||||
|
@ -53,7 +53,7 @@ RSpec.describe 'commencer/show.html.haml', type: :view do
|
|||
|
||||
context 'and they have a submitted dossier' do
|
||||
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, :with_individual, user: user, procedure: procedure) }
|
||||
|
||||
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
|
||||
|
||||
|
@ -66,7 +66,7 @@ RSpec.describe 'commencer/show.html.haml', type: :view do
|
|||
|
||||
context 'and they have several submitted dossiers' do
|
||||
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
|
||||
let!(:dossiers) { create_list(:dossier, 2, :en_construction, :for_individual, user: user, procedure: procedure) }
|
||||
let!(:dossiers) { create_list(:dossier, 2, :en_construction, :with_individual, user: user, procedure: procedure) }
|
||||
|
||||
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'users/dossiers/brouillon.html.haml', type: :view do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_notice, :with_service, for_individual: true) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, state: Dossier.states.fetch(:brouillon), procedure: procedure) }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_notice, :with_service) }
|
||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure) }
|
||||
let(:footer) { view.content_for(:footer) }
|
||||
|
||||
before do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'users/dossiers/identite.html.haml', type: :view do
|
||||
let(:procedure) { create(:simple_procedure, for_individual: true) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) }
|
||||
let(:procedure) { create(:simple_procedure, :for_individual) }
|
||||
let(:dossier) { create(:dossier, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) }
|
||||
|
||||
before do
|
||||
sign_in dossier.user
|
||||
|
|
Loading…
Reference in a new issue