Merge pull request #759 from sgmap/update_follow_mechanisme

Update follow mechanisme
This commit is contained in:
LeSim 2017-10-05 17:02:35 +02:00 committed by GitHub
commit 82ae008d9c
5 changed files with 29 additions and 1 deletions

View file

@ -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,7 @@ module NewGestionnaire
def archive
dossier.update_attributes(archived: true)
current_gestionnaire.unfollow(dossier)
redirect_back(fallback_location: procedures_url)
end
@ -50,6 +51,7 @@ module NewGestionnaire
def create_commentaire
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier))
current_gestionnaire.follow(dossier)
flash.notice = "Message envoyé"
redirect_to messagerie_dossier_path(dossier.procedure, dossier)
end

View file

@ -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

View file

@ -55,12 +55,15 @@ describe NewGestionnaire::DossiersController, type: :controller do
describe '#archive' do
before do
gestionnaire.follow(dossier)
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
dossier.reload
gestionnaire.reload
end
it { expect(dossier.archived).to be true }
it { expect(response).to redirect_to(procedures_url) }
it { expect(gestionnaire.followed_dossiers).not_to include(dossier) }
end
describe '#unarchive' do
@ -121,6 +124,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
it { expect(saved_commentaire.email).to eq(gestionnaire.email) }
it { expect(saved_commentaire.dossier).to eq(dossier) }
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
it { expect(gestionnaire.followed_dossiers).to include(dossier) }
end
describe "#create_avis" do

View file

@ -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 }

View file

@ -408,17 +408,21 @@ describe Procedure do
let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) }
let!(:dossier2) { create(:dossier, procedure: procedure) }
let(:gestionnaire) { create(:gestionnaire) }
it { expect(Dossier.count).to eq(2) }
it { expect(Dossier.all).to include(dossier, dossier2) }
context "when hidding procedure" do
before do
gestionnaire.followed_dossiers << dossier
procedure.hide!
gestionnaire.reload
end
it { expect(procedure.dossiers.count).to eq(0) }
it { expect(Dossier.count).to eq(0) }
it { expect(gestionnaire.followed_dossiers).not_to include(dossier) }
end
end