diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index f3ba6c3e3..623c7e002 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -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 diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index c41af3283..1b13f20cc 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 16ddc5f82..5cb0c04a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 5a1f29985..114d989c0 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -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 diff --git a/spec/views/admin/procedures/show.html.haml_spec.rb b/spec/views/admin/procedures/show.html.haml_spec.rb new file mode 100644 index 000000000..295b244bb --- /dev/null +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -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 \ No newline at end of file