Unarchive button & tests

This commit is contained in:
Mathieu Magnin 2017-02-28 14:33:05 +01:00
parent ef1d46d30e
commit fa884f3ed0
5 changed files with 45 additions and 8 deletions

View file

@ -162,7 +162,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
end
def archive
facade = create_dossier_facade params[:dossier_id]
facade = create_dossier_facade params[:id]
unless facade.dossier.archived
facade.dossier.update(archived: true)
flash.notice = 'Dossier archivé'
@ -170,6 +170,15 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
redirect_to backoffice_dossiers_path
end
def unarchive
@dossier = Dossier.find(params[:id])
if @dossier.archived
@dossier.update(archived: false)
flash.notice = 'Dossier désarchivé'
end
redirect_to backoffice_dossier_path(@dossier)
end
private
def create_dossier_facade dossier_id

View file

@ -23,12 +23,14 @@
%button.action.refuse-dossier
%i.fa.fa-times
%hr
- if @facade.dossier.archived?
%hr
%p
Archivé
%p
Archivé
= link_to 'Désarchiver', unarchive_backoffice_dossier_path(@facade.dossier), method: :post, class: 'btn btn-default btn-block'
- else
= link_to 'Archiver', backoffice_dossier_archive_path(@facade.dossier), method: :post, class: 'btn btn-default btn-block'
= link_to 'Archiver', archive_backoffice_dossier_path(@facade.dossier), method: :post, class: 'btn btn-default btn-block'

View file

@ -164,7 +164,10 @@ Rails.application.routes.draw do
post 'refuse' => 'dossiers#refuse'
post 'without_continuation' => 'dossiers#without_continuation'
post 'close' => 'dossiers#close'
post 'archive' => 'dossiers#archive'
member do
post 'archive'
post 'unarchive'
end
put 'follow' => 'dossiers#follow'
resources :commentaires, only: [:index]

View file

@ -383,7 +383,7 @@ describe Backoffice::DossiersController, type: :controller do
sign_in gestionnaire
end
subject { post :archive, params: {dossier_id: dossier_id} }
subject { post :archive, params: {id: dossier_id} }
it 'change state to archived' do
subject

View file

@ -2,8 +2,9 @@ require 'spec_helper'
describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml', type: :view do
let!(:dossier) { create(:dossier, :with_entreprise, state: state) }
let!(:dossier) { create(:dossier, :with_entreprise, state: state, archived: archived) }
let(:state) { 'draft' }
let(:archived) { false }
let(:gestionnaire) { create(:gestionnaire) }
before do
@ -165,6 +166,28 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm
expect(rendered).not_to have_css('form[data-toggle="tooltip"][title="Refuser"]')
end
end
context 'when dossier is not archived' do
let(:archived) { false }
before do
render
end
it { expect(rendered).to have_link('Archiver') }
end
context 'when dossier is archived' do
let(:archived) { true }
before do
render
end
it { expect(rendered).to have_content('Archivé') }
it { expect(rendered).to have_link('Désarchiver') }
end
end
end