Add “previously followed” dossiers and gestionnaires
Using an “inactive” Follow scope, similar to the “active” scope. (I was tempted to use a default_scope, but this breaks when trying to `unscope` it in associations.)
This commit is contained in:
parent
be4c575622
commit
6b90bc1ea1
4 changed files with 6 additions and 0 deletions
|
@ -27,7 +27,9 @@ class Dossier < ApplicationRecord
|
|||
has_many :commentaires, dependent: :destroy
|
||||
has_many :invites, dependent: :destroy
|
||||
has_many :follows, -> { active }
|
||||
has_many :previous_follows, -> { inactive }, class_name: 'Follow'
|
||||
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
|
||||
has_many :previous_followers_gestionnaires, -> { distinct }, through: :previous_follows, source: :gestionnaire
|
||||
has_many :avis, dependent: :destroy
|
||||
|
||||
has_many :dossier_operation_logs, dependent: :destroy
|
||||
|
|
|
@ -7,6 +7,7 @@ class Follow < ApplicationRecord
|
|||
before_create :set_default_date
|
||||
|
||||
scope :active, -> { where(unfollowed_at: nil) }
|
||||
scope :inactive, -> { where.not(unfollowed_at: nil) }
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ class Gestionnaire < ApplicationRecord
|
|||
|
||||
has_many :dossiers, -> { state_not_brouillon }, through: :procedures
|
||||
has_many :follows, -> { active }
|
||||
has_many :previous_follows, -> { inactive }, class_name: 'Follow'
|
||||
has_many :followed_dossiers, through: :follows, source: :dossier
|
||||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :avis
|
||||
has_many :dossiers_from_avis, through: :avis, source: :dossier
|
||||
has_many :trusted_device_tokens
|
||||
|
|
|
@ -67,6 +67,7 @@ describe Gestionnaire, type: :model do
|
|||
end
|
||||
|
||||
it { expect(gestionnaire.follow?(already_followed_dossier)).to be false }
|
||||
it { expect(gestionnaire.previously_followed_dossiers).to include(already_followed_dossier) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue