commit
6f3ce45c2c
3 changed files with 84 additions and 3 deletions
|
@ -39,9 +39,14 @@ class NotificationMailer < ApplicationMailer
|
||||||
create_commentaire_for_notification(dossier, subject, body)
|
create_commentaire_for_notification(dossier, subject, body)
|
||||||
|
|
||||||
if dossier.procedure.logo?
|
if dossier.procedure.logo?
|
||||||
logo_filename = dossier.procedure.logo.filename
|
begin
|
||||||
attachments.inline[logo_filename] = dossier.procedure.logo.read
|
logo_filename = dossier.procedure.logo.filename
|
||||||
@logo_url = attachments[logo_filename].url
|
attachments.inline[logo_filename] = dossier.procedure.logo.read
|
||||||
|
@logo_url = attachments[logo_filename].url
|
||||||
|
rescue StandardError => e
|
||||||
|
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
|
||||||
|
Raven.capture_exception(e)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
|
|
|
@ -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