Add Procedure#publiee?

This commit is contained in:
gregoirenovel 2017-07-13 15:14:28 +02:00
parent cfec05506a
commit 9a7d5d1833
6 changed files with 23 additions and 11 deletions

View file

@ -53,7 +53,7 @@ class Admin::ProceduresController < AdminController
def destroy
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

View file

@ -129,6 +129,10 @@ class Procedure < ActiveRecord::Base
published_at.present?
end
def publiee?
published_at.present? && archived_at.nil?
end
def archive
self.update_attributes!(archived_at: Time.now)
end

View file

@ -20,7 +20,7 @@
= procedure.created_at_fr
%td
= 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')
= smart_listing.paginate

View file

@ -25,7 +25,7 @@
= 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
%button#archive.btn.btn-small.btn-default.text-info{ type: :button }
%i.fa.fa-eraser
@ -130,7 +130,7 @@
- else
= 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
.alert.alert-danger
%p

View file

@ -297,7 +297,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'new_path' }
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(response.status).to eq 200
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 }
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(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée'
end
it 'archive previous procedure' do
expect(procedure2.published?).to be_truthy
expect(procedure2.archivee?).to be_truthy
expect(procedure2.path).to be_nil
end
@ -325,13 +324,13 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { procedure3.path }
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(response.status).to eq 200
end
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.path).to match(/fake_path/)
end
@ -341,7 +340,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'Invalid Procedure Path' }
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(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Lien de la procédure invalide'

View file

@ -243,6 +243,16 @@ describe Procedure do
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
let(:procedure_brouillon) { Procedure.new() }
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
@ -263,7 +273,6 @@ describe Procedure do
procedure.reload
end
it { expect(procedure.published?).to be_truthy }
it { expect(procedure.archivee?).to be_truthy }
it { expect(procedure.archived_at).to eq(now) }