Add Backoffice::DossiersController#process_dossier and use it

This commit is contained in:
gregoirenovel 2017-06-01 21:23:47 +02:00
parent 1bff7d1914
commit 33944e343a
5 changed files with 59 additions and 13 deletions

View file

@ -103,6 +103,17 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
redirect_to backoffice_dossier_path(id: dossier.id)
end
def process_dossier
case params[:process_action]
when "refuse"
refuse
when "without_continuation"
without_continuation
when "close"
close
end
end
def refuse
create_dossier_facade params[:dossier_id]

View file

@ -8,16 +8,19 @@
= link_to 'Passer en instruction', backoffice_dossier_receive_path(@facade.dossier), method: :post, class: 'btn btn-danger btn-block', data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" }
- elsif @facade.dossier.received?
%ul.list-inline
%li
= link_to url_for({ controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id }), class: 'btn btn-success', method: :post, title: 'Accepter', data: { toggle: :tooltip, confirm: "Accepter ce dossier ?" } do
%i.fa.fa-check
%li
= link_to url_for({ controller: 'backoffice/dossiers', action: :without_continuation, dossier_id: @facade.dossier.id }), class: 'btn btn-warning', method: :post, title: 'Classer sans suite', data: { toggle: :tooltip, confirm: "Classer sans suite ce dossier ?" } do
%i.fa.fa-circle-o
%li
= link_to url_for({ controller: 'backoffice/dossiers', action: :refuse, dossier_id: @facade.dossier.id }), class: 'btn btn-danger', method: :post, title: 'Refuser', data: { toggle: :tooltip, confirm: "Refuser ce dossier ?" } do
%i.fa.fa-times
= form_tag(backoffice_dossier_process_dossier_url(@facade.dossier.id), method: :post) do
%ul.list-inline
%li
= button_tag name: :process_action, value: "close", class: 'btn btn-success', title: 'Accepter', data: { toggle: :tooltip, confirm: "Accepter ce dossier ?" } do
%i.fa.fa-check
%li
= button_tag name: :process_action, value: "without_continuation", class: 'btn btn-warning', title: 'Classer sans suite', data: { toggle: :tooltip, confirm: "Classer sans suite ce dossier ?" } do
%i.fa.fa-circle-o
%li
= button_tag name: :process_action, value: "refuse", class: 'btn btn-danger', title: 'Refuser', data: { toggle: :tooltip, confirm: "Refuser ce dossier ?" } do
%i.fa.fa-times
= link_to 'Reouvrir', backoffice_dossier_reopen_path(@facade.dossier), method: :post, class: 'btn btn-default btn-block', data: { confirm: "Confirmer vous la réouverture de ce dossier ?" }

View file

@ -172,6 +172,7 @@ Rails.application.routes.draw do
resources :dossiers do
post 'receive' => 'dossiers#receive'
post 'process_dossier' => 'dossiers#process_dossier'
post 'refuse' => 'dossiers#refuse'
post 'without_continuation' => 'dossiers#without_continuation'
post 'close' => 'dossiers#close'

View file

@ -250,6 +250,37 @@ describe Backoffice::DossiersController, type: :controller do
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
end
describe 'POST #process_dossier' do
before do
dossier.received!
sign_in gestionnaire
end
context "with refuse" do
it "calls the refuse method" do
expect(controller).to receive(:refuse)
post :process_dossier, params: { dossier_id: dossier_id, process_action: "refuse" }
end
end
context "with without_continuation" do
it "calls the without_continuation method" do
expect(controller).to receive(:without_continuation)
post :process_dossier, params: { dossier_id: dossier_id, process_action: "without_continuation" }
end
end
context "with close" do
it "calls the close method" do
expect(controller).to receive(:close)
post :process_dossier, params: { dossier_id: dossier_id, process_action: "close" }
end
end
end
describe 'POST #refuse' do
before do
dossier.received!

View file

@ -74,9 +74,9 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm
it { expect(rendered).to have_content('En instruction') }
it 'button accepter / refuser / classer sans suite are present' do
expect(rendered).to have_css('a[title="Accepter"]')
expect(rendered).to have_css('a[title="Classer sans suite"]')
expect(rendered).to have_css('a[title="Refuser"]')
expect(rendered).to have_css('button[title="Accepter"]')
expect(rendered).to have_css('button[title="Classer sans suite"]')
expect(rendered).to have_css('button[title="Refuser"]')
end
end