feat(dossier): pending resolution state
This commit is contained in:
parent
2c79ca94f5
commit
d73b96ea40
3 changed files with 37 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
class DossierResolution < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
belongs_to :commentaire
|
||||
|
||||
scope :pending, -> { where(resolved_at: nil) }
|
||||
end
|
||||
|
|
28
spec/models/concern/dossier_resolvable_concern_spec.rb
Normal file
28
spec/models/concern/dossier_resolvable_concern_spec.rb
Normal 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
|
Loading…
Reference in a new issue