From 54b4679d1913d387feeeef413c5bb5e99d79b893 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Tue, 25 Aug 2015 16:33:55 +0200 Subject: [PATCH] add mailto --- app/controllers/admin/commentaires_controller.rb | 3 +++ app/models/dossier.rb | 5 +++++ app/views/recapitulatif/_commentaires_flux.html.haml | 2 +- app/views/recapitulatif/show.html.haml | 4 ++++ config/routes.rb | 1 + .../admin/dossier_page/_commentaires_flux_spec.rb | 2 +- spec/models/dossier_spec.rb | 7 +++++++ spec/views/recapitulatif/show.html.haml_spec.rb | 12 ++++++++++++ 8 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/commentaires_controller.rb create mode 100644 spec/views/recapitulatif/show.html.haml_spec.rb diff --git a/app/controllers/admin/commentaires_controller.rb b/app/controllers/admin/commentaires_controller.rb new file mode 100644 index 000000000..e86f75c65 --- /dev/null +++ b/app/controllers/admin/commentaires_controller.rb @@ -0,0 +1,3 @@ +class Admin::CommentairesController < CommentairesController + before_action :authenticate_user! +end \ No newline at end of file diff --git a/app/models/dossier.rb b/app/models/dossier.rb index cc7b1609c..81269a181 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -32,10 +32,15 @@ class Dossier < ActiveRecord::Base end end + def mailto + "mailto:#{formulaire.email_contact}?subject=Demande%20de%20contact&body=Bonjour,%0A%0AJe%20vous%20informe%20que%20j'ai%20rempli%20le%20dossier%20sur%20admi_facile.%20Vous%20pouvez%20y%20acc%C3%A9der%20en%20suivant%20le%20lien%20suivant%20:%20%0Ahttps://admi_facile.apientreprise.fr/admin/dossiers/#{id}%20%0A%20Le%20num%C3%A9ro%20de%20mon%20dossier%20est%20le%20#{id}" + end + private def build_default_cerfa build_cerfa true end + end diff --git a/app/views/recapitulatif/_commentaires_flux.html.haml b/app/views/recapitulatif/_commentaires_flux.html.haml index bf70e9714..62bd43289 100644 --- a/app/views/recapitulatif/_commentaires_flux.html.haml +++ b/app/views/recapitulatif/_commentaires_flux.html.haml @@ -14,7 +14,7 @@ %br %h4{style: 'margin-bottom:2%'} Nouveau - = form_tag(url_for({controller: '/commentaires', action: :create}), class: 'form-inline', method: 'POST') do + = form_tag(url_for({ controller: :commentaires, action: :create, dossier_id: @dossier.id }), class: 'form-inline', method: 'POST') do %input.form-control{:type => 'text', style: 'width: 30%; margin-bottom:2%', :id => 'email_commentaire', :name => 'email_commentaire', :value => @commentaire_email} %textarea.form-control{:id => 'texte_commentaire', :name => 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', maxlength: '255'} %br diff --git a/app/views/recapitulatif/show.html.haml b/app/views/recapitulatif/show.html.haml index c74a978ba..378819538 100644 --- a/app/views/recapitulatif/show.html.haml +++ b/app/views/recapitulatif/show.html.haml @@ -20,4 +20,8 @@ = render partial: '/dossiers/infos_dossier' %br +%a.btn.btn-success{ href: @dossier.mailto } + Contacter l'administration + + = render partial: 'commentaires_flux' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1e877ca51..d0feb64cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,7 @@ Rails.application.routes.draw do namespace :admin do get '/dossiers/:dossier_id' => 'dossier#show' get '/dossiers' => 'dossier#index' + post '/commentaire' => 'commentaires#create' end # The priority is based upon order of creation: first created -> highest priority. diff --git a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb index fce40f77a..b19fe0fc9 100644 --- a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb +++ b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb @@ -29,7 +29,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do context 'Affichage du formulaire de commentaire' do scenario 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' do - expect(page).to have_selector("form[action='/dossiers/#{dossier_id}/commentaire'][method=post]") + expect(page).to have_selector("form[action='/admin/commentaire?dossier_id=#{dossier_id}'][method=post]") end scenario 'Champs de texte' do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 26568599e..b2fac1938 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -121,5 +121,12 @@ describe Dossier do end end end + + describe '#mailto' do + let(:dossier) { create(:dossier) } + let(:email_contact) { dossier.formulaire.email_contact } + subject { dossier.mailto } + it { is_expected.to eq("mailto:#{email_contact}?subject=Demande%20de%20contact&body=Bonjour,%0A%0AJe%20vous%20informe%20que%20j'ai%20rempli%20le%20dossier%20sur%20admi_facile.%20Vous%20pouvez%20y%20acc%C3%A9der%20en%20suivant%20le%20lien%20suivant%20:%20%0Ahttps://admi_facile.apientreprise.fr/admin/dossiers/#{dossier.id}%20%0A%20Le%20num%C3%A9ro%20de%20mon%20dossier%20est%20le%20#{dossier.id}")} + end end end diff --git a/spec/views/recapitulatif/show.html.haml_spec.rb b/spec/views/recapitulatif/show.html.haml_spec.rb new file mode 100644 index 000000000..c4a04f3b0 --- /dev/null +++ b/spec/views/recapitulatif/show.html.haml_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe 'recapitulatif/show.html.haml', type: :view do + let(:dossier) { create(:dossier, :with_entreprise) } + before do + assign(:dossier, dossier.decorate) + assign(:commentaires, dossier.commentaires) + render + end + it { expect(rendered).to have_content("Contacter l'administration") } + it { expect(rendered).to include(dossier.mailto.gsub('&','&')) } +end