Skip to content

Commit 7499523

Browse files
committed
Do not validate first_published_at against govt dates for historic or political editions
Users trying to edit previously published, historic documents are unable to do so if the `first_published_at` date was (correctly) updated in the past, since the validation prevents them from saving. This caused a minor production incident. This commit (along with the previous one) fixes this by ensuring the `first_published_preceeds_change_notes` validation doesn't run on historic or political editions.
1 parent 133984d commit 7499523

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

app/models/edition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def error_labels
451451
def first_published_preceeds_change_notes
452452
return if first_published_at.blank?
453453
return if other_editions.empty?
454+
return if political? || historic?
454455

455456
change_note_dates = other_editions.pluck(:major_change_published_at).compact.sort
456457

test/unit/app/models/edition_test.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,37 @@ class EditionTest < ActiveSupport::TestCase
724724
assert_equal "First published date must be after the start of the current government (11/11/2009)", edition.errors.full_messages.first
725725
end
726726

727-
test "polictial editions can have their first_published_at date set before the current government " do
727+
test "polictial editions can have their first_published_at date set before the current government" do
728728
create(:current_government)
729729
political_edition = create(:edition, political: true, first_published_at: 10.years.ago)
730730

731731
assert political_edition.valid?
732732
end
733733

734+
test "political editions can have their first_published_at date after the earliest change note" do
735+
edition_with_change_note = create(:edition_with_document, :published, change_note: "changed", major_change_published_at: 2.days.ago)
736+
edition = build(:edition, political: true, document: edition_with_change_note.document, first_published_at: 1.day.ago)
737+
738+
assert edition.valid?
739+
end
740+
741+
test "historical editions can have their first_published_at date set before the current government" do
742+
prev_government = create(:previous_government, start_date: 10.years.ago, end_date: 1.year.ago)
743+
create(:current_government, start_date: 1.year.ago)
744+
political_edition = create(:edition, political: true, first_published_at: 9.years.ago, government_id: prev_government.id)
745+
746+
assert political_edition.valid?
747+
end
748+
749+
test "historical editions can have their first_published_at date set after the earliest change note" do
750+
prev_government = create(:previous_government, start_date: 10.years.ago, end_date: 1.year.ago)
751+
create(:current_government, start_date: 1.year.ago)
752+
historic_edition_with_change_note = create(:edition_with_document, :published, change_note: "changed", major_change_published_at: 9.years.ago)
753+
historic_edition = create(:edition, political: true, first_published_at: 8.years.ago, government_id: prev_government.id, document: historic_edition_with_change_note.document)
754+
755+
assert historic_edition.valid?
756+
end
757+
734758
test "after_change_notes' error message takes priority if multiple validation errors on first_published_at" do
735759
edition_with_change_note = create(:edition_with_document, :published, change_note: "changed", major_change_published_at: 2.days.ago)
736760
edition = build(:edition, document: edition_with_change_note.document, first_published_at: 10.years.from_now)

0 commit comments

Comments
 (0)