Adds draft phase functionality in legislation processes

This commit is contained in:
João Lutz
2018-10-19 15:27:18 -03:00
parent fb4b12c2d4
commit 34b58a5208
15 changed files with 209 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ require 'rails_helper'
RSpec.describe Legislation::Process::Phase, type: :model do
let(:process) { create(:legislation_process) }
let(:process_in_draft_phase) { create(:legislation_process, :in_draft_phase) }
describe "#enabled?" do
it "checks debate phase" do
@@ -11,6 +12,15 @@ RSpec.describe Legislation::Process::Phase, type: :model do
expect(process.debate_phase.enabled?).to be false
end
it "checks draft phase" do
expect(process.draft_phase.enabled?).to be false
expect(process_in_draft_phase.draft_phase.enabled?).to be true
process.update_attributes(draft_phase_enabled: false)
expect(process.draft_phase.enabled?).to be false
end
it "checks allegations phase" do
expect(process.allegations_phase.enabled?).to be true
@@ -38,6 +48,24 @@ RSpec.describe Legislation::Process::Phase, type: :model do
expect(process.debate_phase.started?).to be true
end
it "checks draft phase" do
# future
process.update_attributes(draft_start_date: Date.current + 2.days, draft_end_date: Date.current + 3.days, draft_phase_enabled: true)
expect(process.draft_phase.started?).to be false
# started
process.update_attributes(draft_start_date: Date.current - 2.days, draft_end_date: Date.current + 1.day, draft_phase_enabled: true)
expect(process.draft_phase.started?).to be true
# starts today
process.update_attributes(draft_start_date: Date.current, draft_end_date: Date.current + 1.day, draft_phase_enabled: true)
expect(process.draft_phase.started?).to be true
# past
process.update_attributes(draft_start_date: Date.current - 2.days, draft_end_date: Date.current - 1.day, draft_phase_enabled: true)
expect(process.draft_phase.started?).to be true
end
it "checks allegations phase" do
# future
process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days)
@@ -76,6 +104,24 @@ RSpec.describe Legislation::Process::Phase, type: :model do
expect(process.debate_phase.open?).to be false
end
it "checks draft phase" do
# future
process.update_attributes(draft_start_date: Date.current + 2.days, draft_end_date: Date.current + 3.days, draft_phase_enabled: true)
expect(process.draft_phase.open?).to be false
# started
process.update_attributes(draft_start_date: Date.current - 2.days, draft_end_date: Date.current + 1.day, draft_phase_enabled: true)
expect(process.draft_phase.open?).to be true
# starts today
process.update_attributes(draft_start_date: Date.current, draft_end_date: Date.current + 1.day, draft_phase_enabled: true)
expect(process.draft_phase.open?).to be true
# past
process.update_attributes(draft_start_date: Date.current - 2.days, draft_end_date: Date.current - 1.day, draft_phase_enabled: true)
expect(process.draft_phase.open?).to be false
end
it "checks allegations phase" do
# future