refactor(champ): simplify dossier link champ
This commit is contained in:
parent
4604be0796
commit
39ecc669b1
5 changed files with 20 additions and 21 deletions
|
@ -2,12 +2,7 @@ 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
|
||||
@dossier_id = params[:dossier][:champs_private_attributes][params[:position]][:value]
|
||||
end
|
||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||
@linked_dossier_id = read_param_value(@champ.input_name, 'value')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<%= render_to_element(".dossier-link-#{@position} .help-block",
|
||||
<%= render_to_element("##{@champ.input_group_id} .help-block",
|
||||
partial: 'shared/champs/dossier_link/help_block',
|
||||
locals: { id: @dossier_id }) %>
|
||||
locals: { id: @linked_dossier_id }) %>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
.dossier-link{ class: "dossier-link-#{form.index}" }
|
||||
.dossier-link
|
||||
= form.number_field :value,
|
||||
id: champ.input_id,
|
||||
aria: { describedby: champ.describedby_id },
|
||||
placeholder: "Numéro de dossier",
|
||||
autocomplete: 'off',
|
||||
required: champ.mandatory?,
|
||||
data: { remote: true, url: champs_dossier_link_path(form.index) }
|
||||
data: { remote: true, url: champs_dossier_link_path(champ.id) }
|
||||
|
||||
.help-block
|
||||
= render partial: 'shared/champs/dossier_link/help_block', locals: { id: champ.value }
|
||||
|
|
|
@ -141,8 +141,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
namespace :champs do
|
||||
get ':position/dossier_link', to: 'dossier_link#show', as: :dossier_link
|
||||
get ':champ_id/siret', to: 'siret#show', as: :siret
|
||||
get ':champ_id/dossier_link', to: 'dossier_link#show', as: :dossier_link
|
||||
post ':champ_id/carte', to: 'carte#show', as: :carte
|
||||
|
||||
get ':champ_id/carte/features', to: 'carte#index', as: :carte_features
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
describe Champs::DossierLinkController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure) { create(:procedure, :published, :with_dossier_link) }
|
||||
|
||||
describe '#show' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
|
||||
context 'when user is connected' do
|
||||
render_views
|
||||
before { sign_in user }
|
||||
|
||||
let(:champs_attributes) do
|
||||
champ_attributes = []
|
||||
champ_attributes[champ.id] = { value: dossier_id }
|
||||
champ_attributes
|
||||
end
|
||||
let(:params) do
|
||||
{
|
||||
champ_id: champ.id,
|
||||
dossier: {
|
||||
champs_attributes: {
|
||||
'1' => { value: dossier_id.to_s }
|
||||
}
|
||||
},
|
||||
position: '1'
|
||||
champs_attributes: champs_attributes
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
@ -30,7 +34,7 @@ describe Champs::DossierLinkController, type: :controller 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')
|
||||
expect(response.body).to include("##{champ.input_group_id} .help-block")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,14 +46,14 @@ describe Champs::DossierLinkController, type: :controller do
|
|||
|
||||
it 'renders error message' do
|
||||
expect(response.body).to include('Ce dossier est inconnu')
|
||||
expect(response.body).to include('.dossier-link-1 .help-block')
|
||||
expect(response.body).to include("##{champ.input_group_id} .help-block")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not connected' do
|
||||
before do
|
||||
get :show, params: { position: '1' }, format: :js, xhr: true
|
||||
get :show, params: { champ_id: champ.id }, format: :js, xhr: true
|
||||
end
|
||||
|
||||
it { expect(response.code).to eq('401') }
|
||||
|
|
Loading…
Reference in a new issue