Merge branch 'staging'

This commit is contained in:
gregoirenovel 2017-05-16 11:28:42 +02:00
commit b8a10b91c1
49 changed files with 331 additions and 133 deletions

1
.gitignore vendored
View file

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

View file

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

View file

@ -35,15 +35,12 @@ class CommentairesController < ApplicationController
end
@commentaire.body = params['texte_commentaire']
saved = false
unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
saved = @commentaire.save unless flash.alert
@commentaire.save unless flash.alert
else
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
end
notify_user_with_mail(@commentaire) if saved
if is_gestionnaire?
unless current_gestionnaire.follow? @commentaire.dossier
current_gestionnaire.toggle_follow_dossier @commentaire.dossier
@ -63,10 +60,4 @@ class CommentairesController < ApplicationController
def is_gestionnaire?
false
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

View file

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

View file

@ -18,7 +18,7 @@ class DossiersListFacades
end
def total_dossier_follow
@current_devise_profil.dossiers_follow.count
@current_devise_profil.followed_dossiers.count
end
def total_new_dossier
@ -30,7 +30,7 @@ class DossiersListFacades
end
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
def unread_notifications

View file

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

View file

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

View file

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

View file

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

View file

@ -1,14 +1,15 @@
class NotificationMailer < ApplicationMailer
default from: 'tps@apientreprise.fr',
to: Proc.new { @user.email }
default to: Proc.new { @user.email }
after_action :create_commentaire_for_notification, only: :send_notification
def send_notification dossier, mail_template
vars_mailer(dossier)
obj = mail_template.object_for_dossier dossier
body = mail_template.body_for_dossier dossier
@obj = mail_template.object_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
def new_answer dossier
@ -17,6 +18,14 @@ class NotificationMailer < ApplicationMailer
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
@dossier = dossier
@user = dossier.user

View file

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

View file

@ -4,7 +4,7 @@ class Commentaire < ActiveRecord::Base
belongs_to :piece_justificative
after_save :internal_notification
after_create :notify
def header
"#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')
@ -12,9 +12,32 @@ class Commentaire < ActiveRecord::Base
private
def internal_notification
if email == dossier.user.email || dossier.invites_user.pluck(:email).to_a.include?(email)
def notify
dossier_user_email = dossier.user.email
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
def notify_gestionnaires
NotificationService.new('commentaire', self.dossier.id).notify
end
def notify_user
NotificationMailer.new_answer(dossier).deliver_now!
end
end

View file

@ -85,7 +85,7 @@ module MailTemplateConcern
when :libelle_procedure
dossier.procedure.libelle
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
'--BALISE_NON_RECONNUE--'
end

View file

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

View file

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

View file

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

View file

@ -84,7 +84,7 @@
%h4 Options avancées
%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)
%p.help-block
%i.fa.fa-info-circle

View file

@ -15,7 +15,7 @@
- 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"))
(
= admin.last_sign_in_at.to_date.strftime('%d/%m/%Y')
= admin.last_sign_in_at.to_date.localtime.strftime('%d/%m/%Y')
)
%td
= admin.procedures.where(published: true).count

View file

@ -12,4 +12,4 @@
<p>
---
<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
.row
.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
.col-xs-4.entreprise-label Effectif organisation :
.col-xs-8.entreprise-info= @facade.entreprise.effectif

View file

@ -7,4 +7,4 @@
%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;'
.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,
---
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,
---
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.
---
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.
---
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: 'https://app.mailjet.com/statics/js/widget.modal.js' }

View file

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

View file

@ -1,6 +1,6 @@
#first-block
.dossiers-en-cours
.count= current_gestionnaire.dossiers_follow.count
.count= current_gestionnaire.followed_dossiers.count
.text SUIVIS
.nouveaux-dossiers
.count= current_gestionnaire.dossiers.nouveaux.count
@ -28,7 +28,7 @@
- if total_new > 0
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
= 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
.badge.progress-bar-warning{ title: 'Notifications' }
= unread_notif_count
@ -40,5 +40,5 @@
= link_to backoffice_dossier_path(dossier.id) do
.notification
.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

View file

@ -45,7 +45,7 @@
%i.fa.fa-bell-o
- @facade.last_notifications.each do |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 }
- if ['champs'].include?(notification.type_notif)
- if notification.liste.size > 1

View file

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

View file

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

View file

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

View file

@ -6,4 +6,4 @@ Login : <%= @admin.email %>
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,
---
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,
# note that it will be overwritten if you use your own mailer class
# 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.
# config.mailer = 'Devise::Mailer'

View file

@ -213,18 +213,6 @@ fr:
- oct.
- nov.
- déc.
day_names:
- dimanche
- lundi
- mardi
- mercredi
- jeudi
- vendredi
- samedi
formats:
default: "%d/%m/%Y"
short: "%e %b"
long: "%e %B %Y"
month_names:
-
- janvier
@ -243,6 +231,18 @@ fr:
- :day
- :month
- :year
day_names:
- dimanche
- lundi
- mardi
- mercredi
- jeudi
- vendredi
- samedi
formats:
default: "%d/%m/%Y"
short: "%e %b"
long: "%e %B %Y"
datetime:
distance_in_words:
about_x_hours:

View file

@ -45,27 +45,4 @@ describe Users::Dossiers::CommentairesController, type: :controller do
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

View file

@ -1,14 +1,15 @@
require 'spec_helper'
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 }
describe 'created_at_fr' do
subject { decorator.created_at_fr }
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

View file

@ -50,10 +50,4 @@ describe EntrepriseDecorator do
expect(subject.pretty_capital_social).to eq('123 000,00 €')
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

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(:dossier) { create(:dossier, user: user) }
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) }
it { expect(subject.subject).to eq(email.object_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
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(: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

View file

@ -116,19 +116,6 @@ describe Gestionnaire, type: :model do
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
subject { gestionnaire.preference_list_dossiers }
@ -288,6 +275,13 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq(1) }
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
let(:notification){ create(:notification, already_read: false) }
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) }
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