Always create menu deroulant champs with a value
This commit is contained in:
parent
14aa4eafdd
commit
9beff5ee9a
2 changed files with 76 additions and 0 deletions
|
@ -52,6 +52,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
after_initialize :set_dynamic_type
|
after_initialize :set_dynamic_type
|
||||||
after_create :populate_stable_id
|
after_create :populate_stable_id
|
||||||
before_save :setup_procedure
|
before_save :setup_procedure
|
||||||
|
before_validation :set_default_drop_down_list
|
||||||
|
|
||||||
attr_reader :dynamic_type
|
attr_reader :dynamic_type
|
||||||
|
|
||||||
|
@ -140,6 +141,14 @@ class TypeDeChamp < ApplicationRecord
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def drop_down_list?
|
||||||
|
type_champ.in?([
|
||||||
|
TypeDeChamp.type_champs.fetch(:drop_down_list),
|
||||||
|
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
|
||||||
|
TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
def exclude_from_view?
|
def exclude_from_view?
|
||||||
type_champ == TypeDeChamp.type_champs.fetch(:explication)
|
type_champ == TypeDeChamp.type_champs.fetch(:explication)
|
||||||
end
|
end
|
||||||
|
@ -178,6 +187,12 @@ class TypeDeChamp < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_default_drop_down_list
|
||||||
|
if drop_down_list? && !drop_down_list
|
||||||
|
self.drop_down_list_attributes = { value: '' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup_procedure
|
def setup_procedure
|
||||||
types_de_champ.each do |type_de_champ|
|
types_de_champ.each do |type_de_champ|
|
||||||
type_de_champ.procedure = procedure
|
type_de_champ.procedure = procedure
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
describe NewAdministrateur::TypesDeChampController, type: :controller do
|
||||||
|
let(:admin) { create(:administrateur) }
|
||||||
|
|
||||||
|
describe '#types_de_champs editor api' do
|
||||||
|
let(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
admin.procedures << procedure
|
||||||
|
sign_in admin
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
|
|
||||||
|
context "create type_de_champ text" do
|
||||||
|
before do
|
||||||
|
post :create, params: {
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
type_de_champ: {
|
||||||
|
type_champ: type_champ,
|
||||||
|
libelle: 'Nouveau champ'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:created) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "validate type_de_champ linked_drop_down_list" do
|
||||||
|
let(:type_champ) { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
post :create, params: {
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
type_de_champ: {
|
||||||
|
type_champ: type_champ,
|
||||||
|
libelle: 'Nouveau champ'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:unprocessable_entity) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create type_de_champ linked_drop_down_list" do
|
||||||
|
let(:type_champ) { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
post :create, params: {
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
type_de_champ: {
|
||||||
|
type_champ: type_champ,
|
||||||
|
libelle: 'Nouveau champ',
|
||||||
|
drop_down_list_value: '--value--'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:created) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue