From 949a0c21e69efed0a43eef8012123c07ba12c64f Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 16 Sep 2019 15:58:15 +0200 Subject: [PATCH] gestion des 2 formats de bouton monavis --- app/validators/mon_avis_embed_validator.rb | 2 +- .../admin/procedures_controller_spec.rb | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/validators/mon_avis_embed_validator.rb b/app/validators/mon_avis_embed_validator.rb index ac84bad24..17e8059bd 100644 --- a/app/validators/mon_avis_embed_validator.rb +++ b/app/validators/mon_avis_embed_validator.rb @@ -1,7 +1,7 @@ class MonAvisEmbedValidator < ActiveModel::Validator def validate(record) # We need to ensure the embed code is not any random string in order to avoid injections - r = Regexp.new('\s*Je donne mon avis\s*', Regexp::MULTILINE) + r = Regexp.new('\s*Je donne mon avis\s*', Regexp::MULTILINE) if record.monavis_embed.present? && !r.match?(record.monavis_embed) record.errors[:base] << "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme." end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 0ed1d5613..7df3010d7 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -796,10 +796,11 @@ describe Admin::ProceduresController, type: :controller do patch :update_monavis, params: { procedure_id: procedure.id, procedure: procedure_params } procedure.reload end + let(:monavis_embed) { <<-MSG - - Je donne mon avis + + Je donne mon avis MSG } @@ -820,6 +821,24 @@ describe Admin::ProceduresController, type: :controller do it { expect(response.body).to include "MonAvis" } end + context 'when the embed code is valid with the original format' do + let(:monavis_embed) { + <<-MSG + + Je donne mon avis + + MSG + } + describe 'the monavis field is updated' do + subject { procedure } + + it { expect(subject.monavis_embed).to eq(monavis_embed) } + end + + it { expect(flash[:notice]).to be_present } + it { expect(response.body).to include "MonAvis" } + end + context 'when the embed code is not valid' do let(:monavis_embed) { 'invalid embed code' }