Remove previous attempt but steal its spec
This commit is contained in:
parent
376013ef03
commit
594cda3ee3
3 changed files with 133 additions and 173 deletions
|
@ -632,47 +632,6 @@ class Procedure < ApplicationRecord
|
||||||
draft_revision.deep_clone(include: [:revision_types_de_champ, :revision_types_de_champ_private])
|
draft_revision.deep_clone(include: [:revision_types_de_champ, :revision_types_de_champ_private])
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers_count_for_instructeur(instructeur)
|
|
||||||
query = <<-EOF
|
|
||||||
SELECT
|
|
||||||
COUNT(*) FILTER ( WHERE "dossiers"."state" in ('en_construction', 'en_instruction') and "follows"."id" IS NULL and not "dossiers"."archived") AS a_suivre,
|
|
||||||
COUNT(*) FILTER ( WHERE "dossiers"."state" in ('en_construction', 'en_instruction') and "follows"."instructeur_id" = :instructeur_id and not "dossiers"."archived" and "follows"."unfollowed_at" IS NULL) AS suivis,
|
|
||||||
COUNT(*) FILTER ( WHERE "dossiers"."state" in ('accepte', 'refuse', 'sans_suite') and not "dossiers"."archived" ) AS termines,
|
|
||||||
COUNT(*) FILTER ( WHERE "dossiers"."state" != 'brouillon' and not "dossiers"."archived" ) AS total,
|
|
||||||
COUNT(*) FILTER ( WHERE "dossiers"."archived" ) AS archived
|
|
||||||
FROM
|
|
||||||
"dossiers"
|
|
||||||
INNER JOIN
|
|
||||||
"groupe_instructeurs"
|
|
||||||
ON "dossiers"."groupe_instructeur_id" = "groupe_instructeurs"."id"
|
|
||||||
INNER JOIN
|
|
||||||
"assign_tos"
|
|
||||||
ON "groupe_instructeurs"."id" = "assign_tos"."groupe_instructeur_id"
|
|
||||||
INNER JOIN
|
|
||||||
"procedures"
|
|
||||||
ON "groupe_instructeurs"."procedure_id" = "procedures"."id"
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
"follows"
|
|
||||||
ON "follows"."dossier_id" = "dossiers"."id"
|
|
||||||
AND "follows"."unfollowed_at" IS NULL
|
|
||||||
WHERE
|
|
||||||
"dossiers"."hidden_at" IS NULL
|
|
||||||
AND "assign_tos"."instructeur_id" = :instructeur_id
|
|
||||||
AND "procedures"."id" = :procedure_id
|
|
||||||
GROUP BY
|
|
||||||
groupe_instructeurs.procedure_id, procedures.libelle
|
|
||||||
EOF
|
|
||||||
|
|
||||||
sanitized_query = ActiveRecord::Base.sanitize_sql([
|
|
||||||
query,
|
|
||||||
instructeur_id: instructeur.id,
|
|
||||||
procedure_id: self.id,
|
|
||||||
now: Time.zone.now
|
|
||||||
])
|
|
||||||
|
|
||||||
Procedure.connection.select_all(sanitized_query).first || { "a_suivre" => 0, "suivis" => 0, "termines" => 0, "total" => 0, "archived" => 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def before_publish
|
def before_publish
|
||||||
|
|
|
@ -568,6 +568,139 @@ describe Instructeur, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#dossiers_count_summary" do
|
||||||
|
let(:instructeur_2) { create(:instructeur) }
|
||||||
|
let(:procedure) { create(:procedure, instructeurs: [instructeur_2]) }
|
||||||
|
let(:gi_1) { procedure.groupe_instructeurs.first }
|
||||||
|
let(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
|
||||||
|
let(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
|
||||||
|
|
||||||
|
subject do
|
||||||
|
instructeur_2.dossiers_count_summary([gi_1.id, gi_2.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when logged in, and belonging to gi_1, gi_2" do
|
||||||
|
before do
|
||||||
|
instructeur.groupe_instructeurs << gi_2
|
||||||
|
end
|
||||||
|
|
||||||
|
context "without any dossier" do
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(0) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a new brouillon dossier' do
|
||||||
|
let!(:brouillon_dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(0) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a new dossier without follower' do
|
||||||
|
let!(:new_unfollow_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(1) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(1) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
|
||||||
|
context 'and dossiers without follower on each of the others groups' do
|
||||||
|
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
||||||
|
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
||||||
|
|
||||||
|
before { subject }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(2) }
|
||||||
|
it { expect(subject['tous']).to eq(2) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a new dossier with a follower' do
|
||||||
|
let!(:new_followed_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
instructeur_2.followed_dossiers << new_followed_dossier
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(1) }
|
||||||
|
it { expect(subject['traites']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(1) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
|
||||||
|
context 'and dossier with a follower on each of the others groups' do
|
||||||
|
let!(:new_follow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
||||||
|
let!(:new_follow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
instructeur_2.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
|
||||||
|
end
|
||||||
|
|
||||||
|
# followed dossiers on another groupe should not be displayed
|
||||||
|
it { expect(subject['suivis']).to eq(2) }
|
||||||
|
it { expect(subject['tous']).to eq(2) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and dossier with a follower is unfollowed' do
|
||||||
|
before do
|
||||||
|
instructeur_2.unfollow(new_followed_dossier)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(1) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(1) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a termine dossier' do
|
||||||
|
let!(:termine_dossier) { create(:dossier, :accepte, procedure: procedure) }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(1) }
|
||||||
|
it { expect(subject['tous']).to eq(1) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
|
||||||
|
context 'and terminer dossiers on each of the others groups' do
|
||||||
|
let!(:termine_dossier_on_gi_2) { create(:dossier, :accepte, groupe_instructeur: gi_2) }
|
||||||
|
let!(:termine_dossier_on_gi_3) { create(:dossier, :accepte, groupe_instructeur: gi_3) }
|
||||||
|
|
||||||
|
before { subject }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(2) }
|
||||||
|
it { expect(subject['tous']).to eq(2) }
|
||||||
|
it { expect(subject['archives']).to eq(0) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an archives dossier' do
|
||||||
|
let!(:archives_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
|
||||||
|
|
||||||
|
it { expect(subject['a_suivre']).to eq(0) }
|
||||||
|
it { expect(subject['suivis']).to eq(0) }
|
||||||
|
it { expect(subject['traites']).to eq(0) }
|
||||||
|
it { expect(subject['tous']).to eq(0) }
|
||||||
|
it { expect(subject['archives']).to eq(1) }
|
||||||
|
|
||||||
|
context 'and terminer dossiers on each of the others groups' do
|
||||||
|
let!(:archives_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
|
||||||
|
let!(:archives_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3, archived: true) }
|
||||||
|
|
||||||
|
it { expect(subject['archives']).to eq(2) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
||||||
|
|
|
@ -1030,136 +1030,4 @@ describe Procedure do
|
||||||
it { is_expected.to be false }
|
it { is_expected.to be false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#dossiers_count_for_instructeur" do
|
|
||||||
let(:instructeur) { create(:instructeur) }
|
|
||||||
let(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
|
||||||
let(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
|
|
||||||
let(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
|
|
||||||
|
|
||||||
subject do
|
|
||||||
procedure.dossiers_count_for_instructeur(instructeur)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when logged in, and belonging to gi_1, gi_2" do
|
|
||||||
before do
|
|
||||||
instructeur.groupe_instructeurs << gi_2
|
|
||||||
end
|
|
||||||
|
|
||||||
context "without any dossier" do
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(0) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a new brouillon dossier' do
|
|
||||||
let!(:brouillon_dossier) { create(:dossier, procedure: procedure) }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(0) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a new dossier without follower' do
|
|
||||||
let!(:new_unfollow_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(1) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(1) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
|
|
||||||
context 'and dossiers without follower on each of the others groups' do
|
|
||||||
let!(:new_unfollow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
|
||||||
let!(:new_unfollow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
|
||||||
|
|
||||||
before { subject }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(2) }
|
|
||||||
it { expect(subject['total']).to eq(2) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a new dossier with a follower' do
|
|
||||||
let!(:new_followed_dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
instructeur.followed_dossiers << new_followed_dossier
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(1) }
|
|
||||||
it { expect(subject['termines']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(1) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
|
|
||||||
context 'and dossier with a follower on each of the others groups' do
|
|
||||||
let!(:new_follow_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2) }
|
|
||||||
let!(:new_follow_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
instructeur.followed_dossiers << new_follow_dossier_on_gi_2 << new_follow_dossier_on_gi_3
|
|
||||||
end
|
|
||||||
|
|
||||||
# followed dossiers on another groupe should not be displayed
|
|
||||||
it { expect(subject['suivis']).to eq(2) }
|
|
||||||
it { expect(subject['total']).to eq(2) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and dossier with a follower is unfollowed' do
|
|
||||||
before do
|
|
||||||
instructeur.unfollow(new_followed_dossier)
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(1) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(1) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a termine dossier' do
|
|
||||||
let!(:termine_dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(1) }
|
|
||||||
it { expect(subject['total']).to eq(1) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
|
|
||||||
context 'and terminer dossiers on each of the others groups' do
|
|
||||||
let!(:termine_dossier_on_gi_2) { create(:dossier, :accepte, groupe_instructeur: gi_2) }
|
|
||||||
let!(:termine_dossier_on_gi_3) { create(:dossier, :accepte, groupe_instructeur: gi_3) }
|
|
||||||
|
|
||||||
before { subject }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(2) }
|
|
||||||
it { expect(subject['total']).to eq(2) }
|
|
||||||
it { expect(subject['archived']).to eq(0) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with an archived dossier' do
|
|
||||||
let!(:archived_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
|
|
||||||
|
|
||||||
it { expect(subject['a_suivre']).to eq(0) }
|
|
||||||
it { expect(subject['suivis']).to eq(0) }
|
|
||||||
it { expect(subject['termines']).to eq(0) }
|
|
||||||
it { expect(subject['total']).to eq(0) }
|
|
||||||
it { expect(subject['archived']).to eq(1) }
|
|
||||||
|
|
||||||
context 'and terminer dossiers on each of the others groups' do
|
|
||||||
let!(:archived_dossier_on_gi_2) { create(:dossier, :en_instruction, groupe_instructeur: gi_2, archived: true) }
|
|
||||||
let!(:archived_dossier_on_gi_3) { create(:dossier, :en_instruction, groupe_instructeur: gi_3, archived: true) }
|
|
||||||
|
|
||||||
it { expect(subject['archived']).to eq(2) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue