Add Follow.unfollowed_at

The active scopes is used indirectly in the dossier<->gestionnaire associations: the existing tests in dossier and gestionnaire just work™.
This commit is contained in:
Nicolas Bouilleaud 2019-06-07 14:59:49 +02:00 committed by Pierre de La Morinerie
parent d417907f36
commit be4c575622
5 changed files with 29 additions and 6 deletions

View file

@ -2,10 +2,12 @@ class Follow < ApplicationRecord
belongs_to :gestionnaire
belongs_to :dossier
validates :gestionnaire_id, uniqueness: { scope: :dossier_id }
validates :gestionnaire_id, uniqueness: { scope: [:dossier_id, :unfollowed_at] }
before_create :set_default_date
scope :active, -> { where(unfollowed_at: nil) }
private
def set_default_date