Update spec/models/procedure_spec.rb
Co-Authored-By: Pierre de La Morinerie <kemenaran@gmail.com>
This commit is contained in:
parent
517ab25783
commit
67dea1ee50
1 changed files with 45 additions and 24 deletions
|
@ -534,16 +534,18 @@ describe Procedure do
|
||||||
let(:procedure) { create(:procedure, path: 'example-path') }
|
let(:procedure) { create(:procedure, path: 'example-path') }
|
||||||
let(:now) { Time.zone.now.beginning_of_minute }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
|
|
||||||
after { Timecop.return }
|
context 'when publishing a new procedure' do
|
||||||
|
|
||||||
context "without canonical procedure" do
|
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(now)
|
Timecop.freeze(now) do
|
||||||
procedure.publish!
|
procedure.publish!
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it do
|
it 'no reference to the canonical procedure on the published procedure' do
|
||||||
expect(procedure.canonical_procedure).to be_nil
|
expect(procedure.canonical_procedure).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes the procedure state to published' do
|
||||||
expect(procedure.closed_at).to be_nil
|
expect(procedure.closed_at).to be_nil
|
||||||
expect(procedure.published_at).to eq(now)
|
expect(procedure.published_at).to eq(now)
|
||||||
expect(Procedure.find_by(path: "example-path")).to eq(procedure)
|
expect(Procedure.find_by(path: "example-path")).to eq(procedure)
|
||||||
|
@ -551,16 +553,20 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with canonical procedure" do
|
context 'when publishing over a previous canonical procedure' do
|
||||||
let(:canonical_procedure) { create(:procedure, :published) }
|
let(:canonical_procedure) { create(:procedure, :published) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(now)
|
Timecop.freeze(now) do
|
||||||
procedure.publish!(canonical_procedure)
|
procedure.publish!(canonical_procedure)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it do
|
it 'references the canonical procedure on the published procedure' do
|
||||||
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes the procedure state to published' do
|
||||||
expect(procedure.closed_at).to be_nil
|
expect(procedure.closed_at).to be_nil
|
||||||
expect(procedure.published_at).to eq(now)
|
expect(procedure.published_at).to eq(now)
|
||||||
end
|
end
|
||||||
|
@ -574,38 +580,53 @@ describe Procedure do
|
||||||
let(:procedure) { create(:procedure, administrateurs: [administrateur]) }
|
let(:procedure) { create(:procedure, administrateurs: [administrateur]) }
|
||||||
let(:now) { Time.zone.now.beginning_of_minute }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
|
|
||||||
context "without canonical procedure" do
|
context 'when publishing over a previous canonical procedure' do
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(now)
|
|
||||||
procedure.path = canonical_procedure.path
|
procedure.path = canonical_procedure.path
|
||||||
|
Timecop.freeze(now) do
|
||||||
procedure.publish_or_reopen!(administrateur)
|
procedure.publish_or_reopen!(administrateur)
|
||||||
|
end
|
||||||
canonical_procedure.reload
|
canonical_procedure.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it 'references the canonical procedure on the published procedure' do
|
||||||
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes the procedure state to published' do
|
||||||
expect(procedure.closed_at).to be_nil
|
expect(procedure.closed_at).to be_nil
|
||||||
expect(procedure.published_at).to eq(now)
|
expect(procedure.published_at).to eq(now)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unpublishes the canonical procedure' do
|
||||||
expect(canonical_procedure.unpublished_at).to eq(now)
|
expect(canonical_procedure.unpublished_at).to eq(now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with canonical procedure" do
|
context 'when publishing over a previous procedure with canonical procedure' do
|
||||||
let(:canonical_procedure) { create(:procedure, :closed) }
|
let(:canonical_procedure) { create(:procedure, :closed) }
|
||||||
let(:parent_procedure) { create(:procedure, :published, administrateurs: [administrateur]) }
|
let(:parent_procedure) { create(:procedure, :published, administrateurs: [administrateur]) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
parent_procedure.update!(path: canonical_procedure.path, canonical_procedure: canonical_procedure)
|
parent_procedure.update!(path: canonical_procedure.path, canonical_procedure: canonical_procedure)
|
||||||
Timecop.freeze(now)
|
|
||||||
procedure.path = canonical_procedure.path
|
procedure.path = canonical_procedure.path
|
||||||
|
Timecop.freeze(now) do
|
||||||
procedure.publish_or_reopen!(administrateur)
|
procedure.publish_or_reopen!(administrateur)
|
||||||
|
end
|
||||||
parent_procedure.reload
|
parent_procedure.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it 'references the canonical procedure on the published procedure' do
|
||||||
|
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes the procedure state to published' do
|
||||||
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
expect(procedure.canonical_procedure).to eq(canonical_procedure)
|
||||||
expect(procedure.closed_at).to be_nil
|
expect(procedure.closed_at).to be_nil
|
||||||
expect(procedure.published_at).to eq(now)
|
expect(procedure.published_at).to eq(now)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'unpublishes parent procedure' do
|
||||||
expect(parent_procedure.unpublished_at).to eq(now)
|
expect(parent_procedure.unpublished_at).to eq(now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -616,10 +637,10 @@ describe Procedure do
|
||||||
let(:now) { Time.zone.now.beginning_of_minute }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(now)
|
Timecop.freeze(now) do
|
||||||
procedure.unpublish!
|
procedure.unpublish!
|
||||||
end
|
end
|
||||||
after { Timecop.return }
|
end
|
||||||
|
|
||||||
it {
|
it {
|
||||||
expect(procedure.closed_at).to eq(nil)
|
expect(procedure.closed_at).to eq(nil)
|
||||||
|
@ -692,11 +713,11 @@ describe Procedure do
|
||||||
let(:procedure) { create(:procedure, :published) }
|
let(:procedure) { create(:procedure, :published) }
|
||||||
let(:now) { Time.zone.now.beginning_of_minute }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(now)
|
Timecop.freeze(now) do
|
||||||
procedure.close!
|
procedure.close!
|
||||||
|
end
|
||||||
procedure.reload
|
procedure.reload
|
||||||
end
|
end
|
||||||
after { Timecop.return }
|
|
||||||
|
|
||||||
it { expect(procedure.close?).to be_truthy }
|
it { expect(procedure.close?).to be_truthy }
|
||||||
it { expect(procedure.closed_at).to eq(now) }
|
it { expect(procedure.closed_at).to eq(now) }
|
||||||
|
|
Loading…
Reference in a new issue