From 0e5c90cb0ccd773e1e968dc245d50365c1709580 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 24 Jan 2017 10:19:42 +0100 Subject: [PATCH] Real index and edit for mail_templates --- app/controllers/admin/mails_controller.rb | 8 +++-- app/views/admin/mails/edit.html.haml | 27 ++++++++++++++++ app/views/admin/mails/index.html.haml | 31 +++++-------------- .../admin/mails_controller_spec.rb | 6 +++- spec/factories/mail_templates.rb | 19 ++++++++++++ spec/factories/procedure.rb | 1 + 6 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 app/views/admin/mails/edit.html.haml create mode 100644 spec/factories/mail_templates.rb diff --git a/app/controllers/admin/mails_controller.rb b/app/controllers/admin/mails_controller.rb index 6101ac8c3..cd1627371 100644 --- a/app/controllers/admin/mails_controller.rb +++ b/app/controllers/admin/mails_controller.rb @@ -2,11 +2,15 @@ class Admin::MailsController < AdminController before_action :retrieve_procedure def index + @mail_templates = @procedure.mail_templates + end + def edit + @mail_template = @procedure.mail_templates.find(params[:id]) end def update - mail = current_administrateur.procedures.find(params[:procedure_id]).mail_templates.find(params[:id]) + mail = @procedure.mail_templates.find(params[:id]) mail.update_attributes(update_params) redirect_to admin_procedure_mails_path @@ -17,4 +21,4 @@ class Admin::MailsController < AdminController def update_params params.require(:mail_received).permit(:body, :object) end -end \ No newline at end of file +end diff --git a/app/views/admin/mails/edit.html.haml b/app/views/admin/mails/edit.html.haml new file mode 100644 index 000000000..5456994e4 --- /dev/null +++ b/app/views/admin/mails/edit.html.haml @@ -0,0 +1,27 @@ +.white-back + %h3 + E-mail d'accusé de réception + = @mail_template.type + + = form_for @mail_template, url: {controller: 'admin/mails', action: 'update', id: @procedure.mail_received.id} do |f| + =f.text_field :object, {class:'form-control', style:'width: 40%'} + %br + =f.text_area :body, {class: 'form-control wysihtml5'} + %br + =f.submit 'Mettre à jour', {class:'btn btn-success', style:'float: right'} + + %table.table{style:'width: 50%'} + %tr + %th + Balise + %th + Description + - MailTemplate.tags.each do |balise| + %tr + %td.center + %b.text-success + \-- + = balise.first + \-- + %td + =balise.second[:description] diff --git a/app/views/admin/mails/index.html.haml b/app/views/admin/mails/index.html.haml index 14c6db2eb..7f2f7a222 100644 --- a/app/views/admin/mails/index.html.haml +++ b/app/views/admin/mails/index.html.haml @@ -1,28 +1,13 @@ .row.white-back - %h3 - E-mail d'accusé de réception + %h1 Emails personnalisables - - unless @procedure.mail_received.blank? - = form_for @procedure.mail_received, url: {controller: 'admin/mails', action: 'update', id: @procedure.mail_received.id} do |f| - =f.text_field :object, {class:'form-control', style:'width: 40%'} - %br - =f.text_area :body, {class: 'form-control wysihtml5'} - %br - =f.submit 'Mettre à jour', {class:'btn btn-success', style:'float: right'} - - - %table.table{style:'width: 50%'} + %table.table %tr - %th - Balise - %th - Description - - MailTemplate.tags.each do |balise| + %th{ colspan: 2 } + Type d'email + - @procedure.mail_templates.each do |mt| %tr - %td.center - %b.text-success - \-- - = balise.first - \-- %td - =balise.second[:description] + = mt.type + %td.text-right + = link_to "Personnaliser l'email", edit_admin_procedure_mail_path(@procedure, mt) diff --git a/spec/controllers/admin/mails_controller_spec.rb b/spec/controllers/admin/mails_controller_spec.rb index a51045d9e..ed800a0d6 100644 --- a/spec/controllers/admin/mails_controller_spec.rb +++ b/spec/controllers/admin/mails_controller_spec.rb @@ -8,9 +8,13 @@ describe Admin::MailsController, type: :controller do end describe 'GET index' do + render_views + subject { get :index, params: {procedure_id: procedure.id} } it { expect(subject.status).to eq 200 } + it { expect(subject.body).to include("Emails personnalisables") } + it { expect(subject.body).to include(*procedure.mail_templates.pluck(:type)) } end describe 'PATCH update' do @@ -39,4 +43,4 @@ describe Admin::MailsController, type: :controller do end end end -end \ No newline at end of file +end diff --git a/spec/factories/mail_templates.rb b/spec/factories/mail_templates.rb new file mode 100644 index 000000000..d5e6faa36 --- /dev/null +++ b/spec/factories/mail_templates.rb @@ -0,0 +1,19 @@ +FactoryGirl.define do + factory :mail_template do + object "Object, voila voila" + body "Blabla ceci est mon body" + type 'MailValidated' + + trait :dossier_submitted do + type 'MailSubmitted' + end + + trait :dossier_refused do + type 'MailRefused' + end + + trait :dossier_received do + type 'MailReceived' + end + end +end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 740faf5bc..c92a8ee5b 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -8,6 +8,7 @@ FactoryGirl.define do direction "direction SGMAP" published false administrateur { create(:administrateur) } + mail_templates { [create(:mail_template, :dossier_received)]} after(:build) do |procedure, _evaluator| if procedure.module_api_carto.nil?