Administrator can unarchived a procedure

This commit is contained in:
Xavier J 2015-11-27 17:13:06 +01:00
parent 7c3f322d6e
commit 3eb990a611
5 changed files with 36 additions and 13 deletions

View file

@ -37,7 +37,6 @@ class Admin::ProceduresController < AdminController
end
def update
@procedure = current_administrateur.procedures.find(params[:id])
unless @procedure.update_attributes(create_procedure_params)
@ -50,9 +49,9 @@ class Admin::ProceduresController < AdminController
def archive
@procedure = current_administrateur.procedures.find(params[:procedure_id])
@procedure.update_attributes({archived: true})
@procedure.update_attributes({archived: params[:archive]})
flash.notice = 'Procédure archivée'
flash.notice = 'Procédure éditée'
redirect_to admin_procedures_path
rescue ActiveRecord::RecordNotFound

View file

@ -6,10 +6,13 @@
%li
= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
%li{style:'float:right'}
= form_tag "/admin/procedures/#{@procedure.id}/archive", action: :archive, method: :put, procedure_id: @procedure.id do
= form_tag admin_procedure_archive_path(procedure_id: @procedure.id, archive: !@procedure.archived?), method: :put do
%button#archive.btn.btn-nav.text-info{type: :button}
%i.fa.fa-eraser
Archiver
- if @procedure.archived
= 'Activer'
- else
= 'Archiver'
#confirm
%button#valid.btn.btn-nav.text-success{type: :submit}
%i.fa.fa-check
@ -22,8 +25,8 @@
=@procedure.libelle
#procedure_new.section.section-label
= form_for @procedure, url: {controller: 'admin/procedures', action: :update} do |f|
=render partial: 'informations', locals: {f: f}
=f.submit 'Editer', class: 'btn btn-success', style: 'float:right'
= form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}) do |f|
= render partial: 'informations', locals: {f: f}
= f.submit 'Editer', class: 'btn btn-success', style: 'float:right'
%br
%br

View file

@ -56,7 +56,7 @@ Rails.application.routes.draw do
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
end
put 'archive' => 'procedures#archive'
put 'archive' => 'procedures#archive', as: :archive
resources :types_de_champ, only: [:destroy]
resource :pieces_justificatives, only: [:show, :update]

View file

@ -176,17 +176,15 @@ describe Admin::ProceduresController, type: :controller do
describe 'PUT #archive' do
let(:procedure) { create(:procedure, administrateur: admin) }
context 'when admin is the owner of the procedure' do
before do
put :archive, procedure_id: procedure.id
put :archive, procedure_id: procedure.id, archive: !procedure.archived
procedure.reload
end
it { expect(procedure.archived).to be_truthy }
it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:notice]).to have_content 'Procédure archivée' }
it { expect(flash[:notice]).to have_content 'Procédure éditée' }
end
context 'when admin is not the owner of the procedure' do

View file

@ -0,0 +1,23 @@
require 'spec_helper'
describe 'admin/procedures/show.html.haml', type: :view do
describe 'archive and unarchive button' do
before do
assign(:procedure, procedure)
render
end
context 'when procedure is active' do
let(:procedure) { create(:procedure) }
it { expect(rendered).to have_content('Archiver') }
end
context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: true) }
it { expect(rendered).to have_content('Activer') }
end
end
end