Merge branch 'develop' into staging

This commit is contained in:
gregoirenovel 2017-05-16 10:03:18 +02:00
commit e2893545b2
49 changed files with 331 additions and 133 deletions

1
.gitignore vendored
View file

@ -23,7 +23,6 @@
public/uploads public/uploads
public/downloads public/downloads
bin/*
config/initializers/token.rb config/initializers/token.rb
config/initializers/super_admin.rb config/initializers/super_admin.rb
doc/*.svg doc/*.svg

View file

@ -10,6 +10,14 @@
color: #FFFFFF; color: #FFFFFF;
overflow-y: scroll; overflow-y: scroll;
.link-to-dossiers {
padding: 15px 0 0 15px;
a {
color: #FFFFFF;
}
}
#first-block { #first-block {
font-family: Arial; font-family: Arial;
font-size: 16px; font-size: 16px;

View file

@ -35,15 +35,12 @@ class CommentairesController < ApplicationController
end end
@commentaire.body = params['texte_commentaire'] @commentaire.body = params['texte_commentaire']
saved = false
unless @commentaire.body.blank? && @commentaire.piece_justificative.nil? unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
saved = @commentaire.save unless flash.alert @commentaire.save unless flash.alert
else else
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe." flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
end end
notify_user_with_mail(@commentaire) if saved
if is_gestionnaire? if is_gestionnaire?
unless current_gestionnaire.follow? @commentaire.dossier unless current_gestionnaire.follow? @commentaire.dossier
current_gestionnaire.toggle_follow_dossier @commentaire.dossier current_gestionnaire.toggle_follow_dossier @commentaire.dossier
@ -63,10 +60,4 @@ class CommentairesController < ApplicationController
def is_gestionnaire? def is_gestionnaire?
false false
end end
private
def notify_user_with_mail(commentaire)
NotificationMailer.new_answer(commentaire.dossier).deliver_now! unless current_user.try(:email) == commentaire.dossier.user.email
end
end end

View file

@ -29,8 +29,4 @@ class EntrepriseDecorator < Draper::Decorator
def pretty_capital_social def pretty_capital_social
h.number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u') h.number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u')
end end
def pretty_date_creation
Time.at(date_creation).strftime('%d-%m-%Y')
end
end end

View file

@ -18,7 +18,7 @@ class DossiersListFacades
end end
def total_dossier_follow def total_dossier_follow
@current_devise_profil.dossiers_follow.count @current_devise_profil.followed_dossiers.count
end end
def total_new_dossier def total_new_dossier
@ -30,7 +30,7 @@ class DossiersListFacades
end end
def gestionnaire_procedures_name_and_id_list def gestionnaire_procedures_name_and_id_list
@current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossier_with_notification_for(procedure)}) } @current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossiers_with_notifications_count_for_procedure(procedure)}) }
end end
def unread_notifications def unread_notifications

View file

@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: "tps@apientreprise.fr" default from: "'Téléprocédures Simplifiées' <#{I18n.t('dynamics.contact_email')}>"
layout 'mailer' layout 'mailer'
end end

View file

@ -18,7 +18,6 @@ class GestionnaireMailer < ApplicationMailer
def send_mail email, args, subject def send_mail email, args, subject
vars_mailer email, args vars_mailer email, args
mail(from: "tps@apientreprise.fr", to: email, mail(to: email, subject: subject)
subject: subject)
end end
end end

View file

@ -19,8 +19,7 @@ class InviteMailer < ApplicationMailer
end end
def send_mail email, subject, reply_to def send_mail email, subject, reply_to
mail(from: "tps@apientreprise.fr", mail(to: email,
to: email,
subject: subject, subject: subject,
reply_to: reply_to) reply_to: reply_to)
end end

View file

@ -4,7 +4,7 @@ class NewAdminMailer < ApplicationMailer
@admin = admin @admin = admin
@password = password @password = password
mail(from: "tps@apientreprise.fr", to: 'tech@apientreprise.fr', mail(to: 'tech@apientreprise.fr',
subject: "Création d'un compte Admin TPS") subject: "Création d'un compte Admin TPS")
end end
end end

View file

@ -1,14 +1,15 @@
class NotificationMailer < ApplicationMailer class NotificationMailer < ApplicationMailer
default from: 'tps@apientreprise.fr', default to: Proc.new { @user.email }
to: Proc.new { @user.email }
after_action :create_commentaire_for_notification, only: :send_notification
def send_notification dossier, mail_template def send_notification dossier, mail_template
vars_mailer(dossier) vars_mailer(dossier)
obj = mail_template.object_for_dossier dossier @obj = mail_template.object_for_dossier dossier
body = mail_template.body_for_dossier dossier @body = mail_template.body_for_dossier dossier
mail(subject: obj) { |format| format.html { body } } mail(subject: @obj) { |format| format.html { @body } }
end end
def new_answer dossier def new_answer dossier
@ -17,6 +18,14 @@ class NotificationMailer < ApplicationMailer
private private
def create_commentaire_for_notification
Commentaire.create(
dossier: @dossier,
email: I18n.t("dynamics.contact_email"),
body: ["[#{@obj}]", @body].join("<br><br>")
)
end
def vars_mailer dossier def vars_mailer dossier
@dossier = dossier @dossier = dossier
@user = dossier.user @user = dossier.user

View file

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

View file

@ -4,7 +4,7 @@ class Commentaire < ActiveRecord::Base
belongs_to :piece_justificative belongs_to :piece_justificative
after_save :internal_notification after_create :notify
def header def header
"#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')
@ -12,9 +12,32 @@ class Commentaire < ActiveRecord::Base
private private
def internal_notification def notify
if email == dossier.user.email || dossier.invites_user.pluck(:email).to_a.include?(email) dossier_user_email = dossier.user.email
NotificationService.new('commentaire', self.dossier.id).notify invited_users_emails = dossier.invites_user.pluck(:email).to_a
case email
when I18n.t("dynamics.contact_email")
# The commentaire is a copy of an automated notification email
# we sent to a user, so do nothing
when dossier_user_email, *invited_users_emails
# A user or an inved user posted a commentaire,
# we need to notify the gestionnaires
notify_gestionnaires
else
# A gestionnaire posted a commentaire,
# we need to notify the user
notify_user
end end
end end
def notify_gestionnaires
NotificationService.new('commentaire', self.dossier.id).notify
end
def notify_user
NotificationMailer.new_answer(dossier).deliver_now!
end
end end

View file

@ -85,7 +85,7 @@ module MailTemplateConcern
when :libelle_procedure when :libelle_procedure
dossier.procedure.libelle dossier.procedure.libelle
when :date_de_decision when :date_de_decision
dossier.processed_at.present? ? dossier.processed_at.strftime("%d/%m/%Y") : "" dossier.processed_at.present? ? dossier.processed_at.localtime.strftime("%d/%m/%Y") : ""
else else
'--BALISE_NON_RECONNUE--' '--BALISE_NON_RECONNUE--'
end end

View file

@ -289,7 +289,7 @@ class Dossier < ActiveRecord::Base
else else
parts = [ parts = [
"Dossier déposé le ", "Dossier déposé le ",
initiated_at.strftime("%d/%m/%Y"), initiated_at.localtime.strftime("%d/%m/%Y"),
" sur la procédure ", " sur la procédure ",
procedure.libelle, procedure.libelle,
" gérée par l'organisme ", " gérée par l'organisme ",

View file

@ -9,6 +9,7 @@ class Gestionnaire < ActiveRecord::Base
has_many :assign_to, dependent: :destroy has_many :assign_to, dependent: :destroy
has_many :procedures, through: :assign_to has_many :procedures, through: :assign_to
has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures
has_many :followed_dossiers, through: :follows, source: :dossier
has_many :follows has_many :follows
has_many :preference_list_dossiers has_many :preference_list_dossiers
@ -17,10 +18,6 @@ class Gestionnaire < ActiveRecord::Base
include CredentialsSyncableConcern include CredentialsSyncableConcern
def dossiers_follow
@dossiers_follow ||= dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}")
end
def procedure_filter def procedure_filter
return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter]) return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter])
@ -75,10 +72,10 @@ class Gestionnaire < ActiveRecord::Base
end end
def notifications_for procedure def notifications_for procedure
procedure_ids = dossiers_follow.pluck(:procedure_id) procedure_ids = followed_dossiers.pluck(:procedure_id)
if procedure_ids.include?(procedure.id) if procedure_ids.include?(procedure.id)
return dossiers_follow.where(procedure_id: procedure.id) return followed_dossiers.where(procedure_id: procedure.id)
.inject(0) do |acc, dossier| .inject(0) do |acc, dossier|
acc += dossier.notifications.where(already_read: false).count acc += dossier.notifications.where(already_read: false).count
end end
@ -86,16 +83,9 @@ class Gestionnaire < ActiveRecord::Base
0 0
end end
def dossier_with_notification_for procedure def dossiers_with_notifications_count_for_procedure(procedure)
procedure_ids = dossiers_follow.pluck(:procedure_id) followed_dossiers_id = followed_dossiers.where(procedure: procedure).pluck(:id)
Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count
if procedure_ids.include?(procedure.id)
return dossiers_follow.where(procedure_id: procedure.id)
.inject(0) do |acc, dossier|
acc += ((dossier.notifications.where(already_read: false).count) > 0 ? 1 : 0)
end
end
0
end end
def dossiers_with_notifications_count def dossiers_with_notifications_count

View file

@ -25,7 +25,7 @@ class DossiersListGestionnaireService
end end
def suivi def suivi
@suivi ||= @current_devise_profil.dossiers_follow.merge(dossiers_to_display) @suivi ||= @current_devise_profil.followed_dossiers.merge(dossiers_to_display)
end end
def nouveaux def nouveaux

View file

@ -84,7 +84,7 @@
%h4 Options avancées %h4 Options avancées
%label{ for: :auto_archive_on } Archivage automatique le %label{ for: :auto_archive_on } Archivage automatique le
= f.text_field :auto_archive_on, id: 'auto_archive_on', value: @procedure.auto_archive_on.try{ |d| d.strftime("%d-%m-%Y") }, data: { provide: 'datepicker', 'date-language' => 'fr', 'date-format' => 'dd/mm/yyyy' } = f.text_field :auto_archive_on, id: 'auto_archive_on', value: @procedure.auto_archive_on.try{ |d| d.localtime.strftime("%d-%m-%Y") }, data: { provide: 'datepicker', 'date-language' => 'fr', 'date-format' => 'dd/mm/yyyy' }
(à 00h00) (à 00h00)
%p.help-block %p.help-block
%i.fa.fa-info-circle %i.fa.fa-info-circle

View file

@ -15,7 +15,7 @@
- unless admin.last_sign_in_at.nil? - unless admin.last_sign_in_at.nil?
= time_ago_in_words(l(admin.last_sign_in_at, format: "%d/%m/%Y %H:%M UTC +02:00")) = time_ago_in_words(l(admin.last_sign_in_at, format: "%d/%m/%Y %H:%M UTC +02:00"))
( (
= admin.last_sign_in_at.to_date.strftime('%d/%m/%Y') = admin.last_sign_in_at.to_date.localtime.strftime('%d/%m/%Y')
) )
%td %td
= admin.procedures.where(published: true).count = admin.procedures.where(published: true).count

View file

@ -12,4 +12,4 @@
<p> <p>
--- ---
<br> <br>
L'équipe TPS - tps@apientreprise.fr</p> L'équipe Téléprocédures Simplifiées</p>

View file

@ -24,7 +24,7 @@
.col-xs-8.entreprise-info= @facade.etablissement.naf .col-xs-8.entreprise-info= @facade.etablissement.naf
.row .row
.col-xs-4.entreprise-label Date de création : .col-xs-4.entreprise-label Date de création :
.col-xs-8.entreprise-info= Time.at(@facade.entreprise.date_creation).strftime "%d-%m-%Y" .col-xs-8.entreprise-info= Time.at(@facade.entreprise.date_creation).localtime.strftime "%d-%m-%Y"
.row .row
.col-xs-4.entreprise-label Effectif organisation : .col-xs-4.entreprise-label Effectif organisation :
.col-xs-8.entreprise-info= @facade.entreprise.effectif .col-xs-8.entreprise-info= @facade.entreprise.effectif

View file

@ -7,4 +7,4 @@
%h4.text-primary{ style: 'margin-top: 0px;' } Ajouter un fichier %h4.text-primary{ style: 'margin-top: 0px;' } Ajouter un fichier
= file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px;' = file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px;'
.col-md-6.text-right .col-md-6.text-right
%input#save-message.form-control.btn.btn-danger{ type: 'submit', value: 'ENVOYER' } = submit_tag 'Envoyer', id: 'save-message', class: 'form-control btn btn-danger', data: { disable_with: 'Envoi...' }

View file

@ -8,4 +8,4 @@ Vous venez d'être assigné à un administrateur sur la plateforme TPS. Voici qu
Bonne journée, Bonne journée,
--- ---
L'équipe TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -9,4 +9,4 @@ Vous venez d'être nommé accompagnateur sur la plateforme TPS. Pour mémoire, v
Bonne journée, Bonne journée,
--- ---
L'équipe TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -9,4 +9,4 @@ Afin de répondre à cette invitation, merci de vous inscrit avec l'adresse emai
Bonne journée. Bonne journée.
--- ---
L'équide TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -7,4 +7,4 @@ Pour le consulter, merci de suivre ce lien : <%= users_dossiers_invite_url(@invi
Bonne journée. Bonne journée.
--- ---
L'équide TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -0,0 +1,2 @@
%data.mj-w-data{ "data-apikey" => "1v5T", "data-base" => "http://app.mailjet.com", "data-height" => "328", "data-lang" => "fr_FR", "data-statics" => "statics", "data-token" => "11c89e7ddb46fbcdcb7f8fe5fdfca818", "data-w-id" => "39b", "data-width" => "640" }
%script{ src: 'http://app.mailjet.com/statics/js/widget.modal.js' }

View file

@ -25,6 +25,8 @@
%li.footer-column %li.footer-column
%ul.footer-links %ul.footer-links
%li.footer-link
%a{ href: '#', 'data-token' => '11c89e7ddb46fbcdcb7f8fe5fdfca818', onclick: 'mjOpenPopin(event, this)' } Newsletter
%li.footer-link %li.footer-link
= link_to "Contact", = link_to "Contact",
"mailto:#{t('dynamics.contact_email')}", "mailto:#{t('dynamics.contact_email')}",

View file

@ -1,6 +1,6 @@
#first-block #first-block
.dossiers-en-cours .dossiers-en-cours
.count= current_gestionnaire.dossiers_follow.count .count= current_gestionnaire.followed_dossiers.count
.text SUIVIS .text SUIVIS
.nouveaux-dossiers .nouveaux-dossiers
.count= current_gestionnaire.dossiers.nouveaux.count .count= current_gestionnaire.dossiers.nouveaux.count
@ -28,7 +28,7 @@
- if total_new > 0 - if total_new > 0
.badge.progress-bar-success{ title: 'Nouveaux dossiers' } .badge.progress-bar-success{ title: 'Nouveaux dossiers' }
= total_new = total_new
- unread_notif_count = procedure.notifications.unread.count - unread_notif_count = current_gestionnaire.dossiers_with_notifications_count_for_procedure(procedure)
- if unread_notif_count > 0 - if unread_notif_count > 0
.badge.progress-bar-warning{ title: 'Notifications' } .badge.progress-bar-warning{ title: 'Notifications' }
= unread_notif_count = unread_notif_count
@ -40,5 +40,5 @@
= link_to backoffice_dossier_path(dossier.id) do = link_to backoffice_dossier_path(dossier.id) do
.notification .notification
.dossier-index= "Dossier nº #{dossier.id}" .dossier-index= "Dossier nº #{dossier.id}"
.updated-at-index= dossier.first_unread_notification.created_at.strftime('%d/%m %H:%M') .updated-at-index= dossier.first_unread_notification.created_at.localtime.strftime('%d/%m %H:%M')
.count= dossier.unreaded_notifications.count .count= dossier.unreaded_notifications.count

View file

@ -45,7 +45,7 @@
%i.fa.fa-bell-o %i.fa.fa-bell-o
- @facade.last_notifications.each do |notification| - @facade.last_notifications.each do |notification|
.notification .notification
.updated-at= notification.updated_at.strftime('%d/%m/%Y %H:%M') .updated-at= notification.updated_at.localtime.strftime('%d/%m/%Y %H:%M')
= render partial: "layouts/left_panels/type_notif_fa", locals: { notification: notification } = render partial: "layouts/left_panels/type_notif_fa", locals: { notification: notification }
- if ['champs'].include?(notification.type_notif) - if ['champs'].include?(notification.type_notif)
- if notification.liste.size > 1 - if notification.liste.size > 1

View file

@ -1,3 +1,6 @@
.link-to-dossiers
= link_to 'retour aux dossiers', users_dossiers_path
#first-block #first-block
.en-cours .en-cours
%h2 Récapitulatif %h2 Récapitulatif

View file

@ -1,6 +1,5 @@
.col-xs-7.main-info .col-xs-7.main-info
%span{ 'data-toggle' => :tooltip, "data-placement" => :bottom, title: @facade.dossier.procedure.libelle } = @facade.dossier.procedure.libelle
= @facade.dossier.procedure.libelle
.col-xs-3.options .col-xs-3.options
.row .row
.col-xs-12 .col-xs-12

View file

@ -33,6 +33,7 @@
= render partial: "layouts/new_footer" = render partial: "layouts/new_footer"
= render partial: "layouts/google_analytics" = render partial: "layouts/google_analytics"
= render partial: "layouts/mailjet_newsletter"
= javascript_include_tag "application", "data-turbolinks-track" => true = javascript_include_tag "application", "data-turbolinks-track" => true
- if Rails.env == "test" - if Rails.env == "test"

View file

@ -6,4 +6,4 @@ Login : <%= @admin.email %>
Password : <%= @password %> Password : <%= @password %>
--- ---
L'équipe TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -11,4 +11,4 @@ Merci de ne pas répondre à ce mail. Postez directement vos questions dans votr
--- ---
--- ---
L'équide TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

View file

@ -12,4 +12,4 @@ Oubli de mot de passe, pas de problème :
Bonne journée, Bonne journée,
--- ---
L'équipe TPS - tps@apientreprise.fr L'équipe Téléprocédures Simplifiées

3
bin/bundle Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

4
bin/rails Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

4
bin/rake Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

34
bin/setup Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

29
bin/update Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

View file

@ -10,7 +10,7 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer, # 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 # note that it will be overwritten if you use your own mailer class
# with default "from" parameter. # with default "from" parameter.
config.mailer_sender = 'tps@apientreprise.fr' config.mailer_sender = "'Téléprocédures Simplifiées' <#{I18n.t('dynamics.contact_email')}>"
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer' # config.mailer = 'Devise::Mailer'

View file

@ -213,6 +213,24 @@ fr:
- oct. - oct.
- nov. - nov.
- déc. - déc.
month_names:
-
- janvier
- février
- mars
- avril
- mai
- juin
- juillet
- août
- septembre
- octobre
- novembre
- décembre
order:
- :day
- :month
- :year
day_names: day_names:
- dimanche - dimanche
- lundi - lundi
@ -225,24 +243,6 @@ fr:
default: "%d/%m/%Y" default: "%d/%m/%Y"
short: "%e %b" short: "%e %b"
long: "%e %B %Y" long: "%e %B %Y"
month_names:
-
- janvier
- février
- mars
- avril
- mai
- juin
- juillet
- août
- septembre
- octobre
- novembre
- décembre
order:
- :day
- :month
- :year
datetime: datetime:
distance_in_words: distance_in_words:
about_x_hours: about_x_hours:

View file

@ -45,27 +45,4 @@ describe Users::Dossiers::CommentairesController, type: :controller do
end end
end end
describe '#notify_user_with_mail' do
let(:commentaire){create(:commentaire)}
context 'when usager is writing a commentaire on dossier' do
before { sign_in commentaire.dossier.user }
it {
expect(NotificationMailer).to_not receive(:new_answer)
subject.send(:notify_user_with_mail, commentaire)
}
end
context 'when anybody else but usager is writing a commentaire' do
before { sign_in create(:user, email: 'administrateur@test.fr') }
it {
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject.send(:notify_user_with_mail, commentaire)
}
end
end
end end

View file

@ -1,14 +1,15 @@
require 'spec_helper' require 'spec_helper'
describe CommentaireDecorator do describe CommentaireDecorator do
let(:commentaire) { Timecop.freeze(Time.utc(2008, 9, 1, 10, 5, 0)) {create :commentaire} } let(:time) { Time.utc(2008, 9, 1, 10, 5, 0) }
let(:commentaire) { Timecop.freeze(time) { create :commentaire } }
let(:decorator) { commentaire.decorate } let(:decorator) { commentaire.decorate }
describe 'created_at_fr' do describe 'created_at_fr' do
subject { decorator.created_at_fr } subject { decorator.created_at_fr }
context 'when created_at have a value' do context 'when created_at have a value' do
it { is_expected.to eq '01/09/2008 - 10:05' } it { is_expected.to eq time.localtime.strftime('%d/%m/%Y - %H:%M') }
end end
end end
end end

View file

@ -50,10 +50,4 @@ describe EntrepriseDecorator do
expect(subject.pretty_capital_social).to eq('123 000,00 €') expect(subject.pretty_capital_social).to eq('123 000,00 €')
end end
end end
describe '#pretty_date_creation' do
it 'pretty print date creation' do
expect(subject.pretty_date_creation).to eq('28-01-2016')
end
end
end end

View file

@ -0,0 +1,24 @@
FactoryGirl.define do
factory :invite_user do
email 'plop@octo.com'
after(:build) do |invite, _evaluator|
if invite.dossier.nil?
invite.dossier = create(:dossier)
end
unless invite.user.nil?
invite.email = invite.user.email
end
end
trait :with_user do
after(:build) do |invite, _evaluator|
if invite.user.nil?
invite.user = create(:user)
invite.email = invite.user.email
end
end
end
end
end

View file

@ -5,10 +5,23 @@ RSpec.describe NotificationMailer, type: :mailer do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) } let(:dossier) { create(:dossier, user: user) }
let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') } let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') }
let (:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email) } subject { described_class.send_notification(dossier, email) }
it { expect(subject.subject).to eq(email.object_for_dossier) } it { expect(subject.subject).to eq(email.object_for_dossier) }
it { expect(subject.body).to eq(email.body_for_dossier) } it { expect(subject.body).to eq(email.body_for_dossier) }
it "creates a commentaire, which is not notified" do
described_class.send_notification(dossier, email).deliver_now
commentaire = Commentaire.last
notifications_count_after = Notification.count
expect(commentaire.dossier).to eq(dossier)
expect(commentaire.email).to eq("contact@tps.apientreprise.fr")
expect(commentaire.body).to eq("[object]<br><br>body")
expect(notifications_count_before).to eq(notifications_count_after)
end
end end
describe ".new_answer" do describe ".new_answer" do

View file

@ -8,4 +8,56 @@ describe Commentaire do
it { is_expected.to belong_to(:dossier) } it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:piece_justificative) } it { is_expected.to belong_to(:piece_justificative) }
describe "#notify" do
let(:procedure) { create(:procedure) }
let(:gestionnaire) { create(:gestionnaire) }
let(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: procedure) }
let(:user) { create(:user) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
let(:commentaire) { Commentaire.new(dossier: dossier) }
context "with a commentaire created by a user" do
it "calls notify_gestionnaires" do
expect(commentaire).to receive(:notify_gestionnaires)
commentaire.email = user.email
commentaire.save
end
end
context "with a commentaire created by an invited user" do
let(:user_invite) { create(:user) }
before do
FactoryGirl.create(:invite_user, email: "invite@tps.apientreprise.fr", dossier: dossier, user: user_invite)
end
it "calls notify_gestionnaires" do
expect(commentaire).to receive(:notify_gestionnaires)
commentaire.email = user_invite.email
commentaire.save
end
end
context "with a commentaire created by a gestionnaire" do
it "calls notify_user" do
expect(commentaire).to receive(:notify_user)
commentaire.email = gestionnaire.email
commentaire.save
end
end
context "with a commentaire automatically created (notification)" do
it "does not call notify_user or notify_gestionnaires" do
expect(commentaire).not_to receive(:notify_user)
expect(commentaire).not_to receive(:notify_gestionnaires)
commentaire.email = "contact@tps.apientreprise.fr"
commentaire.save
end
end
end
end end

View file

@ -116,19 +116,6 @@ describe Gestionnaire, type: :model do
end end
end end
describe '#dossiers_follow' do
let!(:dossier) { create :dossier, procedure: procedure, state: :initiated }
before do
create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id
end
subject { gestionnaire.dossiers_follow }
it { expect(Follow.all.size).to eq 1 }
it { expect(subject.first).to eq dossier }
end
describe '#build_default_preferences_list_dossier' do describe '#build_default_preferences_list_dossier' do
subject { gestionnaire.preference_list_dossiers } subject { gestionnaire.preference_list_dossiers }
@ -288,6 +275,13 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq(1) } it { is_expected.to eq(1) }
end end
context 'when there is one notification read' do
let(:notification){ create(:notification, already_read: true) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(0) }
end
context 'when there are many notifications for one dossier' do context 'when there are many notifications for one dossier' do
let(:notification){ create(:notification, already_read: false) } let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) } let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
@ -305,4 +299,52 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq(2) } it { is_expected.to eq(2) }
end end
end end
describe '#dossiers_with_notifications_count_for_procedure' do
subject { gestionnaire.dossiers_with_notifications_count_for_procedure(procedure) }
context 'without notifications' do
it { is_expected.to eq(0) }
end
context 'with a followed dossier' do
let!(:dossier){create(:dossier, procedure: procedure, state: 'received')}
let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) }
context 'with 1 notification' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
context 'with 1 read notification' do
let!(:notification){ create(:notification, already_read: true, dossier: dossier) }
it { is_expected.to eq(0) }
end
context 'with 2 notifications' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
context 'with another dossier' do
let!(:dossier2){create(:dossier, procedure: procedure, state: 'received')}
let!(:follow2){ create(:follow, dossier: dossier2, gestionnaire: gestionnaire) }
context 'and some notifications' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification3){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification4){ create(:notification, already_read: false, dossier: dossier2) }
let!(:notification5){ create(:notification, already_read: false, dossier: dossier2) }
it { is_expected.to eq(2) }
end
end
end
end
end end