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

View file

@ -97,7 +97,7 @@ class Dossier < ActiveRecord::Base
end
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'
end
@ -132,6 +132,10 @@ class Dossier < ActiveRecord::Base
elsif initiated?
replied!
end
when 'follow'
if initiated?
updated!
end
when 'valid'
if updated?
validated!

View file

@ -4,14 +4,19 @@ describe Backoffice::DossiersController, type: :controller do
before do
@request.env['HTTP_REFERER'] = TPS::Application::URL
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_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
before do
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
end
describe 'GET #show' do
context 'gestionnaire is connected' do
before do
@ -223,6 +228,20 @@ describe Backoffice::DossiersController, type: :controller do
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

View file

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