Skip to content

Commit f66b8bf

Browse files
authored
Merge pull request #11434 from alphagov/revert-11429-first-publishing-date
Revert "First publishing date [WHIT-3076]"
2 parents 6e75a13 + 2490cf5 commit f66b8bf

8 files changed

Lines changed: 8 additions & 76 deletions

File tree

app/models/edition.rb

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ class Edition < ApplicationRecord
6868
validates :summary, presence: true, if: :summary_required?, length: { maximum: 65_535 }
6969
validates :previously_published, inclusion: { in: [true, false], message: "You must specify whether the document has been published before" }
7070
validates :first_published_at, presence: true, if: -> { previously_published || published_major_version }
71-
validates :first_published_at, inclusion: { in: proc { Date.parse("1900-01-01")..Time.zone.now } }, if: -> { draft? && other_editions.empty? }, allow_blank: true
71+
validates :first_published_at, inclusion: { in: proc { Date.parse("1900-01-01")..Time.zone.now } }, if: :draft?, allow_blank: true
7272
validates :scheduled_publication, inclusion: { in: proc { Time.zone.now.. }, message: "must be in the future" }, if: :draft?, allow_blank: true
7373
validates :political, inclusion: { in: [true, false] }
7474
validates :image_display_option, inclusion: { in: ["no_image", "organisation_image", "custom_image", nil] }
7575

76-
validate :first_published_preceeds_change_notes, if: :draft?
77-
validate :first_published_within_current_govt, if: :draft?
78-
7976
UNMODIFIABLE_STATES = %w[scheduled published superseded deleted unpublished].freeze
8077
FROZEN_STATES = %w[superseded deleted].freeze
8178
PRE_PUBLICATION_STATES = %w[draft submitted rejected scheduled].freeze
@@ -239,8 +236,6 @@ def body_without_markup
239236
end
240237

241238
def other_editions
242-
return [] if document.nil?
243-
244239
if persisted?
245240
document.editions.where(self.class.arel_table[:id].not_eq(id))
246241
else
@@ -450,29 +445,6 @@ def error_labels
450445
{}
451446
end
452447

453-
def first_published_preceeds_change_notes
454-
return if first_published_at.blank?
455-
return if other_editions.empty?
456-
457-
change_note_dates = other_editions.pluck(:major_change_published_at).compact.sort
458-
459-
return if change_note_dates.empty?
460-
461-
if first_published_at > change_note_dates.first
462-
errors.add(:first_published_at, :after_change_notes, latest: change_note_dates.first.strftime("%d/%m/%Y %H:%M"))
463-
end
464-
end
465-
466-
def first_published_within_current_govt
467-
return if first_published_at.blank?
468-
return if Government.current.blank?
469-
return if political? || historic?
470-
471-
if first_published_at.to_date < Government.current.start_date
472-
errors.add(:first_published_at, :before_current_govt, earliest: Government.current.start_date.strftime("%d/%m/%Y"))
473-
end
474-
end
475-
476448
private
477449

478450
def date_for_government

config/locales/en/errors.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ en:
2323
invalid_date: First published date is not in the correct format
2424
blank: Enter a first published date
2525
inclusion: First published date must be between 1/1/1900 and the present
26-
after_change_notes: "First published date must be before the first change note (%{latest})"
27-
before_current_govt: "First published date must be after the start of the current government (%{earliest})"
2826
html_attachments:
2927
missing_contact_reference: "- \"%{html_attachment_title}\" - embedded Contact (ID %{contact_id}) doesn't exist"
3028
unpublishing:

features/support/document_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def fill_in_worldwide_organisation_fields(world_location: "United Kingdom")
115115
fill_in "Logo formatted name", with: "Logo\r\nformatted\r\nname\r\n"
116116
end
117117

118-
def fill_in_publication_fields(first_published: Time.zone.now, publication_type: "Research and analysis")
118+
def fill_in_publication_fields(first_published: "2010-01-01", publication_type: "Research and analysis")
119119
checkbox_label = "This document has previously been published on another website"
120120
check checkbox_label
121121
within_conditional_reveal checkbox_label do

test/unit/app/models/call_for_evidence_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class CallForEvidenceTest < ActiveSupport::TestCase
328328
test "#government returns the government active on the first_public_at date" do
329329
create(:current_government)
330330
previous_government = create(:previous_government)
331-
call_for_evidence = build(:call_for_evidence, first_published_at: 4.years.ago)
331+
call_for_evidence = create(:call_for_evidence, first_published_at: 4.years.ago)
332332

333333
assert_equal previous_government, call_for_evidence.government
334334
end

test/unit/app/models/consultation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class ConsultationTest < ActiveSupport::TestCase
368368
test "#government returns the government active on the first_public_at date" do
369369
create(:current_government)
370370
previous_government = create(:previous_government)
371-
consultation = build(:consultation, first_published_at: 4.years.ago)
371+
consultation = create(:consultation, first_published_at: 4.years.ago)
372372

373373
assert_equal previous_government, consultation.government
374374
end

test/unit/app/models/edition_test.rb

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -678,38 +678,6 @@ class EditionTest < ActiveSupport::TestCase
678678
assert_equal "First published date must be between 1/1/1900 and the present", edition.errors.full_messages.first
679679
end
680680

681-
test "first_published_at cannot be after the date of the first change note" do
682-
edition_with_change_note = create(:edition_with_document, :published, change_note: "changed", major_change_published_at: 2.days.ago)
683-
edition = build(:edition, document: edition_with_change_note.document, first_published_at: 1.day.ago)
684-
685-
assert edition.invalid?
686-
assert_equal "First published date must be before the first change note (09/11/2011 11:11)", edition.errors.full_messages.first
687-
end
688-
689-
test "first_published_at cannot be before the start of the current government" do
690-
create(:current_government)
691-
edition = build(:edition, first_published_at: 10.years.ago)
692-
693-
assert edition.invalid?
694-
assert_equal "First published date must be after the start of the current government (11/11/2009)", edition.errors.full_messages.first
695-
end
696-
697-
test "polictial editions can have their first_published_at date set before the current government " do
698-
create(:current_government)
699-
political_edition = create(:edition, political: true, first_published_at: 10.years.ago)
700-
701-
assert political_edition.valid?
702-
end
703-
704-
test "after_change_notes' error message takes priority if multiple validation errors on first_published_at" do
705-
edition_with_change_note = create(:edition_with_document, :published, change_note: "changed", major_change_published_at: 2.days.ago)
706-
edition = build(:edition, document: edition_with_change_note.document, first_published_at: 10.years.from_now)
707-
edition.validate
708-
709-
assert_equal 1, edition.errors.size
710-
assert_equal "First published date must be before the first change note (09/11/2011 11:11)", edition.errors.full_messages.first
711-
end
712-
713681
test "#government returns the associated government when the edition has a specific government_id" do
714682
create(:current_government)
715683
previous_government = create(:previous_government)
@@ -738,7 +706,7 @@ class EditionTest < ActiveSupport::TestCase
738706
test "#government returns the historic government for a previously published edition" do
739707
previous_government = create(:previous_government)
740708
create(:current_government)
741-
edition = build(:edition, first_published_at: 4.years.ago)
709+
edition = create(:edition, first_published_at: 4.years.ago)
742710
assert_equal previous_government, edition.government
743711
end
744712

@@ -760,7 +728,7 @@ class EditionTest < ActiveSupport::TestCase
760728

761729
previous_government = create(:previous_government)
762730

763-
edition = build(:edition, political: false, first_published_at: previous_government.start_date)
731+
edition = create(:edition, political: false, first_published_at: previous_government.start_date)
764732
assert_not edition.historic?
765733

766734
edition = create(:edition, political: false, first_published_at: current_government.start_date)
@@ -1014,12 +982,6 @@ class EditionTest < ActiveSupport::TestCase
1014982
assert_not edition.valid?
1015983
end
1016984

1017-
test "#other_editions returns an empty array if there is no associated document" do
1018-
edition = build(:edition)
1019-
1020-
assert_equal edition.other_editions, []
1021-
end
1022-
1023985
def decoded_token_payload(token)
1024986
payload, _header = JWT.decode(
1025987
token,

test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class PublishingApi::DocumentCollectionPresenterPreviousGovernmentTest < ActiveS
403403
slug: "a-previous-government",
404404
)
405405
@presented_document_collection = PublishingApi::DocumentCollectionPresenter.new(
406-
build(
406+
create(
407407
:document_collection,
408408
first_published_at: @previous_government.start_date + 1.day,
409409
),

test/unit/app/presenters/publishing_api/statistical_data_set_presenter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class PublishingApi::StatisticalDataSetPresenterPreviousGovernmentTest < ActiveS
268268
slug: "a-previous-government",
269269
)
270270
@presented_statistical_data_set = PublishingApi::StatisticalDataSetPresenter.new(
271-
build(
271+
create(
272272
:statistical_data_set,
273273
first_published_at: @previous_government.start_date + 1.day,
274274
),

0 commit comments

Comments
 (0)