Validate process dates depending on enabled phases

When configuring phases in a process, we were validating the start date
or the end date is present, the other date is present too.

However, in other parts of the application we were checking whether a
phase is enabled and then assumed its dates were present if the phase
was enabled. However, we weren't validating this behavior, so it was
possible to enable a phase and leaving its dates blank, causing the
application to crash.

So, as suggested by Alberto, we're changing the validation rule so
phase dates are mandatory when a phase is enabled.

With this rule, the old validation rules are not necessary. I've
considered leaving them in order to avoid database inconsistencies.
However, I realized records having a disabled phase with its start and
end dates have always been valid. This means applications checking for
the presence of these dates instead of checking whether the phase is
enabled have never worked properly.

We don't have to change the logic anywhere else because as mentioned we
were already checking phases are enabled before using their dates.
This commit is contained in:
Javi Martín
2021-05-20 11:43:39 +02:00
parent d5b3b25e1e
commit f55d2ab891
3 changed files with 124 additions and 34 deletions

View File

@@ -289,6 +289,24 @@ describe "Admin collaborative legislation", :admin do
expect(page).to have_field "draft_publication_date", disabled: true
end
scenario "Enabling comments phase with blank dates" do
visit edit_admin_legislation_process_path(process)
within_fieldset "Comments phase" do
check "Enabled"
fill_in "Start", with: ""
fill_in "End", with: ""
end
click_button "Save changes"
expect(page).to have_content "errors prevented this process from being saved"
within_fieldset "Comments phase" do
expect(page).to have_content "can't be blank"
end
end
scenario "Change proposal categories" do
visit edit_admin_legislation_process_path(process)
within(".admin-content") { click_link "Proposals" }