Merge pull request #659 from sgmap/fix_658

[Fix #658] when dossier linked to avis is hidden, do not crash applic…
This commit is contained in:
Mathieu Magnin 2017-08-28 10:23:59 +02:00 committed by GitHub
commit 47bb6250a3
3 changed files with 13 additions and 1 deletions

View file

@ -190,7 +190,7 @@ class StatsController < ApplicationController
average = Avis.with_answer average = Avis.with_answer
.where(created_at: min_date..max_date) .where(created_at: min_date..max_date)
.average("EXTRACT(EPOCH FROM updated_at - created_at) / 86400") .average("EXTRACT(EPOCH FROM avis.updated_at - avis.created_at) / 86400")
result = average ? average.to_f.round(2) : 0 result = average ? average.to_f.round(2) : 0

View file

@ -6,6 +6,7 @@ class Avis < ApplicationRecord
before_create :try_to_assign_gestionnaire before_create :try_to_assign_gestionnaire
after_create :notify_gestionnaire after_create :notify_gestionnaire
default_scope { joins(:dossier) }
scope :with_answer, -> { where.not(answer: nil) } scope :with_answer, -> { where.not(answer: nil) }
scope :without_answer, -> { where(answer: nil) } scope :without_answer, -> { where(answer: nil) }
scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) } scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) }

View file

@ -58,6 +58,17 @@ describe BackofficeController, type: :controller do
it { expect(response.body).to include("1 avis rendu") } it { expect(response.body).to include("1 avis rendu") }
it { expect(response.body).to include(dossier.procedure.libelle) } it { expect(response.body).to include(dossier.procedure.libelle) }
end end
context 'when dossier linked to avis is hidden' do
before do
dossier.update_attributes(hidden_at: Time.now)
get :invitations
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include("0 avis à rendre") }
it { expect(response.body).to include("0 avis rendu") }
end
end end
end end
end end