When gestionnaire follow an initiated dossier, this paste his state at 'updated'

This commit is contained in:
Xavier J 2016-09-09 15:55:03 +02:00
parent 955c984a88
commit c5035ca81e
4 changed files with 40 additions and 7 deletions

View file

@ -95,6 +95,8 @@ class Backoffice::DossiersController < ApplicationController
def follow def follow
follow = current_gestionnaire.toggle_follow_dossier params[:dossier_id] 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é') flash.notice = (follow.class == Follow ? 'Dossier suivi' : 'Dossier relaché')
redirect_to request.referer redirect_to request.referer
end end

View file

@ -97,7 +97,7 @@ class Dossier < ActiveRecord::Base
end end
def next_step! role, action def next_step! role, action
unless %w(initiate update comment valid submit receive refuse without_continuation close).include?(action) unless %w(initiate follow update comment valid submit receive refuse without_continuation close).include?(action)
fail 'action is not valid' fail 'action is not valid'
end end
@ -132,6 +132,10 @@ class Dossier < ActiveRecord::Base
elsif initiated? elsif initiated?
replied! replied!
end end
when 'follow'
if initiated?
updated!
end
when 'valid' when 'valid'
if updated? if updated?
validated! validated!

View file

@ -4,14 +4,19 @@ describe Backoffice::DossiersController, type: :controller do
before do before do
@request.env['HTTP_REFERER'] = TPS::Application::URL @request.env['HTTP_REFERER'] = TPS::Application::URL
end end
let(:procedure) { create :procedure }
let(:dossier) { create(:dossier, :with_entreprise) } let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) } let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 } let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) } let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
before do
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
end
describe 'GET #show' do describe 'GET #show' do
context 'gestionnaire is connected' do context 'gestionnaire is connected' do
before do before do
@ -223,6 +228,20 @@ describe Backoffice::DossiersController, type: :controller do
it { expect(subject.status).to eq 302 } 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 describe 'flash alert' do
context 'when dossier is not follow by gestionnaire' do context 'when dossier is not follow by gestionnaire' do
before do before do

View file

@ -219,6 +219,12 @@ describe Dossier do
it { is_expected.to eq('replied') } it { is_expected.to eq('replied') }
end end
context 'when is follow' do
let(:action) { 'follow' }
it { is_expected.to eq 'updated' }
end
context 'when is validated the dossier' do context 'when is validated the dossier' do
let(:action) { 'valid' } let(:action) { 'valid' }
@ -244,10 +250,7 @@ describe Dossier do
context 'when is updated dossier informations' do context 'when is updated dossier informations' do
let(:action) { 'update' } let(:action) { 'update' }
it { it { is_expected.to eq('updated') }
is_expected.to eq('updated')
}
end end
end end
@ -260,6 +263,12 @@ describe Dossier do
it { is_expected.to eq('replied') } it { is_expected.to eq('replied') }
end end
context 'when is follow' do
let(:action) { 'follow' }
it { is_expected.to eq 'replied' }
end
context 'when is validated the dossier' do context 'when is validated the dossier' do
let(:action) { 'valid' } let(:action) { 'valid' }
@ -453,7 +462,6 @@ describe Dossier do
end end
end end
context 'when dossier is at state closed' do context 'when dossier is at state closed' do
before do before do
dossier.closed! dossier.closed!