From 6d43465ee509bf30c8432145a208a2839115229b Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Wed, 17 Jul 2019 15:34:10 +0200 Subject: [PATCH] renammed into monavis_embed --- .../admin/procedures_controller.rb | 2 +- app/models/procedure.rb | 4 +- app/views/admin/procedures/_monavis.html.haml | 4 +- app/views/users/dossiers/merci.html.haml | 2 +- ...190717132452_add_monavis_to_procedures.rb} | 2 +- db/schema.rb | 4 +- .../admin/procedures_controller_spec.rb | 44 ++++++++++++++----- spec/models/procedure_spec.rb | 30 ++++++------- 8 files changed, 56 insertions(+), 36 deletions(-) rename db/migrate/{20190716141633_add_monavis_to_procedures.rb => 20190717132452_add_monavis_to_procedures.rb} (62%) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index a3e7a74c4..448df9f3c 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -277,7 +277,7 @@ class Admin::ProceduresController < AdminController end def procedure_params - editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on, :monavis] + editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on, :monavis_embed] if @procedure&.locked? params.require(:procedure).permit(*editable_params) else diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 14595964e..e94691871 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -74,8 +74,8 @@ class Procedure < ApplicationRecord class MonavisValidator < ActiveModel::Validator def validate(record) - r = Regexp.new('\s*Je donne mon avis\s*', Regexp::MULTILINE) - if record.monavis.present? && !r.match?(record.monavis) + 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 end diff --git a/app/views/admin/procedures/_monavis.html.haml b/app/views/admin/procedures/_monavis.html.haml index 36d631868..a1f861cf1 100644 --- a/app/views/admin/procedures/_monavis.html.haml +++ b/app/views/admin/procedures/_monavis.html.haml @@ -12,5 +12,5 @@ %p Une fois en possession du code généré sur le site MonAvis, vous pouvez le coller dans le champ ci-dessous : .form-group - = f.label :monavis, "Mon avis" - = f.text_area :monavis, rows: '6', placeholder: 'Je donne mon avis', class: 'form-control' + = f.label :monavis_embed, "Mon avis" + = f.text_area :monavis_embed, rows: '6', placeholder: 'Je donne mon avis', class: 'form-control' diff --git a/app/views/users/dossiers/merci.html.haml b/app/views/users/dossiers/merci.html.haml index 0e39a8040..941ffe36f 100644 --- a/app/views/users/dossiers/merci.html.haml +++ b/app/views/users/dossiers/merci.html.haml @@ -23,4 +23,4 @@ .flex.column.align-center = link_to 'Accéder à votre dossier', dossier_path(@dossier), class: 'button large primary' = link_to 'Déposer un autre dossier', procedure_lien(@dossier.procedure) - != @dossier.procedure.monavis + != @dossier.procedure.monavis_embed diff --git a/db/migrate/20190716141633_add_monavis_to_procedures.rb b/db/migrate/20190717132452_add_monavis_to_procedures.rb similarity index 62% rename from db/migrate/20190716141633_add_monavis_to_procedures.rb rename to db/migrate/20190717132452_add_monavis_to_procedures.rb index 0fdc98478..d97b5056f 100644 --- a/db/migrate/20190716141633_add_monavis_to_procedures.rb +++ b/db/migrate/20190717132452_add_monavis_to_procedures.rb @@ -1,5 +1,5 @@ class AddMonavisToProcedures < ActiveRecord::Migration[5.2] def change - add_column :procedures, :monavis, :text + add_column :procedures, :monavis_embed, :text end end diff --git a/db/schema.rb b/db/schema.rb index 5b102ddac..b38ea35e9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_07_16_141633) do +ActiveRecord::Schema.define(version: 2019_07_17_132452) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -500,7 +500,7 @@ ActiveRecord::Schema.define(version: 2019_07_16_141633) do t.boolean "durees_conservation_required", default: true t.string "path" t.string "declarative_with_state" - t.text "monavis" + t.text "monavis_embed" t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state" t.index ["hidden_at"], name: "index_procedures_on_hidden_at" t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id" diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index d87a8bb5f..4acaf3531 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -14,7 +14,7 @@ describe Admin::ProceduresController, type: :controller do let(:cadre_juridique) { 'cadre juridique' } let(:duree_conservation_dossiers_dans_ds) { 3 } let(:duree_conservation_dossiers_hors_ds) { 6 } - let(:monavis) { nil } + let(:monavis_embed) { nil } let(:procedure_params) { { @@ -26,7 +26,7 @@ describe Admin::ProceduresController, type: :controller do cadre_juridique: cadre_juridique, duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds, - monavis: monavis + monavis_embed: monavis_embed } } @@ -752,7 +752,7 @@ describe Admin::ProceduresController, type: :controller do let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) } let(:procedure_params) { { - monavis: monavis + monavis_embed: monavis_embed } } @@ -771,31 +771,51 @@ 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 + + MSG + } context 'when all attributes are present' do render_views - let(:monavis) { 'code html for monavis' } before { update_monavis } - describe 'the monavis field is updated' do - subject { procedure } + context 'when the embed code is valid' do + describe 'the monavis field is updated' do + subject { procedure } - it { expect(subject.monavis).to eq(monavis) } + 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 - it { expect(flash[:notice]).to be_present } - it { expect(response.body).to include "MonAvis" } + context 'when the embed code is not valid' do + let(:monavis_embed) { 'invalid embed code' } + + describe 'the monavis field is not updated' do + subject { procedure } + + it { expect(subject.monavis_embed).to eq(nil) } + end + + it { expect(flash[:alert]).to be_present } + it { expect(response.body).to include "MonAvis" } + end end context 'when procedure is published' do let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) } - let(:monavis) { 'code html for monavis' } subject { update_monavis } - describe 'the monavis field is updated' do - it { expect(subject.monavis).to eq procedure_params[:monavis] } + describe 'the monavis field is not updated' do + it { expect(subject.monavis_embed).to eq monavis_embed } end end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 8526a0975..81f94e500 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -200,37 +200,37 @@ describe Procedure do context 'monavis' do context 'nil is allowed' do - it { is_expected.to allow_value(nil).for(:monavis) } - it { is_expected.to allow_value('').for(:monavis) } + it { is_expected.to allow_value(nil).for(:monavis_embed) } + it { is_expected.to allow_value('').for(:monavis_embed) } end context 'random string is not allowed' do - let(:procedure) { build(:procedure, monavis: "plop") } + let(:procedure) { build(:procedure, monavis_embed: "plop") } it { expect(procedure.valid?).to eq(false) } end context 'random html is not allowed' do - let(:procedure) { build(:procedure, monavis: '') } + let(:procedure) { build(:procedure, monavis_embed: '') } it { expect(procedure.valid?).to eq(false) } end context 'Monavis embed code with white button is allowed' do monavis_blanc = <<-MSG - - Je donne mon avis - -MSG - let(:procedure) { build(:procedure, monavis: monavis_blanc) } + + Je donne mon avis + + MSG + let(:procedure) { build(:procedure, monavis_embed: monavis_blanc) } it { expect(procedure.valid?).to eq(true) } end context 'Monavis embed code with blue button is allowed' do - monavis_blanc = <<-MSG - - Je donne mon avis - -MSG - let(:procedure) { build(:procedure, monavis: monavis_blanc) } + monavis_bleu = <<-MSG + + Je donne mon avis + + MSG + let(:procedure) { build(:procedure, monavis_embed: monavis_bleu) } it { expect(procedure.valid?).to eq(true) } end end