Follow: remove old backoffice follow and toggle_follow

This commit is contained in:
Simon Lehericey 2017-07-17 12:27:33 +02:00 committed by Mathieu Magnin
parent a7f270bac4
commit 95fbd1824a
5 changed files with 0 additions and 121 deletions

View file

@ -145,15 +145,6 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
redirect_to backoffice_dossier_path(id: dossier.id)
end
def follow
follow = current_gestionnaire.toggle_follow_dossier params[:dossier_id]
current_gestionnaire.dossiers.find(params[:dossier_id]).next_step! 'gestionnaire', 'follow'
flash.notice = (follow.class == Follow ? 'Dossier suivi' : 'Dossier relaché')
redirect_to request.referer
end
def reload_smartlisting
begin
@liste = URI(request.referer).query.split('=').second

View file

@ -34,17 +34,6 @@ class Gestionnaire < ActiveRecord::Base
dossiers.where(id: dossier_id).any?
end
def toggle_follow_dossier dossier_id
dossier = dossier_id
dossier = Dossier.find(dossier_id) unless dossier_id.class == Dossier
Follow.create!(dossier: dossier, gestionnaire: self)
rescue ActiveRecord::RecordInvalid
Follow.where(dossier: dossier, gestionnaire: self).delete_all
rescue ActiveRecord::RecordNotFound
nil
end
def follow(dossier)
return if follow?(dossier)

View file

@ -190,7 +190,6 @@ Rails.application.routes.draw do
post 'unarchive'
end
post 'reopen' => 'dossiers#reopen'
put 'follow' => 'dossiers#follow'
resources :commentaires, only: [:index]
resources :avis, only: [:create, :update]
end

View file

@ -369,46 +369,6 @@ describe Backoffice::DossiersController, type: :controller do
end
end
describe 'PUT #toggle_follow' do
before do
sign_in gestionnaire
end
subject { put :follow, params: {dossier_id: dossier_id} }
it { expect(subject.status).to eq 302 }
context 'when dossier is at state initiated' do
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
before do
subject
dossier.reload
end
it 'change state for updated' do
expect(dossier.state).to eq 'updated'
end
end
describe 'flash alert' do
context 'when dossier is not follow by gestionnaire' do
before do
subject
end
it { expect(flash[:notice]).to have_content 'Dossier suivi' }
end
context 'when dossier is follow by gestionnaire' do
before do
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier.id
subject
end
it { expect(flash[:notice]).to have_content 'Dossier relaché' }
end
end
end
describe 'POST #reopen' do
before do
dossier.received!

View file

@ -13,66 +13,6 @@ describe Gestionnaire, type: :model do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2
end
describe '#toggle_follow_dossier' do
let!(:dossier) { create :dossier, procedure: procedure }
subject { gestionnaire.toggle_follow_dossier dossier_id }
context 'when dossier id not valid' do
let(:dossier_id) { 0 }
it { expect(subject).to eq nil }
end
context 'when dossier id is valid' do
let(:dossier_id) { dossier.id }
context 'when dossier is not follow by gestionnaire' do
it 'value change in database' do
expect { subject }.to change(Follow, :count).by(1)
end
it { expect(subject).to be_an_instance_of Follow }
end
context 'when dossier is follow by gestionnaire' do
before do
create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id
end
it 'value change in database' do
expect { subject }.to change(Follow, :count).by(-1)
end
it { expect(subject).to eq 1 }
end
end
context 'when dossier instance is past' do
let(:dossier_id) { dossier }
context 'when dossier is not follow by gestionnaire' do
it 'value change in database' do
expect { subject }.to change(Follow, :count).by(1)
end
it { expect(subject).to be_an_instance_of Follow }
end
context 'when dossier is follow by gestionnaire' do
before do
create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id
end
it 'value change in database' do
expect { subject }.to change(Follow, :count).by(-1)
end
it { expect(subject).to eq 1 }
end
end
end
describe 'follow' do
let(:dossier) { create :dossier }
let(:already_followed_dossier) { create :dossier }