feat(routing): add controller
This commit is contained in:
parent
bf737edec1
commit
b93e3776c4
3 changed files with 62 additions and 0 deletions
32
app/controllers/administrateurs/routing_controller.rb
Normal file
32
app/controllers/administrateurs/routing_controller.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Administrateurs
|
||||
class RoutingController < AdministrateurController
|
||||
include Logic
|
||||
|
||||
before_action :retrieve_procedure
|
||||
|
||||
def update
|
||||
left = champ_value(targeted_champ)
|
||||
right = constant(value)
|
||||
|
||||
@procedure.groupe_instructeurs.find(groupe_instructeur_id).update!(routing_rule: ds_eq(left, right))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def targeted_champ
|
||||
routing_params[:targeted_champ].to_i
|
||||
end
|
||||
|
||||
def value
|
||||
routing_params[:value]
|
||||
end
|
||||
|
||||
def groupe_instructeur_id
|
||||
routing_params[:groupe_instructeur_id]
|
||||
end
|
||||
|
||||
def routing_params
|
||||
params.permit(:targeted_champ, :value, :groupe_instructeur_id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -506,6 +506,8 @@ Rails.application.routes.draw do
|
|||
delete :delete_row, on: :member
|
||||
end
|
||||
|
||||
patch :update, controller: 'routing', as: :routing_rules
|
||||
|
||||
put 'clone'
|
||||
put 'archive'
|
||||
get 'publication' => 'procedures#publication', as: :publication
|
||||
|
|
28
spec/controllers/administrateurs/routing_controller_spec.rb
Normal file
28
spec/controllers/administrateurs/routing_controller_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
describe Administrateurs::RoutingController, type: :controller do
|
||||
include Logic
|
||||
|
||||
before { sign_in(procedure.administrateurs.first.user) }
|
||||
|
||||
describe '#update' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }]) }
|
||||
let(:gi_2) { procedure.groupe_instructeurs.create(label: 'groupe 2') }
|
||||
let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||
let(:params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
targeted_champ: drop_down_tdc.stable_id,
|
||||
value: 'Lyon',
|
||||
groupe_instructeur_id: gi_2.id
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in(procedure.administrateurs.first.user)
|
||||
post :update, params: params, format: :turbo_stream
|
||||
end
|
||||
|
||||
it do
|
||||
expect(gi_2.reload.routing_rule).to eq(ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue