Fix procedures with multiple dossier link champs

This commit is contained in:
Paul Chavard 2018-10-10 21:59:53 +02:00
parent f0610c493c
commit c0344fc30e
4 changed files with 10 additions and 4 deletions

View file

@ -2,6 +2,8 @@ class Champs::DossierLinkController < ApplicationController
before_action :authenticate_logged_user!
def show
@position = params[:position]
if params[:dossier].key?(:champs_attributes)
@dossier_id = params[:dossier][:champs_attributes][params[:position]][:value]
else

View file

@ -1,3 +1,3 @@
<%= render_to_element('.dossier-link .help-block',
<%= render_to_element(".dossier-link-#{@position} .help-block",
partial: 'shared/champs/dossier_link/help_block',
locals: { id: @dossier_id }) %>

View file

@ -1,4 +1,4 @@
.dossier-link
.dossier-link{ class: "dossier-link-#{form.index}" }
= form.number_field :value,
placeholder: "Numéro de dossier",
autocomplete: 'off',

View file

@ -28,10 +28,11 @@ describe Champs::DossierLinkController, type: :controller do
get :show, params: params, format: 'js'
}
it 'returns the procedure name' do
it 'renders the procedure name' do
expect(response.body).to include('Dossier en brouillon')
expect(response.body).to include(procedure.libelle)
expect(response.body).to include(procedure.organisation)
expect(response.body).to include('.dossier-link-1 .help-block')
end
end
@ -41,7 +42,10 @@ describe Champs::DossierLinkController, type: :controller do
get :show, params: params, format: 'js'
}
it { expect(response.body).to include('Ce dossier est inconnu') }
it 'renders error message' do
expect(response.body).to include('Ce dossier est inconnu')
expect(response.body).to include('.dossier-link-1 .help-block')
end
end
end