Add an action to set a dossier as 'recu'.

This commit is contained in:
Guillaume Lazzara 2016-08-25 15:21:25 +02:00
parent e4cf25b677
commit 0120ce2a32
7 changed files with 92 additions and 28 deletions

View file

@ -48,6 +48,15 @@ class Backoffice::DossiersController < ApplicationController
render 'show'
end
def receive
create_dossier_facade params[:dossier_id]
@facade.dossier.next_step! 'gestionnaire', 'receive'
flash.notice = 'Dossier considéré comme reçu.'
render 'show'
end
def close
create_dossier_facade params[:dossier_id]

View file

@ -87,7 +87,7 @@ class Dossier < ActiveRecord::Base
end
def next_step! role, action
unless %w(initiate update comment valid submit close).include?(action)
unless %w(initiate update comment valid submit receive close).include?(action)
fail 'action is not valid'
end
@ -130,8 +130,12 @@ class Dossier < ActiveRecord::Base
elsif initiated?
validated!
end
when 'close'
when 'receive'
if submitted?
received!
end
when 'close'
if received?
closed!
end
end

View file

@ -66,7 +66,12 @@
= 'Valider le dossier'
-elsif @facade.dossier.submitted?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :receive, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Notifier de la bonne réception'
-elsif @facade.dossier.received?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Traiter le dossier'
= 'Accepter le dossier'

View file

@ -156,6 +156,7 @@ Rails.application.routes.draw do
resources :dossiers do
post 'valid' => 'dossiers#valid'
post 'receive' => 'dossiers#receive'
post 'close' => 'dossiers#close'
post 'invites' => '/invites#create'

View file

@ -119,12 +119,26 @@ describe Backoffice::DossiersController, type: :controller do
end
end
describe 'POST #close' do
describe 'POST #receive' do
before do
dossier.submitted!
sign_in gestionnaire
end
it 'change state to received' do
post :receive, dossier_id: dossier_id
dossier.reload
expect(dossier.state).to eq('received')
end
end
describe 'POST #close' do
before do
dossier.received!
sign_in gestionnaire
end
it 'change state to closed' do
post :close, dossier_id: dossier_id

View file

@ -323,10 +323,10 @@ describe Dossier do
dossier.submitted!
end
context 'when user is connect' do
context 'when user is connected' do
let(:role) { 'user' }
context 'when is post a comment' do
context 'when he posts a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('submitted') }
@ -336,13 +336,45 @@ describe Dossier do
context 'when gestionnaire is connect' do
let(:role) { 'gestionnaire' }
context 'when is post a comment' do
context 'when he posts a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('submitted') }
end
context 'when is closed the dossier' do
context 'when he receive the dossier' do
let(:action) { 'receive' }
it { is_expected.to eq('received') }
end
end
end
context 'when dossier is at state received' do
before do
dossier.received!
end
context 'when user is connected' do
let(:role) { 'user' }
context 'when he posts a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('received') }
end
end
context 'when gestionnaire is connect' do
let(:role) { 'gestionnaire' }
context 'when he posts a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('received') }
end
context 'when he closes the dossier' do
let(:action) { 'close' }
it { is_expected.to eq('closed') }

View file

@ -119,28 +119,13 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
it { expect(rendered).to have_content('Déposé') }
it 'button Traiter le dossier is present' do
it 'button notifier de la bonne réception is present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Traiter le dossier')
expect(rendered).to have_content('Notifier de la bonne réception')
end
it 'button Valider le dossier is not present' do
expect(rendered).not_to have_content('Valider le dossier')
end
end
context 'when dossier have state closed' do
let(:state) { 'closed' }
before do
render
end
it { expect(rendered).to have_content('Accepté') }
it 'button Valider le dossier is not present' do
expect(rendered).not_to have_css('#action_button')
expect(rendered).not_to have_content('Valider le dossier')
expect(rendered).not_to have_content('Accepter le dossier')
end
end
@ -153,9 +138,23 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
it { expect(rendered).to have_content('Reçu') }
it 'button Valider le dossier is not present' do
it 'button accepter le dossier is present' do
expect(rendered).to have_content('Accepter le dossier')
end
end
context 'when dossier have state closed' do
let(:state) { 'closed' }
before do
render
end
it { expect(rendered).to have_content('Accepté') }
it 'button Accepter le dossier is not present' do
expect(rendered).not_to have_css('#action_button')
expect(rendered).not_to have_content('Valider le dossier')
expect(rendered).not_to have_content('Accepter le dossier')
end
end