-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instructeur can create groupe instructeur service
- Loading branch information
Showing
8 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app/controllers/instructeurs/groupe_instructeur_services_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Instructeurs | ||
class GroupeInstructeurServicesController < InstructeurController | ||
def new | ||
assign_procedure_and_groupe_instructeur | ||
@service = @groupe_instructeur.build_groupe_instructeur_service | ||
end | ||
|
||
def create | ||
assign_procedure_and_groupe_instructeur | ||
@service = @groupe_instructeur.build_groupe_instructeur_service(service_params) | ||
if @service.save | ||
redirect_to instructeur_groupe_path(@groupe_instructeur, procedure_id: @procedure.id), notice: "Le service #{@service.nom} a bien été créé" | ||
else | ||
flash[:alert] = @service.errors.full_messages | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def assign_procedure_and_groupe_instructeur | ||
@procedure = current_instructeur.procedures.find params[:procedure_id] | ||
@groupe_instructeur = current_instructeur.groupe_instructeurs.find params[:groupe_id] | ||
end | ||
|
||
def service_params | ||
params.require(:groupe_instructeur_service).permit(:nom, :organisme, :type_organisme, :email, :telephone, :horaires, :adresse, :siret) | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
app/views/instructeurs/groupe_instructeur_services/_form.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
= form_with url: instructeur_groupe_groupe_instructeur_service_path, model: @service, local: true do |f| | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :nom, input_type: :text_field) | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :organisme, input_type: :text_field) | ||
|
||
.fr-input-group | ||
= f.label :type_organisme, class: "fr-label" do | ||
Type d’organisme | ||
|
||
= f.select :type_organisme, Service.type_organismes.keys.map { |key| [ I18n.t("type_organisme.#{key}"), key] }, {}, class: 'fr-select' | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :siret, input_type: :text_field, opts: { placeholder: "14 chiffres, sans espace" }) do |c| | ||
- c.with_hint do | ||
= "Indiquez le numéro de SIRET de l’organisme dont ce service dépend. Rechercher le SIRET sur " | ||
= link_to("annuaire-entreprises.data.gouv.fr", annuaire_link, **external_link_attributes) | ||
|
||
= render Dsfr::CalloutComponent.new(title: "Informations de contact") do |c| | ||
- c.body do | ||
Votre démarche sera hébergée par #{APPLICATION_NAME} – mais nous ne pouvons pas assurer le support des démarches. Et malgré la dématérialisation, les usagers se poseront parfois des questions légitimes sur le processus administratif. | ||
%br | ||
%br | ||
%strong Il est donc indispensable que les usagers puissent vous contacter | ||
par le moyen de leur choix s’ils ont des questions sur votre démarche. | ||
%br | ||
%br | ||
Ces informations de contact seront visibles par les utilisateurs de la démarche, affichées dans le menu « Aide », ainsi qu’en pied de page lors du dépôt d’un dossier. En cas d’informations invalides, #{APPLICATION_NAME} se réserve le droit de suspendre la publication de la démarche. | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :email, input_type: :email_field) | ||
= render Dsfr::InputComponent.new(form: f, attribute: :telephone, input_type: :telephone_field) | ||
= render Dsfr::InputComponent.new(form: f, attribute: :horaires, input_type: :text_area) | ||
= render Dsfr::InputComponent.new(form: f, attribute: :adresse, input_type: :text_area) | ||
|
||
- if procedure_id.present? | ||
= hidden_field_tag :procedure_id, procedure_id | ||
|
||
.sticky-action-footer | ||
= f.submit "Enregistrer", class: "fr-btn fr-mr-2w" | ||
= link_to "Annuler", instructeur_groupe_path(@groupe_instructeur, procedure_id: procedure_id), class: "fr-btn fr-btn--secondary" |
10 changes: 10 additions & 0 deletions
10
app/views/instructeurs/groupe_instructeur_services/new.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
= render partial: 'administrateurs/breadcrumbs', | ||
locals: { steps: [[@procedure.libelle.truncate_words(10), instructeur_procedure_path(@procedure)], | ||
['Groupes d’instructeurs', instructeur_groupes_path(@procedure)], | ||
[@groupe_instructeur.label, instructeur_groupe_path(@groupe_instructeur, procedure_id: @procedure.id) ], | ||
['Service']]} | ||
.container | ||
%h1 Nouveau Service | ||
|
||
= render partial: 'form', | ||
locals: { service: @service, procedure_id: @procedure.id } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
spec/controllers/instructeurs/groupe_instructeur_services_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
describe Instructeurs::GroupeInstructeurServicesController, type: :controller do | ||
let(:instructeur) { create(:instructeur) } | ||
let(:procedure) { create(:procedure) } | ||
let(:assign_to) { create(:assign_to, instructeur: instructeur, groupe_instructeur: build(:groupe_instructeur, procedure: procedure)) } | ||
let(:gi) { assign_to.groupe_instructeur } | ||
|
||
before do | ||
sign_in(instructeur.user) | ||
end | ||
|
||
describe '#create' do | ||
context 'when submitting a new service' do | ||
let(:params) do | ||
{ | ||
groupe_instructeur_service: { | ||
nom: 'super service', | ||
organisme: 'organisme', | ||
type_organisme: 'association', | ||
email: 'email@toto.com', | ||
telephone: '1234', | ||
horaires: 'horaires', | ||
adresse: 'adresse', | ||
siret: "35600082800018" | ||
}, | ||
procedure_id: procedure.id, | ||
groupe_id: gi.id | ||
} | ||
end | ||
|
||
it do | ||
post :create, params: params | ||
expect(flash.alert).to be_nil | ||
expect(flash.notice).to eq('Le service super service a bien été créé') | ||
expect(GroupeInstructeurService.last.nom).to eq('super service') | ||
expect(GroupeInstructeurService.last.organisme).to eq('organisme') | ||
expect(GroupeInstructeurService.last.type_organisme).to eq(Service.type_organismes.fetch(:association)) | ||
expect(GroupeInstructeurService.last.email).to eq('email@toto.com') | ||
expect(GroupeInstructeurService.last.telephone).to eq('1234') | ||
expect(GroupeInstructeurService.last.horaires).to eq('horaires') | ||
expect(GroupeInstructeurService.last.adresse).to eq('adresse') | ||
expect(GroupeInstructeurService.last.siret).to eq('35600082800018') | ||
end | ||
end | ||
|
||
context 'when submitting an invalid service' do | ||
before do | ||
post :create, params: params | ||
end | ||
|
||
let(:params) { | ||
{ | ||
groupe_instructeur_service: { | ||
nom: 'super service' | ||
}, | ||
procedure_id: procedure.id, | ||
groupe_id: gi.id | ||
} | ||
} | ||
|
||
it { expect(flash.alert).not_to be_nil } | ||
it { expect(response).to render_template(:new) } | ||
it { expect(assigns(:service).nom).to eq('super service') } | ||
end | ||
end | ||
end |