Gestionnaire: refactor follow?

This commit is contained in:
Simon Lehericey 2017-07-17 13:13:20 +02:00 committed by Mathieu Magnin
parent 8fdc16d89f
commit 033f08524f
4 changed files with 5 additions and 7 deletions

View file

@ -45,10 +45,8 @@ class Gestionnaire < ActiveRecord::Base
nil nil
end end
def follow? dossier_id def follow?(dossier)
dossier_id = dossier_id.id if dossier_id.class == Dossier followed_dossiers.include?(dossier)
Follow.where(gestionnaire_id: id, dossier_id: dossier_id).any?
end end
def assigned_on_procedure?(procedure_id) def assigned_on_procedure?(procedure_id)

View file

@ -52,7 +52,7 @@
= value = value
%td.center %td.center
- if current_gestionnaire.follow?(dossier.id) - if current_gestionnaire.follow?(dossier)
= link_to('Quitter', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-danger', id: "suivre_dossier_#{dossier.id}") = link_to('Quitter', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-danger', id: "suivre_dossier_#{dossier.id}")
- else - else
= link_to('Suivre', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-primary', id: "suivre_dossier_#{dossier.id}") = link_to('Suivre', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-primary', id: "suivre_dossier_#{dossier.id}")

View file

@ -4,7 +4,7 @@
- if current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id) - if current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id)
.row .row
.col-xs-12 .col-xs-12
- if current_gestionnaire.follow?(@facade.dossier.id) - if current_gestionnaire.follow?(@facade.dossier)
= link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), "data-method" => :put, class: "button-navbar-action", id: "suivre_dossier_#{@facade.dossier.id}" do = link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), "data-method" => :put, class: "button-navbar-action", id: "suivre_dossier_#{@facade.dossier.id}" do
%i.fa.fa-user-times %i.fa.fa-user-times
Ne plus suivre Ne plus suivre

View file

@ -76,7 +76,7 @@ describe Gestionnaire, type: :model do
describe '#follow?' do describe '#follow?' do
let!(:dossier) { create :dossier, procedure: procedure } let!(:dossier) { create :dossier, procedure: procedure }
subject { gestionnaire.follow? dossier.id } subject { gestionnaire.follow?(dossier) }
context 'when gestionnaire follow a dossier' do context 'when gestionnaire follow a dossier' do
before do before do