Handle "réactiver" feature with permanent procedure url

This commit is contained in:
Guillaume Lazzara 2016-06-24 16:57:35 +02:00
parent e5002dbb11
commit 92a5100a09
4 changed files with 23 additions and 17 deletions

View file

@ -73,7 +73,7 @@ class Procedure < ActiveRecord::Base
end end
def publish(path) def publish(path)
self.update_attributes!({ published: true }) self.update_attributes!({ published: true, archived: false })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur) ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
end end

View file

@ -6,12 +6,16 @@
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"} %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} × %span{"aria-hidden" => "true"} ×
%h4#myModalLabel.modal-title %h4#myModalLabel.modal-title
Publier la procédure =@procedure.archived?? 'Réactiver' : 'Publier'
la procédure
%span#publishModal_title %span#publishModal_title
.modal-body .modal-body
Vous vous apprêtez à publier votre procédure au public. Vous vous apprêtez à
%b =@procedure.archived?? 'republier' : 'publier'
Elle ne pourra plus être modifiée à l'issue de cette publication. votre procédure au public.
- unless @procedure.archived?
%b
Elle ne pourra plus être modifiée à l'issue de cette publication.
%br %br
Afin de faciliter l'accès à la procédure, vous êtes invité à personnaliser l'adresse d'accès si vous le souhaitez. Afin de faciliter l'accès à la procédure, vous êtes invité à personnaliser l'adresse d'accès si vous le souhaitez.
%br %br
@ -39,7 +43,7 @@
Ce lien n'est pas valide. Seuls les caractères a-z, 0-9 et '_' sont autorisés. Ce lien n'est pas valide. Seuls les caractères a-z, 0-9 et '_' sont autorisés.
.modal-footer .modal-footer
= submit_tag 'Annuler', class: %w(btn btn btn-default), id: 'cancel', data: { dismiss: 'modal' } = submit_tag 'Annuler', class: %w(btn btn btn-default), id: 'cancel', data: { dismiss: 'modal' }
= submit_tag 'Publier', class: %w(btn btn btn-success), = submit_tag "#{@procedure.archived?? 'Réactiver' : 'Publier'}", class: %w(btn btn btn-success),
id: 'publish', id: 'publish',
data: { disable_with: 'Publication en cours', submit: true}, data: { disable_with: 'Publication en cours', submit: true},
disabled: :disabled disabled: :disabled

View file

@ -8,14 +8,17 @@
%br %br
=render partial: '/admin/procedures/modal_publish' =render partial: '/admin/procedures/modal_publish'
-if @facade.procedure.archived?
%a.btn.btn-small.btn-default.text-info{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
%i.fa.fa-eraser
Réactiver
%br
=render partial: '/admin/procedures/modal_publish'
-else -else
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do = form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
%button#archive.btn.btn-small.btn-default.text-info{type: :button} %button#archive.btn.btn-small.btn-default.text-info{type: :button}
%i.fa.fa-eraser %i.fa.fa-eraser
- if @facade.procedure.archived = 'Archiver'
= 'Réactiver'
- else
= 'Archiver'
#confirm #confirm
%button#valid.btn.btn-small.btn-success{type: :submit} %button#valid.btn.btn-small.btn-success{type: :submit}
%i.fa.fa-check %i.fa.fa-check

View file

@ -355,26 +355,25 @@ describe Admin::ProceduresController, type: :controller do
context 'when admin is the owner of the procedure' do context 'when admin is the owner of the procedure' do
before do before do
put :archive, procedure_id: procedure.id, archive: archive put :archive, procedure_id: procedure.id
procedure.reload procedure.reload
end end
context 'when owner want archive procedure' do context 'when owner want archive procedure' do
let(:archive) { true }
it { expect(procedure.archived).to be_truthy } it { expect(procedure.archived).to be_truthy }
it { expect(response).to redirect_to :admin_procedures } 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 archivée' }
end end
context 'when owner want reactive procedure' do context 'when owner want reactive procedure' do
before do
let(:archive) { false } put :publish, procedure_id: procedure.id, procedure_path: 'fake_path'
procedure.reload
end
it { expect(procedure.archived).to be_falsey } it { expect(procedure.archived).to be_falsey }
it { expect(response).to redirect_to :admin_procedures } it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:notice]).to have_content 'Procédure éditée' } it { expect(flash[:notice]).to have_content 'Procédure publiée' }
end end
end end