Gestionnaire: add follow(dossier) method

This commit is contained in:
Simon Lehericey 2017-07-17 11:28:14 +02:00 committed by Mathieu Magnin
parent 033f08524f
commit e68f3332c1
2 changed files with 25 additions and 0 deletions

View file

@ -45,6 +45,12 @@ class Gestionnaire < ActiveRecord::Base
nil
end
def follow(dossier)
return if follow?(dossier)
followed_dossiers << dossier
end
def follow?(dossier)
followed_dossiers.include?(dossier)
end

View file

@ -73,6 +73,25 @@ describe Gestionnaire, type: :model do
end
end
describe 'follow' do
let(:dossier) { create :dossier }
let(:already_followed_dossier) { create :dossier }
before { gestionnaire.followed_dossiers << already_followed_dossier }
context 'when a gestionnaire follow a dossier for the first time' do
before { gestionnaire.follow(dossier) }
it { expect(gestionnaire.follow?(dossier)).to be true }
end
context 'when a gestionnaire follows a dossier already followed' do
before { gestionnaire.follow(already_followed_dossier) }
it { expect(gestionnaire.follow?(already_followed_dossier)).to be true }
end
end
describe '#follow?' do
let!(:dossier) { create :dossier, procedure: procedure }