Add Procedure#publiee?
This commit is contained in:
parent
cfec05506a
commit
9a7d5d1833
6 changed files with 23 additions and 11 deletions
|
@ -53,7 +53,7 @@ class Admin::ProceduresController < AdminController
|
||||||
def destroy
|
def destroy
|
||||||
procedure = Procedure.find(params[:id])
|
procedure = Procedure.find(params[:id])
|
||||||
|
|
||||||
return render json: {}, status: 401 if procedure.published? || procedure.archivee?
|
return render json: {}, status: 401 if procedure.publiee? || procedure.archivee?
|
||||||
|
|
||||||
procedure.destroy
|
procedure.destroy
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,10 @@ class Procedure < ActiveRecord::Base
|
||||||
published_at.present?
|
published_at.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publiee?
|
||||||
|
published_at.present? && archived_at.nil?
|
||||||
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
self.update_attributes!(archived_at: Time.now)
|
self.update_attributes!(archived_at: Time.now)
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
= procedure.created_at_fr
|
= procedure.created_at_fr
|
||||||
%td
|
%td
|
||||||
= link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn')
|
= link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn')
|
||||||
- unless procedure.published? || procedure.archivee?
|
- unless procedure.publiee? || procedure.archivee?
|
||||||
= link_to('X', url_for(controller: 'admin/procedures', action: :destroy, id: procedure.id), 'data-method' => :delete, class: 'btn-sm btn-danger')
|
= link_to('X', url_for(controller: 'admin/procedures', action: :destroy, id: procedure.id), 'data-method' => :delete, class: 'btn-sm btn-danger')
|
||||||
|
|
||||||
= smart_listing.paginate
|
= smart_listing.paginate
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
= render partial: '/admin/procedures/modal_publish'
|
= render partial: '/admin/procedures/modal_publish'
|
||||||
|
|
||||||
- elsif @facade.procedure.published?
|
- elsif @facade.procedure.publiee?
|
||||||
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archivee?), method: :put, style: 'float: right; margin-top: 10px;' do
|
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archivee?), 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
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
- else
|
- else
|
||||||
= pie_chart @facade.dossiers_for_pie_highchart
|
= pie_chart @facade.dossiers_for_pie_highchart
|
||||||
|
|
||||||
- if @facade.procedure.published? || @facade.procedure.archivee?
|
- if @facade.procedure.publiee? || @facade.procedure.archivee?
|
||||||
%h3 Supprimer la procédure
|
%h3 Supprimer la procédure
|
||||||
.alert.alert-danger
|
.alert.alert-danger
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -297,7 +297,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:procedure_path) { 'new_path' }
|
let(:procedure_path) { 'new_path' }
|
||||||
|
|
||||||
it 'publish the given procedure' do
|
it 'publish the given procedure' do
|
||||||
expect(procedure.published?).to be_truthy
|
expect(procedure.publiee?).to be_truthy
|
||||||
expect(procedure.path).to eq(procedure_path)
|
expect(procedure.path).to eq(procedure_path)
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
expect(flash[:notice]).to have_content 'Procédure publiée'
|
expect(flash[:notice]).to have_content 'Procédure publiée'
|
||||||
|
@ -308,14 +308,13 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:procedure_path) { procedure2.path }
|
let(:procedure_path) { procedure2.path }
|
||||||
|
|
||||||
it 'publish the given procedure' do
|
it 'publish the given procedure' do
|
||||||
expect(procedure.published?).to be_truthy
|
expect(procedure.publiee?).to be_truthy
|
||||||
expect(procedure.path).to eq(procedure_path)
|
expect(procedure.path).to eq(procedure_path)
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
expect(flash[:notice]).to have_content 'Procédure publiée'
|
expect(flash[:notice]).to have_content 'Procédure publiée'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'archive previous procedure' do
|
it 'archive previous procedure' do
|
||||||
expect(procedure2.published?).to be_truthy
|
|
||||||
expect(procedure2.archivee?).to be_truthy
|
expect(procedure2.archivee?).to be_truthy
|
||||||
expect(procedure2.path).to be_nil
|
expect(procedure2.path).to be_nil
|
||||||
end
|
end
|
||||||
|
@ -325,13 +324,13 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:procedure_path) { procedure3.path }
|
let(:procedure_path) { procedure3.path }
|
||||||
|
|
||||||
it 'does not publish the given procedure' do
|
it 'does not publish the given procedure' do
|
||||||
expect(procedure.published?).to be_falsey
|
expect(procedure.publiee?).to be_falsey
|
||||||
expect(procedure.path).to be_nil
|
expect(procedure.path).to be_nil
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'previous procedure remains published' do
|
it 'previous procedure remains published' do
|
||||||
expect(procedure2.published?).to be_truthy
|
expect(procedure2.publiee?).to be_truthy
|
||||||
expect(procedure2.archivee?).to be_falsey
|
expect(procedure2.archivee?).to be_falsey
|
||||||
expect(procedure2.path).to match(/fake_path/)
|
expect(procedure2.path).to match(/fake_path/)
|
||||||
end
|
end
|
||||||
|
@ -341,7 +340,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let(:procedure_path) { 'Invalid Procedure Path' }
|
let(:procedure_path) { 'Invalid Procedure Path' }
|
||||||
|
|
||||||
it 'does not publish the given procedure' do
|
it 'does not publish the given procedure' do
|
||||||
expect(procedure.published?).to be_falsey
|
expect(procedure.publiee?).to be_falsey
|
||||||
expect(procedure.path).to be_nil
|
expect(procedure.path).to be_nil
|
||||||
expect(response).to redirect_to :admin_procedures
|
expect(response).to redirect_to :admin_procedures
|
||||||
expect(flash[:alert]).to have_content 'Lien de la procédure invalide'
|
expect(flash[:alert]).to have_content 'Lien de la procédure invalide'
|
||||||
|
|
|
@ -243,6 +243,16 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#publiee?" do
|
||||||
|
let(:procedure_brouillon) { Procedure.new() }
|
||||||
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||||
|
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
||||||
|
|
||||||
|
it { expect(procedure_brouillon.publiee?).to be_falsey }
|
||||||
|
it { expect(procedure_publiee.publiee?).to be_truthy }
|
||||||
|
it { expect(procedure_archivee.publiee?).to be_falsey }
|
||||||
|
end
|
||||||
|
|
||||||
describe "#archivee?" do
|
describe "#archivee?" do
|
||||||
let(:procedure_brouillon) { Procedure.new() }
|
let(:procedure_brouillon) { Procedure.new() }
|
||||||
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||||
|
@ -263,7 +273,6 @@ describe Procedure do
|
||||||
procedure.reload
|
procedure.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(procedure.published?).to be_truthy }
|
|
||||||
it { expect(procedure.archivee?).to be_truthy }
|
it { expect(procedure.archivee?).to be_truthy }
|
||||||
it { expect(procedure.archived_at).to eq(now) }
|
it { expect(procedure.archived_at).to eq(now) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue