From cf5398fe99b3a1514eda6509fad25361b7aab837 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 27 Jun 2017 11:23:02 +0200 Subject: [PATCH] Record published_at when publishing a procedure --- app/models/procedure.rb | 2 +- spec/models/procedure_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 38c7200e3..c5a0ce236 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -112,7 +112,7 @@ class Procedure < ActiveRecord::Base end def publish!(path) - self.update_attributes!({published: true, archived: false}) + self.update_attributes!({ published: true, archived: false, published_at: Time.now }) ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur) end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 7f37f0833..88e3fbd16 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -224,10 +224,12 @@ describe Procedure do before do procedure.publish!("example-path") + Timecop.freeze(Time.now) end it { expect(procedure.published).to eq(true) } it { expect(procedure.archived).to eq(false) } + it { expect(procedure.published_at).to eq(Time.now) } it { expect(ProcedurePath.find_by_path("example-path")).to be } it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) } it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) }