From af063d9d01eb62ff14e048630a552a2d3114cdbf Mon Sep 17 00:00:00 2001 From: Michael Walker Date: Fri, 6 Mar 2020 13:26:45 +0000 Subject: [PATCH] Revert "Override old "documents" fields with new "attachments" fields" --- app/presenters/consultation_presenter.rb | 16 ++------ .../featured_attachments_migration.rb | 23 ----------- app/presenters/publication_presenter.rb | 6 +-- .../featured_attachments_migration.rb | 41 ------------------- 4 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 app/presenters/content_item/featured_attachments_migration.rb delete mode 100644 test/presenters/content_item/featured_attachments_migration.rb diff --git a/app/presenters/consultation_presenter.rb b/app/presenters/consultation_presenter.rb index 5acb45a69..26393817a 100644 --- a/app/presenters/consultation_presenter.rb +++ b/app/presenters/consultation_presenter.rb @@ -5,7 +5,6 @@ class ConsultationPresenter < ContentItemPresenter include ContentItem::Political include ContentItem::Shareable include ContentItem::TitleAndContext - include ContentItem::FeaturedAttachmentsMigration def opening_date_time content_item["details"]["opening_date"] @@ -136,23 +135,14 @@ def ways_to_respond end def final_outcome_documents_list - @final_outcome_documents_list ||= choose_field( - new_field_name: "final_outcome_attachments", - old_field_name: "final_outcome_documents", - ) + content_item["details"]["final_outcome_documents"] || [] end def public_feedback_documents_list - @public_feedback_documents_list ||= choose_field( - new_field_name: "public_feedback_attachments", - old_field_name: "public_feedback_documents", - ) + content_item["details"]["public_feedback_documents"] || [] end def documents_list - @documents_list ||= choose_field( - new_field_name: "featured_attachments", - old_field_name: "documents", - ) + content_item["details"]["documents"] || [] end end diff --git a/app/presenters/content_item/featured_attachments_migration.rb b/app/presenters/content_item/featured_attachments_migration.rb deleted file mode 100644 index 4806a1a0f..000000000 --- a/app/presenters/content_item/featured_attachments_migration.rb +++ /dev/null @@ -1,23 +0,0 @@ -module ContentItem - module FeaturedAttachmentsMigration - def choose_field(new_field_name:, old_field_name:) - new_list = content_item["details"][new_field_name] - old_list = content_item["details"][old_field_name] || [] - - # don't raise an error just because a document hasn't been - # republished to have the new field yet. - return old_list if new_list.nil? - - if new_list.length == old_list.length - new_list - else - GovukError.notify( - "Mismatch between attachments and documents", - extra: { error_message: "Document with #{new_list.length} #{new_field_name} but #{old_list.length} #{old_field_name} at #{base_path}" }, - ) - - old_list - end - end - end -end diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index 161635078..97032933c 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -3,7 +3,6 @@ class PublicationPresenter < ContentItemPresenter include ContentItem::NationalApplicability include ContentItem::NationalStatisticsLogo include ContentItem::Political - include ContentItem::FeaturedAttachmentsMigration def details content_item["details"]["body"] @@ -28,9 +27,6 @@ def dataset? private def documents_list - @documents_list ||= choose_field( - new_field_name: "featured_attachments", - old_field_name: "documents", - ) + content_item["details"]["documents"] end end diff --git a/test/presenters/content_item/featured_attachments_migration.rb b/test/presenters/content_item/featured_attachments_migration.rb deleted file mode 100644 index a796c81bf..000000000 --- a/test/presenters/content_item/featured_attachments_migration.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "test_helper" - -class FeaturedAttachmentsMigrationTest < ActiveSupport::TestCase - class DummyContentItem - include ContentItem::FeaturedAttachmentsMigration - attr_accessor :content_item - - def initialize(old_list, new_list) - @content_item = { - "base_path" => "/a/base/path", - "details" => { "old_badness" => old_list, "new_hotness" => new_list }.compact, - "links" => {}, - } - end - - def choose - choose_field( - old_field_name: "old_badness", - new_field_name: "new_hotness", - ) - end - end - - test "presents the old field if the new one is missing" do - item = DummyContentItem.new(%w(1 2 3), nil) - - assert_equal %w(1 2 3), item.choose - end - - test "presents the old field if the new one is a different size" do - item = DummyContentItem.new(%w(1 2 3), %w(foo bar baz bat)) - - assert_equal %w(1 2 3), item.choose - end - - test "presents the new field if present and the old one is the same size" do - item = DummyContentItem.new(%w(1 2 3), %w(foo bar baz)) - - assert_equal %w(foo bar baz), item.choose - end -end