amelioration(procedure.chorus): ajoute le form component pour le 'crud' du ChorusConfiguration
This commit is contained in:
parent
d8f50700fc
commit
87f435d2d3
8 changed files with 142 additions and 1 deletions
7
app/components/procedure/chorus_form_component.rb
Normal file
7
app/components/procedure/chorus_form_component.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class Procedure::ChorusFormComponent < ApplicationComponent
|
||||
attr_reader :procedure
|
||||
|
||||
def initialize(procedure:)
|
||||
@procedure = procedure
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
= form_for([procedure, procedure.chorus_configuration],url: admin_procedure_chorus_path(procedure), method: :put) do |f|
|
||||
|
||||
.fr-select-group
|
||||
= f.label :centre_de_coup, class: 'fr-label'
|
||||
= f.select :centre_de_coup, options_for_select(ChorusConfiguration.centre_de_coup_options, procedure.chorus_configuration.centre_de_coup), {}, class: 'fr-select'
|
||||
|
||||
.fr-select-group
|
||||
= f.label :domaine_fonctionnel, class: 'fr-label'
|
||||
= f.select :domaine_fonctionnel, options_for_select(ChorusConfiguration.domaine_fonctionnel_options, procedure.chorus_configuration.domaine_fonctionnel), {}, class: 'fr-select'
|
||||
|
||||
.fr-select-group
|
||||
= f.label :referentiel_de_programmation, class: 'fr-label'
|
||||
= f.select :referentiel_de_programmation, options_for_select(ChorusConfiguration.referentiel_de_programmation_options, procedure.chorus_configuration.referentiel_de_programmation), {}, class: 'fr-select'
|
||||
|
||||
= f.submit "Enregister", class: 'fr-btn'
|
|
@ -4,5 +4,25 @@ module Administrateurs
|
|||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@configuration = @procedure.chorus_configuration
|
||||
@configuration.assign_attributes(configurations_params)
|
||||
if @configuration.valid?
|
||||
@procedure.update!(chorus: @configuration.attributes)
|
||||
|
||||
flash.notice = "La configuration Chorus a été mise à jour et prend immédiatement effet pour les nouveaux dossiers."
|
||||
redirect_to admin_procedure_path(@procedure)
|
||||
else
|
||||
flash.now.alert = "Des erreurs empêchent la validation du connecteur chorus. Corrigez les erreurs"
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def configurations_params
|
||||
params.require(:chorus_configuration).permit(:centre_de_coup, :domaine_fonctionnel, :referentiel_de_programmation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
24
app/models/chorus_configuration.rb
Normal file
24
app/models/chorus_configuration.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class ChorusConfiguration
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
|
||||
attribute :centre_de_coup, default: nil
|
||||
attribute :domaine_fonctionnel, default: nil
|
||||
attribute :referentiel_de_programmation, default: nil
|
||||
|
||||
validates :centre_de_coup, inclusion: { in: Proc.new { ChorusConfiguration.centre_de_coup_options } }
|
||||
validates :domaine_fonctionnel, inclusion: { in: Proc.new { ChorusConfiguration.domaine_fonctionnel_options } }
|
||||
validates :referentiel_de_programmation, inclusion: { in: Proc.new { ChorusConfiguration.referentiel_de_programmation_options } }
|
||||
|
||||
def self.centre_de_coup_options
|
||||
[1, 2, 3].map(&:to_s)
|
||||
end
|
||||
|
||||
def self.domaine_fonctionnel_options
|
||||
[4, 5, 6].map(&:to_s)
|
||||
end
|
||||
|
||||
def self.referentiel_de_programmation_options
|
||||
[7, 8, 9].map(&:to_s)
|
||||
end
|
||||
end
|
|
@ -2,6 +2,10 @@ module ProcedureChorusConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def chorus_configuration
|
||||
@chorus_configuration ||= ChorusConfiguration.new(chorus)
|
||||
end
|
||||
|
||||
def chorusable?
|
||||
feature_enabled?(:chorus)
|
||||
end
|
||||
|
|
|
@ -7,3 +7,5 @@
|
|||
.container
|
||||
%h1.mb-2
|
||||
Cadre budgétaire
|
||||
|
||||
= render Procedure::ChorusFormComponent.new(procedure: @procedure)
|
||||
|
|
|
@ -601,7 +601,7 @@ Rails.application.routes.draw do
|
|||
resource :attestation_template, only: [:show, :edit, :update, :create] do
|
||||
get 'preview', on: :member
|
||||
end
|
||||
resource :chorus, only: [:edit]
|
||||
resource :chorus, only: [:edit, :update]
|
||||
resource :dossier_submitted_message, only: [:edit, :update, :create]
|
||||
# ADDED TO ACCESS IT FROM THE IFRAME
|
||||
get 'attestation_template/preview' => 'attestation_templates#preview'
|
||||
|
|
|
@ -17,6 +17,75 @@ describe Administrateurs::ChorusController, type: :controller do
|
|||
context 'signed as admin' do
|
||||
before { sign_in(admin.user) }
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
context 'rendered' do
|
||||
render_views
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'update' do
|
||||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:administrateur, user: create(:user)) }
|
||||
let(:procedure) { create(:procedure, administrateurs: [admin]) }
|
||||
let(:chorus_configuration_params) { {} }
|
||||
subject do
|
||||
put :update,
|
||||
params: {
|
||||
procedure_id: procedure.id,
|
||||
chorus_configuration: chorus_configuration_params
|
||||
}
|
||||
end
|
||||
|
||||
context 'not signed in' do
|
||||
it { is_expected.to redirect_to(new_user_session_path) }
|
||||
end
|
||||
|
||||
context 'signed in but not admin of procedure' do
|
||||
before { sign_in(user) }
|
||||
it { is_expected.to redirect_to(new_user_session_path) }
|
||||
end
|
||||
|
||||
context 'signed as admin' do
|
||||
before { sign_in(admin.user) }
|
||||
|
||||
context "valid payload" do
|
||||
let(:chorus_configuration_params) do
|
||||
{
|
||||
centre_de_coup: ChorusConfiguration.centre_de_coup_options.first,
|
||||
domaine_fonctionnel: ChorusConfiguration.domaine_fonctionnel_options.first,
|
||||
referentiel_de_programmation: ChorusConfiguration.referentiel_de_programmation_options.first
|
||||
}
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to(admin_procedure_path(procedure)) }
|
||||
it 'updates params' do
|
||||
subject
|
||||
expect(flash[:notice]).to eq("La configuration Chorus a été mise à jour et prend immédiatement effet pour les nouveaux dossiers.")
|
||||
procedure.reload
|
||||
expect(procedure.chorus_configuration.centre_de_coup).to eq(ChorusConfiguration.centre_de_coup_options.first)
|
||||
expect(procedure.chorus_configuration.domaine_fonctionnel).to eq(ChorusConfiguration.domaine_fonctionnel_options.first)
|
||||
expect(procedure.chorus_configuration.referentiel_de_programmation).to eq(ChorusConfiguration.referentiel_de_programmation_options.first)
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid payload" do
|
||||
let(:chorus_configuration_params) do
|
||||
{
|
||||
centre_de_coup: 0
|
||||
}
|
||||
end
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
it 'updates params' do
|
||||
subject
|
||||
expect(flash[:notice]).to eq("Des erreurs empêchent la validation du connecteur chorus. Corrigez les erreurs")
|
||||
procedure.reload
|
||||
expect(procedure.chorus_configuration.centre_de_coup).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue