Add Procedure#brouillon?

This commit is contained in:
gregoirenovel 2017-07-13 15:21:52 +02:00
parent 25800305ad
commit 36bee67085
3 changed files with 15 additions and 1 deletions

View file

@ -120,6 +120,10 @@ class Procedure < ActiveRecord::Base
return procedure if procedure.save
end
def brouillon?
published_at.nil?
end
def publish!(path)
self.update_attributes!({ published_at: Time.now, archived_at: nil })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)

View file

@ -1,6 +1,6 @@
.row.white-back
#procedure_show
- unless @facade.procedure.published?
- if @facade.procedure.brouillon?
- if @facade.procedure.gestionnaires.size == 0
%a.action_button.btn.btn-success#publish-procedure{ style: 'float: right; margin-top: 10px;', disabled: 'disabled', 'data-toggle' => :tooltip, title: 'Vous ne pouvez pas publier une procédure sans qu\'aucun accompagnateur ne soit affecté à celle-ci.' }
%i.fa.fa-eraser

View file

@ -243,6 +243,16 @@ describe Procedure do
end
end
describe "#brouillon?" 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.brouillon?).to be_truthy }
it { expect(procedure_publiee.brouillon?).to be_falsey }
it { expect(procedure_archivee.brouillon?).to be_falsey }
end
describe "#publiee?" do
let(:procedure_brouillon) { Procedure.new() }
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }