Merge branch 'develop' of github.com:sgmap/tps into develop

This commit is contained in:
Tanguy PATTE 2015-12-15 16:49:58 +01:00
commit 789ea308ee
25 changed files with 211 additions and 8 deletions

View file

@ -67,6 +67,8 @@ gem "font-awesome-rails"
gem 'hashie'
gem 'mailjet'
group :test do
gem 'capybara'
gem 'factory_girl'

View file

@ -194,6 +194,10 @@ GEM
lumberjack (1.0.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mailjet (1.1.0)
activesupport (>= 3.1.0)
rack (>= 1.4.0)
rest-client
method_source (0.8.2)
mime-types (2.6.1)
mini_portile (0.6.2)
@ -446,6 +450,7 @@ DEPENDENCIES
leaflet-markercluster-rails (~> 0.7.0)
leaflet-rails
logstasher
mailjet
mina!
openid_connect
pg

View file

@ -52,6 +52,8 @@ class Backoffice::DossiersController < ApplicationController
@dossier.next_step! 'gestionnaire', 'valid'
flash.notice = 'Dossier confirmé avec succès.'
NotificationMailer.dossier_validated(@dossier).deliver_now!
render 'show'
end

View file

@ -15,6 +15,7 @@ class CommentairesController < ApplicationController
@commentaire.save
if is_gestionnaire?
NotificationMailer.new_answer(@commentaire.dossier).deliver_now!
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
else
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id'])

View file

@ -8,9 +8,11 @@ class Users::RegistrationsController < Devise::RegistrationsController
# end
# POST /resource
# def create
# super
# end
def create
retour = super
WelcomeMailer.welcome_email(User.last).deliver_now!
retour
end
# GET /resource/edit
# def edit

View file

@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "tps@apientreprise.fr"
layout 'mailer'
end

View file

@ -0,0 +1,23 @@
class NotificationMailer < ApplicationMailer
def new_answer dossier
send_mail dossier, "Nouveau commentaire pour votre dossier TPS N°#{dossier.id}"
end
def dossier_validated dossier
send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été validé"
end
private
def vars_mailer dossier
@dossier = dossier
@user = dossier.user
end
def send_mail dossier, subject
vars_mailer dossier
mail(from: "tps@apientreprise.fr", to: @user.email,
subject: subject)
end
end

View file

@ -0,0 +1,9 @@
class WelcomeMailer < ApplicationMailer
def welcome_email user
@user = user
mail(from: "tps@apientreprise.fr", to: user.email,
subject: "Création de votre compte TPS")
end
end

View file

@ -0,0 +1,15 @@
<p>Bonjour <%= @resource.email %>!</p>
<p>Vous avez demandé à regénérer votre mot de passe sur la plateforme TPS. Pour ceci, merci de suivre le lien suivant :</p>
<p><%= link_to 'Changer mon mot de passe', edit_password_url(@resource, reset_password_token: @token) %> - <%= edit_password_url(@resource, reset_password_token: @token) %></p>
<p>Si vous n'avez pas effectué une telle demande, merci d'ignorer ce mail. Votre mot de passe ne sera pas changé.</p>
<p>Bonne journée</p>
<p>
---
<br>
L'équipe TPS - tps@apientreprise.fr</p>

View file

@ -0,0 +1,3 @@
%hmtl
%body
= yield

View file

@ -0,0 +1 @@
= yield

View file

@ -0,0 +1,10 @@
Bonjour <%= @user.email %>!
Votre dossier N°<%=@dossier.id%> a été validé par votre gestionnaire.
Afin de finaliser son dépot, merci de vous rendre sur <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%>
Bonne journée
---
L'équide TPS - tps@apientreprise.fr

View file

@ -0,0 +1,10 @@
Bonjour <%= @user.email %>!
Un nouveau commentaire est disponible dans votre espace TPS.
Pour le consulter, merci de vous rendre sur <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%>
Bonne journée
---
L'équide TPS - tps@apientreprise.fr

View file

@ -26,6 +26,8 @@
-# </div>
-#<% end %>
= devise_error_messages!
#form_login
= image_tag('logo-tps.png')
%br

View file

@ -0,0 +1,15 @@
Bienvenue sur la plateforme TPS
Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles :
URL : https://tps.apientreprise.fr
Login : <%= @user.email %>
Oubli de mot de passe, pas de problème :
https://tps.apientreprise.fr/users/password/new
Bonne journée,
---
L'équipe TPS - tps@apientreprise.fr

View file

@ -36,6 +36,9 @@ Rails.application.configure do
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
config.action_mailer.delivery_method = :mailjet
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

View file

@ -37,6 +37,9 @@ Rails.application.configure do
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View file

@ -10,7 +10,7 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
config.mailer_sender = 'tps@apientreprise.fr'
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'

View file

@ -63,8 +63,8 @@ ActiveRecord::Schema.define(version: 20151214133426) do
t.boolean "autorisation_donnees"
t.string "nom_projet"
t.integer "procedure_id"
t.datetime "created_at", default: '2015-09-22 09:25:29'
t.datetime "updated_at", default: '2015-09-22 09:25:29'
t.datetime "created_at", default: '2015-12-07 09:51:23'
t.datetime "updated_at", default: '2015-12-07 09:51:23'
t.string "state"
t.integer "user_id"
t.text "json_latlngs"

View file

@ -31,6 +31,13 @@ describe Backoffice::CommentairesController, type: :controller do
subject { dossier.state }
it {is_expected.to eq('replied')}
it 'Notification email is send' do
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire
end
end
end
end

View file

@ -98,12 +98,21 @@ describe Backoffice::DossiersController, type: :controller do
sign_in gestionnaire
end
subject { post :valid, dossier_id: dossier_id }
it 'change state to validated' do
post :valid, dossier_id: dossier_id
subject
dossier.reload
expect(dossier.state).to eq('validated')
end
it 'Notification email is send' do
expect(NotificationMailer).to receive(:dossier_validated).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
end
end
describe 'POST #close' do

View file

@ -8,11 +8,22 @@ describe Users::CommentairesController, type: :controller do
describe '#POST create' do
context 'création correct d\'un commentaire' do
it 'depuis la page récapitulatif' do
subject do
sign_in dossier.user
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire
end
it 'depuis la page récapitulatif' do
subject
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
it 'Notification email is not send' do
expect(NotificationMailer).not_to receive(:new_answer)
expect(WelcomeMailer).not_to receive(:deliver_now!)
subject
end
end
describe 'change dossier state after post a comment' do

View file

@ -0,0 +1,26 @@
require 'spec_helper'
describe Users::RegistrationsController, type: :controller do
let(:email) { 'test@octo.com' }
let(:password) { 'password' }
let(:user) { { email: email, password: password, password_confirmation: password } }
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
describe '.create' do
subject { post :create, user: user }
it { expect(described_class).to be < Devise::RegistrationsController }
it 'welcome email is send' do
expect(WelcomeMailer).to receive(:welcome_email).and_return(WelcomeMailer)
expect(WelcomeMailer).to receive(:deliver_now!)
subject
end
end
end

View file

@ -0,0 +1,25 @@
require "rails_helper"
RSpec.describe NotificationMailer, type: :mailer do
describe ".new_answer" do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
subject(:subject) { described_class.new_answer(dossier) }
it { expect(subject.body).to match('Un nouveau commentaire est disponible dans votre espace TPS.') }
it { expect(subject.body).to include("Pour le consulter, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") }
it { expect(subject.subject).to eq("Nouveau commentaire pour votre dossier TPS N°#{dossier.id}") }
end
describe ".dossier_validated" do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, user: user) }
subject(:subject) { described_class.dossier_validated(dossier) }
it { expect(subject.body).to match("Votre dossier N°#{dossier.id} a été validé par votre gestionnaire.") }
it { expect(subject.body).to include("Afin de finaliser son dépot, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") }
it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été validé") }
end
end

View file

@ -0,0 +1,15 @@
require 'spec_helper'
describe WelcomeMailer, type: :mailer do
describe ".welcome_email" do
let(:user) { create(:user) }
subject(:subject) { described_class.welcome_email(user) }
it { expect(subject.body).to match('https://tps.apientreprise.fr') }
it { expect(subject.body).to match('https://tps.apientreprise.fr/users/password/new') }
it { expect(subject.body).to match(user.email) }
it { expect(subject.body).to match('Bienvenue sur la plateforme TPS') }
it { expect(subject.body).to match('Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles :')}
it { expect(subject.subject).to eq("Création de votre compte TPS") }
end
end