Merge pull request #1620 from betagouv/frederic/fix_1619-invitation_on_dossier_for_removed_procedure
[Fix #1619] Do not consider invitations to deleted dossiers
This commit is contained in:
commit
a02e749c03
2 changed files with 25 additions and 0 deletions
|
@ -10,4 +10,11 @@ class Invite < ApplicationRecord
|
|||
validates :email, uniqueness: { scope: :dossier_id }
|
||||
|
||||
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
|
||||
|
||||
# #1619 When an administrateur deletes a `Procedure`, its `hidden_at` field, and
|
||||
# the `hidden_at` field of its `Dossier`s, get set, effectively removing the Procedure
|
||||
# and Dossier from their respective `default_scope`s.
|
||||
# Therefore, we also remove `Invite`s for such effectively deleted `Dossier`s
|
||||
# from their default scope.
|
||||
default_scope { joins(:dossier).where(dossiers: { hidden_at: nil }) }
|
||||
end
|
||||
|
|
|
@ -56,4 +56,22 @@ describe Invite do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#default_scope" do
|
||||
let(:dossier) { create(:dossier, hidden_at: hidden_at) }
|
||||
let!(:invite) { create(:invite, email: "email@totor.com", dossier: dossier) }
|
||||
|
||||
context "when dossier is not hidden" do
|
||||
let(:hidden_at) { nil }
|
||||
|
||||
it { expect(Invite.count).to eq(1) }
|
||||
it { expect(Invite.all).to include(invite) }
|
||||
end
|
||||
|
||||
context "when dossier is hidden" do
|
||||
let(:hidden_at) { 1.day.ago }
|
||||
|
||||
it { expect(Invite.count).to eq(0) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue