feat(dossier): pending resolution state

This commit is contained in:
Colin Darie 2023-02-28 15:11:48 +01:00
parent 2c79ca94f5
commit d73b96ea40
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
3 changed files with 37 additions and 0 deletions

View file

@ -3,5 +3,12 @@ module DossierResolvableConcern
included do
has_many :resolutions, class_name: 'DossierResolution', dependent: :destroy
def pending_resolution?
# We don't want to show any alert if user is not allowed to modify the dossier
return false unless en_construction?
resolutions.pending.exists?
end
end
end

View file

@ -12,4 +12,6 @@
class DossierResolution < ApplicationRecord
belongs_to :dossier
belongs_to :commentaire
scope :pending, -> { where(resolved_at: nil) }
end

View file

@ -0,0 +1,28 @@
describe DossierResolvableConcern do
describe "#pending_resolution?" do
let(:dossier) { create(:dossier, :en_construction) }
context "when dossier has no resolution" do
it { expect(dossier.pending_resolution?).to be_falsey }
end
context "when dossier has a pending resolution" do
before { create(:dossier_resolution, dossier:) }
it { expect(dossier.pending_resolution?).to be_truthy }
end
context "when dossier has a resolved resolution" do
before { create(:dossier_resolution, :resolved, dossier:) }
it { expect(dossier.pending_resolution?).to be_falsey }
end
context "when dossier is not en_construction" do
let(:dossier) { create(:dossier, :en_instruction) }
before { create(:dossier_resolution, dossier:) }
it { expect(dossier.pending_resolution?).to be_falsey }
end
end
end