Gestionnaire: add unfollow method
This commit is contained in:
parent
01da457ad0
commit
19b3416361
3 changed files with 19 additions and 1 deletions
|
@ -32,7 +32,7 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def unfollow
|
||||
current_gestionnaire.followed_dossiers.delete(dossier)
|
||||
current_gestionnaire.unfollow(dossier)
|
||||
flash.notice = "Vous ne suivez plus le dossier nº #{dossier.id}"
|
||||
|
||||
redirect_back(fallback_location: procedures_url)
|
||||
|
|
|
@ -40,6 +40,10 @@ class Gestionnaire < ActiveRecord::Base
|
|||
followed_dossiers << dossier
|
||||
end
|
||||
|
||||
def unfollow(dossier)
|
||||
followed_dossiers.delete(dossier)
|
||||
end
|
||||
|
||||
def follow?(dossier)
|
||||
followed_dossiers.include?(dossier)
|
||||
end
|
||||
|
|
|
@ -32,6 +32,20 @@ describe Gestionnaire, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#unfollow' do
|
||||
let(:already_followed_dossier) { create(:dossier) }
|
||||
before { gestionnaire.followed_dossiers << already_followed_dossier }
|
||||
|
||||
context 'when a gestionnaire unfollow a dossier already followed' do
|
||||
before do
|
||||
gestionnaire.unfollow(already_followed_dossier)
|
||||
already_followed_dossier.reload
|
||||
end
|
||||
|
||||
it { expect(gestionnaire.follow?(already_followed_dossier)).to be false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#follow?' do
|
||||
let!(:dossier) { create :dossier, procedure: procedure }
|
||||
|
||||
|
|
Loading…
Reference in a new issue