From 9beff5ee9ac377d129982eb9045c2f9dd0192832 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 10 Apr 2019 18:38:53 +0200 Subject: [PATCH 1/2] Always create menu deroulant champs with a value --- app/models/type_de_champ.rb | 15 +++++ .../types_de_champ_controller_spec.rb | 61 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 spec/controllers/new_administrateur/types_de_champ_controller_spec.rb diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 860883ae0..f3b9efe86 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -52,6 +52,7 @@ class TypeDeChamp < ApplicationRecord after_initialize :set_dynamic_type after_create :populate_stable_id before_save :setup_procedure + before_validation :set_default_drop_down_list attr_reader :dynamic_type @@ -140,6 +141,14 @@ class TypeDeChamp < ApplicationRecord ]) 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? type_champ == TypeDeChamp.type_champs.fetch(:explication) end @@ -178,6 +187,12 @@ class TypeDeChamp < ApplicationRecord 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 types_de_champ.each do |type_de_champ| type_de_champ.procedure = procedure diff --git a/spec/controllers/new_administrateur/types_de_champ_controller_spec.rb b/spec/controllers/new_administrateur/types_de_champ_controller_spec.rb new file mode 100644 index 000000000..3722ed60b --- /dev/null +++ b/spec/controllers/new_administrateur/types_de_champ_controller_spec.rb @@ -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 From 0770362fb4571baa6ed9dbbb27f5bdf70b00ce44 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 11 Apr 2019 15:08:10 +0200 Subject: [PATCH 2/2] Fix when missing logo on remote storage crash email sending --- app/mailers/notification_mailer.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 3ed99794e..e9e88b4c1 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -39,9 +39,14 @@ class NotificationMailer < ApplicationMailer create_commentaire_for_notification(dossier, subject, body) if dossier.procedure.logo? - logo_filename = dossier.procedure.logo.filename - attachments.inline[logo_filename] = dossier.procedure.logo.read - @logo_url = attachments[logo_filename].url + begin + logo_filename = dossier.procedure.logo.filename + 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 @dossier = dossier