diff --git a/app/components/admin/currently_featured_tab_component.rb b/app/components/admin/currently_featured_tab_component.rb index 78d8da66acc..6dcc367ebdd 100644 --- a/app/components/admin/currently_featured_tab_component.rb +++ b/app/components/admin/currently_featured_tab_component.rb @@ -26,18 +26,12 @@ def remaining def table(caption, featured) if features.present? render Admin::Features::FeaturedDocumentsTableComponent.new(caption:, features: featured) - else - # Legacy - render Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new(caption:, featurings: featured) end end def reorder_path if features.present? reorder_admin_feature_list_path(features.first.feature_list) - else - # legacy - reorder_admin_topical_event_topical_event_featurings_path(featurings.first.topical_event) end end end diff --git a/app/components/admin/features/featured_documents_table_component.rb b/app/components/admin/features/featured_documents_table_component.rb index e2a45d9bc9b..317fdacc984 100644 --- a/app/components/admin/features/featured_documents_table_component.rb +++ b/app/components/admin/features/featured_documents_table_component.rb @@ -34,8 +34,6 @@ def title_row(feature) def title(feature) if feature.document&.live_edition.present? feature - elsif feature.topical_event.present? # legacy - feature.topical_event elsif feature.offsite_link.present? feature.offsite_link else @@ -52,8 +50,6 @@ def type_row(feature) def type(feature) if feature.document&.live_edition.present? "#{feature.document.live_edition.display_type} (document)" - elsif feature.topical_event.present? - "Topical Event" elsif feature.offsite_link.present? "#{feature.offsite_link.humanized_link_type} (offsite link)" else @@ -76,8 +72,6 @@ def actions_row(feature) def edit_link(feature) if feature.document&.live_edition.present? link_to(sanitize("Edit #{tag.span(feature, class: 'govuk-visually-hidden')}"), admin_edition_path(feature.document.live_edition), class: "govuk-link") - elsif feature.topical_event.present? # legacy - link_to(sanitize("Edit #{tag.span(feature.topical_event, class: 'govuk-visually-hidden')}"), edit_admin_topical_event_path(feature.topical_event), class: "govuk-link") elsif feature.offsite_link.present? link_to(sanitize("Edit #{tag.span(feature.offsite_link, class: 'govuk-visually-hidden')}"), polymorphic_path([:edit, :admin, feature.offsite_link.parent, feature.offsite_link]), class: "govuk-link") else @@ -86,7 +80,7 @@ def edit_link(feature) end def unfeature_link(feature) - if feature.document&.live_edition.present? || feature.topical_event.present? || feature.offsite_link.present? + if feature.document&.live_edition.present? || feature.offsite_link.present? link_to(sanitize("Unfeature #{tag.span(title(feature), class: 'govuk-visually-hidden')}"), confirm_unfeature_admin_feature_list_feature_path(feature.feature_list, feature), class: "gem-link--destructive govuk-!-margin-left-2") else "" diff --git a/app/components/admin/organisations/show/summary_list_component.rb b/app/components/admin/organisations/show/summary_list_component.rb index 1b4a57ef3c5..67cb93801c0 100644 --- a/app/components/admin/organisations/show/summary_list_component.rb +++ b/app/components/admin/organisations/show/summary_list_component.rb @@ -32,7 +32,6 @@ def rows recruitment_url_row, political_row, parent_organisations_row, - topical_events_row, # legacy featured_links_position_row, featured_links_row, foi_exempt_row, @@ -193,13 +192,6 @@ def parent_organisations_row associations_rows(parent_organisations, "Sponsoring organisation") end - # legacy - def topical_events_row - return if topical_events.blank? - - associations_rows(topical_events, "Topical event") - end - def featured_links_position_row { field: "Featured link position", @@ -259,11 +251,6 @@ def parent_organisations @parent_organisations ||= organisation.parent_organisations end - # legacy - def topical_events - @topical_events ||= organisation.topical_events - end - def featured_links @featured_links ||= organisation.featured_links end diff --git a/app/components/admin/topical_events/featurings/featured_documents_table_component.html.erb b/app/components/admin/topical_events/featurings/featured_documents_table_component.html.erb deleted file mode 100644 index da6c7938ea9..00000000000 --- a/app/components/admin/topical_events/featurings/featured_documents_table_component.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%= render "govuk_publishing_components/components/table", { - caption:, - caption_classes: "govuk-heading-s", - head: [ - { - text: "Title", - }, - { - text: "Type", - }, - { - text: "Published", - }, - { - text: tag.span("Actions", class: "govuk-visually-hidden"), - format: "numeric", - }, - ], - rows: rows(featurings), -} %> diff --git a/app/components/admin/topical_events/featurings/featured_documents_table_component.rb b/app/components/admin/topical_events/featurings/featured_documents_table_component.rb deleted file mode 100644 index 458ecf984a6..00000000000 --- a/app/components/admin/topical_events/featurings/featured_documents_table_component.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -# Legacy -class Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent < ViewComponent::Base - include Admin::EditionRoutesHelper - include Admin::TopicalEventFeaturingsHelper - - attr_reader :caption, :featurings - - def initialize(caption:, featurings:) - @caption = caption - @featurings = featurings - end - -private - - def rows(featurings) - featurings.map do |featuring| - [ - title_row(featuring), - type_row(featuring), - published_row(featuring), - actions_row(featuring), - ] - end - end - - def title_row(featuring) - { - text: tag.p(featuring.title, class: "govuk-!-font-weight-bold govuk-!-margin-0"), - } - end - - def type_row(featuring) - { - text: type(featuring), - } - end - - def type(featuring) - if featuring.offsite? - "#{featuring.offsite_link.humanized_link_type} (offsite link)" - else - "#{featuring.edition.display_type} (document)" - end - end - - def published_row(featuring) - { - text: featuring_published_on(featuring), - } - end - - def actions_row(featuring) - { - text: sanitize(edit_link(featuring) + unfeature_link(featuring)), - } - end - - def edit_link(featuring) - if featuring.offsite? - link_to(sanitize("Edit #{tag.span(featuring.offsite_link, class: 'govuk-visually-hidden')}"), edit_admin_topical_event_offsite_link_path(featuring.topical_event, featuring.offsite_link), class: "govuk-link") - else - link_to(sanitize("View #{tag.span(featuring.title, class: 'govuk-visually-hidden')}"), admin_edition_path(featuring.edition), class: "govuk-link") - end - end - - def unfeature_link(featuring) - link_to(sanitize("Unfeature #{tag.span(featuring.title, class: 'govuk-visually-hidden')}"), confirm_destroy_admin_topical_event_topical_event_featuring_path(featuring.topical_event, featuring), class: "gem-link--destructive govuk-!-margin-left-2") - end -end diff --git a/app/controllers/admin/editions_controller.rb b/app/controllers/admin/editions_controller.rb index 777beb8de12..3e25184d361 100644 --- a/app/controllers/admin/editions_controller.rb +++ b/app/controllers/admin/editions_controller.rb @@ -253,8 +253,7 @@ def permitted_edition_attributes world_location_ids: [], worldwide_organisation_ids: [], topic_ids: [], - topical_event_ids: [], # LEGACY - topical_event_document_ids: [], # New + topical_event_document_ids: [], related_detailed_guide_ids: [], role_appointment_ids: [], statistical_data_set_document_ids: [], diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb index 6e36ce2af13..5fc8a4e1db1 100644 --- a/app/controllers/admin/features_controller.rb +++ b/app/controllers/admin/features_controller.rb @@ -1,7 +1,7 @@ class Admin::FeaturesController < Admin::BaseController before_action :find_feature_list before_action :build_feature, only: %i[new create] - before_action :find_edition, :find_topical_event, :find_offsite_link, only: [:new] + before_action :find_edition, :find_offsite_link, only: [:new] def new; end @@ -47,7 +47,6 @@ def feature_params params.fetch(:feature, {}).permit( :alt_text, :document_id, - :topical_event_id, # LEGACY :offsite_link_id, image_attributes: %i[file], ) @@ -57,11 +56,6 @@ def find_edition @feature.document = Edition.find(params[:edition_id]).document if params[:edition_id] end - # LEGACY - def find_topical_event - @feature.topical_event = TopicalEvent.find(params[:topical_event_id]) if params[:topical_event_id] - end - def find_offsite_link @feature.offsite_link = OffsiteLink.find(params[:offsite_link_id]) if params[:offsite_link_id] end diff --git a/app/controllers/admin/offsite_links_controller.rb b/app/controllers/admin/offsite_links_controller.rb index 15282d7afb5..ce946cdde35 100644 --- a/app/controllers/admin/offsite_links_controller.rb +++ b/app/controllers/admin/offsite_links_controller.rb @@ -44,7 +44,6 @@ def destroy def load_parent @parent = WorldLocation.friendly.find(params[:world_location_news_id]).world_location_news if params[:world_location_news_id] @parent = Organisation.friendly.find(params[:organisation_id]) if params[:organisation_id] - @parent = TopicalEvent.friendly.find(params[:topical_event_id]) if params[:topical_event_id] # Legacy @parent = Edition.find(params[:standard_edition_id]) if params[:standard_edition_id] end @@ -53,19 +52,11 @@ def load_offsite_link end def offsite_link_path(offsite_link) - if offsite_link.parent.is_a? TopicalEvent # legacy - polymorphic_path([:admin, offsite_link.parent, :topical_event_featurings]) - else - polymorphic_url([:features, :admin, offsite_link.parent]) - end + polymorphic_url([:features, :admin, offsite_link.parent]) end def offsite_links_path - if @parent.is_a? TopicalEvent #  legacy - polymorphic_path([:admin, @parent, :topical_event_featurings], anchor: "non_govuk_government_links_tab") - else - polymorphic_path([:features, :admin, @parent], anchor: "non_govuk_government_links_tab") - end + polymorphic_path([:features, :admin, @parent], anchor: "non_govuk_government_links_tab") end def offsite_link_params diff --git a/app/controllers/admin/organisations_controller.rb b/app/controllers/admin/organisations_controller.rb index 96d3d158d2c..f463ac9b322 100644 --- a/app/controllers/admin/organisations_controller.rb +++ b/app/controllers/admin/organisations_controller.rb @@ -47,7 +47,6 @@ def features ) @filter = Admin::EditionFilter.new(Edition, current_user, filter_params) - @featurable_topical_events = TopicalEvent.active #  legacy @featurable_offsite_links = @organisation.offsite_links render :features @@ -56,7 +55,6 @@ def features def edit; end def update - delete_absent_topical_event_organisations if @organisation.update(organisation_params) redirect_to admin_organisation_path(@organisation), notice: "Organisation updated successfully." else @@ -116,32 +114,10 @@ def organisation_params default_news_image_attributes: %i[file file_cache id], organisation_roles_attributes: %i[id ordering], parent_organisation_ids: [], - topical_event_organisations_attributes: %i[topical_event_id ordering id _destroy], featured_links_attributes: %i[title url _destroy id], ) end - def build_topical_event_organisations - n = @organisation.topical_event_organisations.count - @organisation.topical_event_organisations.each.with_index do |ot, i| - ot.ordering = i - end - (n...13).each do |i| - @organisation.topical_event_organisations.build(ordering: i) - end - end - - def delete_absent_topical_event_organisations - return unless organisation_params && - organisation_params[:topical_event_organisations_attributes] - - organisation_params[:topical_event_organisations_attributes].each do |p| - if p[:topical_event_id].blank? - p["_destroy"] = true - end - end - end - def build_organisation @organisation = Organisation.new end @@ -151,7 +127,6 @@ def load_organisation end def build_dependencies - build_topical_event_organisations @organisation.build_default_news_image if @organisation.default_news_image.blank? @organisation.featured_links.build if @organisation.featured_links.blank? end diff --git a/app/controllers/admin/topical_event_about_pages_controller.rb b/app/controllers/admin/topical_event_about_pages_controller.rb deleted file mode 100644 index e528a01050b..00000000000 --- a/app/controllers/admin/topical_event_about_pages_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -class Admin::TopicalEventAboutPagesController < Admin::BaseController - before_action :find_topical_event - before_action :find_page, except: %i[new create] - - def new - @topical_event_about_page = TopicalEventAboutPage.new(topical_event: @topical_event) - end - - def create - @topical_event_about_page = @topical_event.build_topical_event_about_page(about_page_params) - if @topical_event_about_page.save - redirect_to admin_topical_event_topical_event_about_pages_path, notice: "About page created" - else - render :new - end - end - - def edit; end - - def update - if @topical_event_about_page.update(about_page_params) - redirect_to admin_topical_event_topical_event_about_pages_path, notice: "About page saved" - else - render :edit - end - end - - def show - @topical_event_about_page = @topical_event.topical_event_about_page - end - -private - - def find_topical_event - @topical_event = TopicalEvent.friendly.find(params[:topical_event_id]) - end - - def find_page - @topical_event_about_page = @topical_event.topical_event_about_page - end - - def about_page_params - params.require(:topical_event_about_page).permit(:body, :name, :summary, :read_more_link_text) - end -end diff --git a/app/controllers/admin/topical_event_featurings_controller.rb b/app/controllers/admin/topical_event_featurings_controller.rb deleted file mode 100644 index 03bc6d70772..00000000000 --- a/app/controllers/admin/topical_event_featurings_controller.rb +++ /dev/null @@ -1,112 +0,0 @@ -# LEGACY TOPICAL EVENTS ONLY -class Admin::TopicalEventFeaturingsController < Admin::BaseController - before_action :load_topical_event - before_action :load_topical_event_featuring, only: %i[confirm_destroy destroy] - - def index - filter_params = params.slice(:page, :type, :author, :organisation, :title) - .permit! - .to_h - .merge( - page_title: "GOV.UK content tagged to this topical event", - per_page: Admin::EditionFilter::GOVUK_DESIGN_SYSTEM_PER_PAGE, - state: "published", - topical_event: @topical_event.to_param, - ) - - @filter = Admin::EditionFilter.new(Edition, current_user, filter_params) - @tagged_editions = editions_to_show - - @topical_event_featurings = @topical_event.topical_event_featurings - @featurable_offsite_links = @topical_event.offsite_links - end - - def new - featured_edition = Edition.find(params[:edition_id]) if params[:edition_id].present? - featured_offsite_link = OffsiteLink.find(params[:offsite_link_id]) if params[:offsite_link_id].present? - @topical_event_featuring = @topical_event.topical_event_featurings.build(edition: featured_edition, offsite_link: featured_offsite_link) - @topical_event_featuring.build_image - end - - def create - @topical_event_featuring = @topical_event.feature(topical_event_featuring_params) - if @topical_event_featuring.valid? - flash[:notice] = if featuring_a_document? - "#{@topical_event_featuring.edition.title} has been featured on #{@topical_event.name}" - else - "#{@topical_event_featuring.offsite_link.title} has been featured on #{@topical_event.name}" - end - redirect_to polymorphic_path([:admin, @topical_event, :topical_event_featurings]) - else - render :new - end - end - - def reorder; end - - def order - @topical_event.topical_event_featurings.reorder_without_callbacks!(order_params) - Whitehall::PublishingApi.republish_async(@topical_event) - - redirect_to polymorphic_path([:admin, @topical_event, :topical_event_featurings]), notice: "Featured items re-ordered" - end - - def confirm_destroy; end - - def destroy - if featuring_a_document? - edition = @topical_event_featuring.edition - @topical_event_featuring.destroy! - flash[:notice] = "#{edition.title} has been unfeatured from #{@topical_event.name}" - else - offsite_link = @topical_event_featuring.offsite_link - @topical_event_featuring.destroy! - flash[:notice] = "#{offsite_link.title} has been unfeatured from #{@topical_event.name}" - end - redirect_to polymorphic_path([:admin, @topical_event, :topical_event_featurings]) - end - - helper_method :featuring_a_document? - def featuring_a_document? - @topical_event_featuring.edition.present? - end - -private - - def load_topical_event - @topical_event = TopicalEvent.find(params[:topical_event_id]) - end - - def load_topical_event_featuring - @topical_event_featuring = @topical_event.topical_event_featurings.find(params[:id]) - end - - def editions_to_show - if filter_values_set? - @filter.editions - else - @topical_event.editions.published - .with_translations - .order("editions.created_at DESC") - .page(params[:page]) - .per(Admin::EditionFilter::GOVUK_DESIGN_SYSTEM_PER_PAGE) - end - end - - def filter_values_set? - params.slice(:page, :type, :author, :organisation, :title).permit!.to_h.any? - end - - def topical_event_featuring_params - params.require(:topical_event_featuring).permit( - :alt_text, - :edition_id, - :offsite_link_id, - image_attributes: %i[file], - ) - end - - def order_params - params.require(:topical_event_featurings)["ordering"] - end -end diff --git a/app/controllers/admin/topical_event_organisations_controller.rb b/app/controllers/admin/topical_event_organisations_controller.rb deleted file mode 100644 index 1d7cc2b7fd5..00000000000 --- a/app/controllers/admin/topical_event_organisations_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Admin::TopicalEventOrganisationsController < Admin::BaseController - before_action :load_topical_event - - def index; end - - def reorder; end - - def order - @topical_event.topical_event_organisations.reorder_without_callbacks!(order_params, :lead_ordering) - - Whitehall::PublishingApi.republish_async(@topical_event) - - redirect_to polymorphic_path([:admin, @topical_event, :topical_event_organisations]), notice: "Lead organisations have been reordered." - end - - def toggle_lead - topical_event_organisation = TopicalEventOrganisation.find(params[:id]) - lead = topical_event_organisation.lead - @topical_event.topical_event_organisations.find(topical_event_organisation.id).update!( - lead ? { lead: false, lead_ordering: nil } : { lead: true, lead_ordering: @topical_event.lead_topical_event_organisations.count }, - ) - - Whitehall::PublishingApi.republish_async(@topical_event) - - redirect_to polymorphic_path([:admin, @topical_event, :topical_event_organisations]), notice: "#{topical_event_organisation.organisation.name} has been assigned as a #{lead ? 'supporting' : 'lead'} organisation." - end - -private - - def load_topical_event - @topical_event = TopicalEvent.find(params[:topical_event_id]) - end - - def order_params - params.require(:topical_event_lead_organisations)["ordering"] - end -end diff --git a/app/controllers/admin/topical_events_controller.rb b/app/controllers/admin/topical_events_controller.rb deleted file mode 100644 index d9724a1e326..00000000000 --- a/app/controllers/admin/topical_events_controller.rb +++ /dev/null @@ -1,102 +0,0 @@ -# LEGACY TOPICAL EVENTS ONLY -class Admin::TopicalEventsController < Admin::BaseController - before_action :load_object, only: %i[show edit confirm_destroy destroy] - before_action :build_object, only: [:new] - before_action :build_associated_objects, only: %i[new edit] - before_action :destroy_blank_social_media_accounts, only: %i[create update] - - def show; end - - def index - @topical_events = TopicalEvent.order(:name) - end - - def new; end - - def create - @topical_event = TopicalEvent.new(object_params) - if @topical_event.save - redirect_to [:admin, @topical_event], notice: "Topical event created" - else - build_associated_objects - render :new - end - end - - def edit; end - - def update - @topical_event = TopicalEvent.friendly.find(params[:id]) - if @topical_event.update(object_params) - if object_params[:topical_event_featurings_attributes] - redirect_to [:admin, @topical_event, :topical_event_featurings], notice: "Order of featured items updated" - else - redirect_to [:admin, TopicalEvent.new], notice: "Topical event updated" - end - else - build_associated_objects - render :edit - end - end - - def confirm_destroy; end - - def destroy - @topical_event.destroy! - if @topical_event.destroyed? - redirect_to [:admin, TopicalEvent], notice: "Topical event destroyed" - else - redirect_to [:admin, TopicalEvent], alert: "Cannot destroy Topical event with associated content" - end - end - - def build_object - @topical_event = TopicalEvent.new - end - - def load_object - @topical_event = TopicalEvent.friendly.find(params[:id]) - end - - def build_associated_objects - @topical_event.social_media_accounts.build if @topical_event.social_media_accounts.blank? - @topical_event.build_logo if @topical_event.logo.blank? - end - - def destroy_blank_social_media_accounts - if params[:topical_event][:social_media_accounts_attributes] - params[:topical_event][:social_media_accounts_attributes].each_pair do |_key, account| - if account[:social_media_service_id].blank? && account[:url].blank? - account[:_destroy] = "1" - end - end - end - end - - def object_params - topical_event_params = params.require(:topical_event).permit( - :name, - :summary, - :description, - :logo_alt_text, - :start_date, - :end_date, - related_topical_event_ids: [], - topical_event_membership_attributes: %i[id ordering], - social_media_accounts_attributes: %i[social_media_service_id url _destroy id], - featured_links_attributes: %i[title url _destroy id], - topical_event_organisations_attributes: %i[id lead lead_ordering], - logo_attributes: %i[file file_cache id], - ) - - clear_file_cache(topical_event_params) - end - - def clear_file_cache(topical_event_params) - if topical_event_params.dig(:logo_attributes, :file).present? && topical_event_params.dig(:logo_attributes, :file_cache).present? - topical_event_params[:logo_attributes].delete(:file_cache) - end - - topical_event_params - end -end diff --git a/app/controllers/admin/world_location_news_controller.rb b/app/controllers/admin/world_location_news_controller.rb index a1e900109cb..74b549be962 100644 --- a/app/controllers/admin/world_location_news_controller.rb +++ b/app/controllers/admin/world_location_news_controller.rb @@ -32,7 +32,6 @@ def features ) @filter = Admin::EditionFilter.new(Edition, current_user, filter_params) - @featurable_topical_events = TopicalEvent.active @featurable_offsite_links = @world_location.world_location_news.offsite_links if request.xhr? diff --git a/app/helpers/admin/features_helper.rb b/app/helpers/admin/features_helper.rb index cf5ecb6f07f..82c040c9dcf 100644 --- a/app/helpers/admin/features_helper.rb +++ b/app/helpers/admin/features_helper.rb @@ -7,14 +7,6 @@ def featurable_offsite_links_for_feature_list(featurable_offsite_links, feature_ end end - def featurable_topical_events_for_feature_list(featurable_topical_events, feature_list) - @featurable_topical_events_for_feature_list ||= featurable_topical_events.reject do |topical_event| - feature_list.features.current.detect do |feature| - feature.topical_event == topical_event - end - end - end - def featurable_editions_for_feature_list(editions, feature_list) @featurable_editions_for_feature_list ||= editions .select { |ed| feature_list.features.current.none? { |f| f.document == ed.document } } @@ -24,8 +16,6 @@ def featurable_editions_for_feature_list(editions, feature_list) def feature_published_on(feature) if feature.document&.live_edition.present? localize(feature.document.live_edition.major_change_published_at.to_date) - elsif feature.topical_event.present? - topical_event_dates_string(feature.topical_event) elsif feature.offsite_link.present? (localize(feature.offsite_link.date.to_date) if feature.offsite_link.date) || "" else diff --git a/app/helpers/admin/organisation_helper.rb b/app/helpers/admin/organisation_helper.rb index cffa452265d..27eb28028e7 100644 --- a/app/helpers/admin/organisation_helper.rb +++ b/app/helpers/admin/organisation_helper.rb @@ -101,14 +101,6 @@ def logo_visibility_css(organisation) end end - # legacy - def topical_event_dates_string(topical_event) - [ - topical_event.start_date.try(:to_date), - topical_event.end_date.try(:to_date), - ].compact.map { |date| l(date) }.join(" to ") - end - def organisation_context_block(current_user, organisation) name = organisation.class.name.underscore.humanize current_user.organisation == organisation ? "My #{name.downcase}" : name diff --git a/app/helpers/admin/taggable_content_helper.rb b/app/helpers/admin/taggable_content_helper.rb index 8d46ea52f17..fd824bddaf6 100644 --- a/app/helpers/admin/taggable_content_helper.rb +++ b/app/helpers/admin/taggable_content_helper.rb @@ -3,16 +3,6 @@ module Admin::TaggableContentHelper include ActionView::Helpers::TranslationHelper - def taggable_topical_events_container(selected_ids = []) - TopicalEvent.order(:name).map do |topical_event| - { - text: topical_event.name, - value: topical_event.id, - selected: selected_ids.include?(topical_event.id), - } - end - end - def taggable_topical_event_documents_container(selected_ids = []) StandardEdition .latest_edition @@ -123,14 +113,6 @@ def cached_taggable_organisations end end - # Returns an MD5 digest representing the current set of taggable topical - # events. This will change if any of the Topics should change or if a new - # topic event is added. - def taggable_topical_events_cache_digest - # legacy - @taggable_topical_events_cache_digest ||= calculate_digest(TopicalEvent.order(:id), "topical-events") - end - # Returns an MD5 digest representing the current set of taggable # organisations. This will change if any of the Topics should change or if a # new organisation is added. diff --git a/app/helpers/admin/topical_event_helper.rb b/app/helpers/admin/topical_event_helper.rb deleted file mode 100644 index 845201b8b4c..00000000000 --- a/app/helpers/admin/topical_event_helper.rb +++ /dev/null @@ -1,35 +0,0 @@ -# Legacy -module Admin::TopicalEventHelper - def topical_event_nav_items(topical_event, current_path) - [ - { - label: "Details", - href: [:admin, topical_event], - current: current_path == url_for([:admin, topical_event]), - }, - { - label: "Organisations", - href: [:admin, topical_event, :topical_event_organisations], - current: current_path == url_for([:admin, topical_event, :topical_event_organisations]), - }, - { - label: "About page", - href: [:admin, topical_event, :topical_event_about_pages], - current: current_path == url_for([:admin, topical_event, :topical_event_about_pages]), - }, - { - label: "Featured", - href: [:admin, topical_event, :topical_event_featurings], - current: current_path == url_for([:admin, topical_event, :topical_event_featurings]), - }, - ] - end - - def duration_row_value(topical_event) - if topical_event.start_date.present? && topical_event.end_date.present? - "#{topical_event.start_date} to #{topical_event.end_date}" - else - "" - end - end -end diff --git a/app/helpers/admin/topical_events_helper.rb b/app/helpers/admin/topical_events_helper.rb deleted file mode 100644 index 1661bfac49d..00000000000 --- a/app/helpers/admin/topical_events_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Legacy -module Admin::TopicalEventsHelper - def topical_event_contents_breakdown(topical_event) - capture do - concat tag.span(pluralize(topical_event.published_detailed_guides.count, "published detailed guide")) - end - end -end diff --git a/app/helpers/admin/url_helper.rb b/app/helpers/admin/url_helper.rb index d1f32244737..9b3154053ce 100644 --- a/app/helpers/admin/url_helper.rb +++ b/app/helpers/admin/url_helper.rb @@ -1,9 +1,4 @@ module Admin::UrlHelper - # legacy - def admin_topical_events_link - admin_link "Topical events", admin_topical_events_path - end - def admin_organisations_link admin_link "Organisations", admin_organisations_path end diff --git a/app/helpers/presenters/publishing_api/featured_documents_helper.rb b/app/helpers/presenters/publishing_api/featured_documents_helper.rb index c56eeb2cd92..9477996a982 100644 --- a/app/helpers/presenters/publishing_api/featured_documents_helper.rb +++ b/app/helpers/presenters/publishing_api/featured_documents_helper.rb @@ -10,8 +10,6 @@ def featured_documents(featurable_item, document_limit) .map do |feature| if feature.document featured_documents_editioned(feature) - elsif feature.topical_event # legacy - featured_documents_topical_event(feature) elsif feature.offsite_link featured_documents_offsite_link(feature) end @@ -29,21 +27,7 @@ def featured_documents_editioned(feature) image: get_image(feature), summary: govspeak_to_html(edition.summary), public_updated_at: edition.public_timestamp, - document_type: edition.display_type, - } - end - - # Legacy - def featured_documents_topical_event(feature) - # Topical events that have been featured - topical_event = feature.topical_event - { - title: topical_event.name, - href: topical_event.public_path(locale: feature.feature_list.locale), - image: get_image(feature), - summary: govspeak_to_html(topical_event.summary), - public_updated_at: topical_event.start_date, - document_type: nil, # We don't want a type for topical events + document_type: edition.display_type, # we're happy sending document type and letting Frontend filter it out. } end diff --git a/app/models/admin/edition_filter.rb b/app/models/admin/edition_filter.rb index acee7ebb8ef..e20fd9257f0 100644 --- a/app/models/admin/edition_filter.rb +++ b/app/models/admin/edition_filter.rb @@ -115,7 +115,6 @@ def unpaginated_editions editions = editions.in_state(state) if state editions = editions.authored_by(author) if author editions = editions.in_organisation(organisation) if organisation - editions = editions.with_topical_event(topical_event) if topical_event # Legacy editions = editions.with_title_containing(title) if title editions = editions.in_world_location(selected_world_locations) if selected_world_locations.any? editions = editions.from_date(from_date) if from_date @@ -282,11 +281,6 @@ def validate_date(field) @errors << "The '#{field.to_s.humanize}' is incorrect. It should be dd/mm/yyyy" unless is_valid end - # Legacy - def topical_event - TopicalEvent.find(options[:topical_event]) if options[:topical_event].present? - end - def not_validated_since options[:not_validated_since].presence end diff --git a/app/models/concerns/edition/scopes/filterable_by_topical_event.rb b/app/models/concerns/edition/scopes/filterable_by_topical_event.rb deleted file mode 100644 index c3df6cd21fd..00000000000 --- a/app/models/concerns/edition/scopes/filterable_by_topical_event.rb +++ /dev/null @@ -1,12 +0,0 @@ -# LEGACY -module Edition::Scopes::FilterableByTopicalEvent - extend ActiveSupport::Concern - - included do - # NOTE: this scope becomes redundant once Admin::EditionFilterer is backed by an admin-only search_api index - scope :with_topical_event, lambda { |topical_event| - joins("INNER JOIN topical_event_memberships ON topical_event_memberships.edition_id = editions.id") - .where("topical_event_memberships.topical_event_id" => topical_event.id) - } - end -end diff --git a/app/models/concerns/edition/topical_events.rb b/app/models/concerns/edition/topical_events.rb index 38bc619a55e..ca0ac6f17d6 100644 --- a/app/models/concerns/edition/topical_events.rb +++ b/app/models/concerns/edition/topical_events.rb @@ -1,19 +1,10 @@ +# TODO: we want to make the concept of linking documents to other documents more 'abstract' +# i.e. drop the 'topical event' specific language throughout Whitehall. module Edition::TopicalEvents extend ActiveSupport::Concern class Trait < Edition::Traits::Trait def process_associations_before_save(edition) - # LEGACY - edition.topical_event_featurings = @edition.topical_event_featurings.map do |cf| - TopicalEventFeaturing.new(cf.attributes.except("id")) - end - - # LEGACY - edition.topical_event_memberships = @edition.topical_event_memberships.map do |dt| - TopicalEventMembership.new(dt.attributes.except("id")) - end - - # NEW edition.topical_event_links = @edition.topical_event_links.map do |link| EditionLink.new(link.attributes.except("id")) end @@ -21,11 +12,6 @@ def process_associations_before_save(edition) end included do - # LEGACY - has_many :topical_event_featurings, dependent: :destroy, foreign_key: :edition_id - has_many :topical_event_memberships, dependent: :destroy, inverse_of: :edition, foreign_key: :edition_id - has_many :topical_events, through: :topical_event_memberships, source: :topical_event - # NEW has_many :topical_event_links, -> { of_type "topical_event" }, class_name: "EditionLink", dependent: :destroy, inverse_of: :edition, foreign_key: :edition_id has_many :topical_event_documents, through: :topical_event_links, source: :document @@ -37,8 +23,4 @@ def process_associations_before_save(edition) def can_be_associated_with_topical_events? true end - - def search_index - super.merge("topical_events" => topical_events.pluck(:slug)) - end end diff --git a/app/models/concerns/simple_workflow.rb b/app/models/concerns/simple_workflow.rb deleted file mode 100644 index cb77ee0922e..00000000000 --- a/app/models/concerns/simple_workflow.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Expects Searchable to be included and destroyable? defined. -module SimpleWorkflow - extend ActiveSupport::Concern - - included do - include ActiveRecord::Transitions - - default_scope -> { where(arel_table[:state].not_eq("deleted")) } - - state_machine auto_scopes: true, initial: :current do - state :current - state :deleted - - event :delete, success: ->(document) { document.remove_from_search_index if document.respond_to?(:remove_from_search_index) } do - transitions from: [:current], to: :deleted, guard: :destroyable? - end - end - - # Overwrite this - def destroyable? - true - end - end -end diff --git a/app/models/configurable_document_types/government_response.json b/app/models/configurable_document_types/government_response.json index 8afaa0d79b3..ecb9ada6848 100644 --- a/app/models/configurable_document_types/government_response.json +++ b/app/models/configurable_document_types/government_response.json @@ -20,20 +20,12 @@ "attribute_path": ["role_appointment_ids"], "translatable": false }, - "topical_events": { - "title": "Topical events", - "block": "select_with_search_tagging", - "container": "topical_events", - "attribute_path": ["topical_event_ids"], - "translatable": false - }, "topical_event_documents": { - "title": "Topical events (experimental)", + "title": "Topical events", "block": "select_with_search_tagging", "container": "topical_event_documents", "attribute_path": ["topical_event_document_ids"], - "translatable": false, - "experimental": true + "translatable": false }, "world_locations": { "title": "World locations", diff --git a/app/models/configurable_document_types/news_story.json b/app/models/configurable_document_types/news_story.json index 001efe0a8a0..58d58951626 100644 --- a/app/models/configurable_document_types/news_story.json +++ b/app/models/configurable_document_types/news_story.json @@ -20,20 +20,12 @@ "attribute_path": ["role_appointment_ids"], "translatable": false }, - "topical_events": { - "title": "Topical events", - "block": "select_with_search_tagging", - "container": "topical_events", - "attribute_path": ["topical_event_ids"], - "translatable": false - }, "topical_event_documents": { - "title": "Topical events (experimental)", + "title": "Topical events", "block": "select_with_search_tagging", "container": "topical_event_documents", "attribute_path": ["topical_event_document_ids"], - "translatable": false, - "experimental": true + "translatable": false }, "world_locations": { "title": "World locations", diff --git a/app/models/configurable_document_types/press_release.json b/app/models/configurable_document_types/press_release.json index 29d4614324e..bda9350069a 100644 --- a/app/models/configurable_document_types/press_release.json +++ b/app/models/configurable_document_types/press_release.json @@ -20,20 +20,12 @@ "attribute_path": ["role_appointment_ids"], "translatable": false }, - "topical_events": { - "title": "Topical events", - "block": "select_with_search_tagging", - "container": "topical_events", - "attribute_path": ["topical_event_ids"], - "translatable": false - }, "topical_event_documents": { - "title": "Topical events (experimental)", + "title": "Topical events", "block": "select_with_search_tagging", "container": "topical_event_documents", "attribute_path": ["topical_event_document_ids"], - "translatable": false, - "experimental": true + "translatable": false }, "world_locations": { "title": "World locations", diff --git a/app/models/configurable_document_types/world_news_story.json b/app/models/configurable_document_types/world_news_story.json index 20c8a79b4dc..68b5ef040ef 100644 --- a/app/models/configurable_document_types/world_news_story.json +++ b/app/models/configurable_document_types/world_news_story.json @@ -13,20 +13,12 @@ "attribute_path": ["block_content", "body"], "translatable": true }, - "topical_events": { - "title": "Topical Events", - "block": "select_with_search_tagging", - "container": "topical_events", - "attribute_path": ["topical_event_ids"], - "translatable": false - }, "topical_event_documents": { - "title": "Topical Events (experimental)", + "title": "Topical Events", "block": "select_with_search_tagging", "container": "topical_event_documents", "attribute_path": ["topical_event_document_ids"], - "translatable": false, - "experimental": true + "translatable": false }, "worldwide_organisations": { "title": "Worldwide organisations", diff --git a/app/models/edition.rb b/app/models/edition.rb index e7db502c7c1..4a5d6f66cf5 100644 --- a/app/models/edition.rb +++ b/app/models/edition.rb @@ -30,7 +30,6 @@ class Edition < ApplicationRecord include Edition::Scopes::FilterableByInvalid include Edition::Scopes::FilterableByBrokenLinks include Edition::Scopes::FilterableByDate - include Edition::Scopes::FilterableByTopicalEvent # legacy include Edition::Scopes::FilterableByType include Edition::Scopes::FilterableByWorldLocation include Edition::Scopes::FindableByOrganisation @@ -46,7 +45,6 @@ class Edition < ApplicationRecord has_many :editorial_remarks, dependent: :destroy has_many :edition_authors, dependent: :destroy has_many :authors, through: :edition_authors, source: :user - has_many :topical_event_featurings, inverse_of: :edition # legacy has_one :link_check_report, class_name: "LinkCheckerApiReport", dependent: :destroy has_many :edition_dependencies, dependent: :destroy @@ -84,7 +82,6 @@ class Edition < ApplicationRecord after_create :update_document_edition_references after_update :update_document_edition_references, if: :saved_change_to_state? - after_update :republish_topical_event_to_publishing_api #  legacy after_update :republish_featurable_to_publishing_api, if: :saved_change_to_state? accepts_nested_attributes_for :document @@ -465,13 +462,6 @@ def date_for_government published_edition_date || draft_edition_date end - # legacy - def republish_topical_event_to_publishing_api - topical_event_featurings.each do |topical_event_featuring| - Whitehall::PublishingApi.republish_async(topical_event_featuring.topical_event) - end - end - def republish_featurable_to_publishing_api active_features_referencing_this_document = document.features.where(ended_at: nil) active_features_referencing_this_document.each(&:republish_to_publishing_api_async) diff --git a/app/models/feature.rb b/app/models/feature.rb index 6ac5de42597..3aea459ae9e 100644 --- a/app/models/feature.rb +++ b/app/models/feature.rb @@ -1,6 +1,5 @@ class Feature < ApplicationRecord belongs_to :document - belongs_to :topical_event # Legacy belongs_to :offsite_link belongs_to :feature_list @@ -9,7 +8,7 @@ class Feature < ApplicationRecord validates :image, presence: true validates_associated :image, unless: -> { image.blank? || image.file.blank? } - validates :document, presence: true, unless: ->(feature) { feature.topical_event_id.present? || feature.offsite_link_id.present? } + validates :document, presence: true, unless: ->(feature) { feature.offsite_link_id.present? } validates :started_at, presence: true validates :alt_text, length: { maximum: 255 } validates :alt_text, format: { without: /\A[ \t'"\u201C\u201D\u2018\u2019]*\z/, message: "must not contain just spaces or quotes. (Leave this field empty to set an empty alt for decorative images.)" }, allow_blank: true @@ -21,8 +20,6 @@ class Feature < ApplicationRecord def to_s if document && document.live_edition LocalisedModel.new(document.live_edition, locale).title - elsif topical_event # Legacy - topical_event.name elsif offsite_link offsite_link.title else @@ -38,11 +35,6 @@ def self.with_published_edition joins(document: :live_edition) end - # Legacy - def self.with_topical_events - joins(:topical_event) - end - def end! self.ended_at = Time.zone.now save!(validate: false) diff --git a/app/models/feature_list.rb b/app/models/feature_list.rb index 7bb4f8220f7..e9dd5c46cb0 100644 --- a/app/models/feature_list.rb +++ b/app/models/feature_list.rb @@ -34,18 +34,13 @@ def reorder!(new_ordering) def current # Legacy - features.current.includes([:topical_event, { document: :live_edition }]) + features.current.includes([{ document: :live_edition }]) end def published_features features.current.with_published_edition end - def topical_events - # Legacy - features.current.with_topical_events - end - delegate :empty?, to: :current def republish_featurable_to_publishing_api diff --git a/app/models/offsite_link.rb b/app/models/offsite_link.rb index 49608451a1a..313dec75698 100644 --- a/app/models/offsite_link.rb +++ b/app/models/offsite_link.rb @@ -60,7 +60,6 @@ def self.display_type(link_type) has_many :offsite_link_parents has_many :organisations, through: :offsite_link_parents, source: :parent, source_type: "Organisation" - has_many :topical_events, through: :offsite_link_parents, source: :parent, source_type: "TopicalEvent" # Legacy has_many :world_location_news, through: :offsite_link_parents, source: :parent, source_type: "WorldLocationNews" has_many :editions, through: :offsite_link_parents, source: :parent, source_type: "Edition" @@ -75,7 +74,7 @@ def self.display_type(link_type) # We only expect one type of parent per offsite link (either organisations, or topical events, or world location news). # Once topical events become editionable, the parents will return all editions associated with the offsite link. def parents - organisations + topical_events + world_location_news + editions + organisations + world_location_news + editions end # For non-editionable parents, we are returning the last - and only - parent. diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 15706af87b0..0c99fc0bdcd 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -90,14 +90,6 @@ class Organisation < ApplicationRecord -> { extending UserOrderableExtension }, through: :roles - has_many :topical_event_organisations, # Legacy - -> { order("topical_event_organisations.ordering") }, - dependent: :destroy - - has_many :topical_events, # Legacy - -> { order("topical_event_organisations.ordering") }, - through: :topical_event_organisations - has_many :users, foreign_key: :organisation_slug, primary_key: :slug, dependent: :nullify has_many :contacts, as: :contactable, dependent: :destroy @@ -150,7 +142,6 @@ def foi_contacts accepts_nested_attributes_for :default_news_image, reject_if: :all_blank accepts_nested_attributes_for :organisation_roles accepts_nested_attributes_for :edition_organisations - accepts_nested_attributes_for :topical_event_organisations, reject_if: ->(attributes) { attributes["topical_event_id"].blank? }, allow_destroy: true accepts_nested_attributes_for :offsite_links validates :slug, presence: true, uniqueness: { case_sensitive: false } diff --git a/app/models/standard_edition.rb b/app/models/standard_edition.rb index b8c4357477d..e52054c4d5e 100644 --- a/app/models/standard_edition.rb +++ b/app/models/standard_edition.rb @@ -79,10 +79,7 @@ def allows_features? end def can_be_associated_with_topical_events? - [ - ConfigurableContentBlocks::Path.new("topical_event_ids"), # Legacy: delete when topical events migrated - ConfigurableContentBlocks::Path.new("topical_event_document_ids"), - ].any? { |path| field_paths.include?(path) } + field_paths.include?(ConfigurableContentBlocks::Path.new("topical_event_document_ids")) end def can_be_marked_political? diff --git a/app/models/topical_event.rb b/app/models/topical_event.rb index b6ec3f46670..c1f614e777b 100644 --- a/app/models/topical_event.rb +++ b/app/models/topical_event.rb @@ -1,20 +1,6 @@ # LEGACY TOPICAL EVENTS ONLY class TopicalEvent < ApplicationRecord - include DateValidation include PublishesToPublishingApi - include Searchable - include SimpleWorkflow - - date_attributes(:start_date, :end_date) - - searchable title: :name, - link: :search_link, - content: :description, - format: "topical_event", - description: :description_without_markup, - slug: :slug, - start_date: :start_date, - end_date: :end_date after_commit :republish_feature_organisations_to_publishing_api, if: :features? @@ -27,7 +13,6 @@ class TopicalEvent < ApplicationRecord has_many :features, inverse_of: :topical_event, dependent: :destroy has_many :offsite_link_parents, as: :parent has_many :offsite_links, through: :offsite_link_parents - has_many :social_media_accounts, as: :socialable, dependent: :destroy has_many :topical_event_organisations, -> { extending UserOrderableExtension } has_many :organisations, through: :topical_event_organisations @@ -56,7 +41,7 @@ class TopicalEvent < ApplicationRecord accepts_nested_attributes_for :logo, reject_if: :all_blank - scope :active, -> { where("end_date > ?", Time.zone.today) } + scope :active, -> { where("1=1") } # Temporary change - treat all topical events as active. validates_with SafeHtmlValidator validates_with NoFootnotesInGovspeakValidator, attribute: :description @@ -64,31 +49,16 @@ class TopicalEvent < ApplicationRecord validates :name, presence: true, uniqueness: { case_sensitive: false } # rubocop:disable Rails/UniqueValidationWithoutIndex validates :description, presence: true validates :summary, presence: true - validate :start_and_end_dates - validates :start_date, presence: true, if: ->(topical_event) { topical_event.end_date } accepts_nested_attributes_for :topical_event_memberships accepts_nested_attributes_for :topical_event_organisations accepts_nested_attributes_for :topical_event_featurings - accepts_nested_attributes_for :social_media_accounts, allow_destroy: true extend FriendlyId friendly_id alias_method :display_name, :to_s - def search_link - base_path - end - - def published_editions - editions.published - end - - def published_detailed_guides - published_editions.detailed_guides - end - def lead_organisations organisations.where(topical_event_organisations: { lead: true }).reorder("topical_event_organisations.lead_ordering") end @@ -98,11 +68,7 @@ def lead_topical_event_organisations end def latest(limit = 3) - published_editions.in_reverse_chronological_order.includes(:translations).limit(limit) - end - - def description_without_markup - Govspeak::Document.new(description).to_text + editions.published.in_reverse_chronological_order.includes(:translations).limit(limit) end def featured?(edition) @@ -168,19 +134,4 @@ def publishing_api_presenter def republish_feature_organisations_to_publishing_api features.map(&:republish_featurable_to_publishing_api) end - - def start_and_end_dates - if start_date && end_date - if more_than_a_year(start_date, end_date) - errors.add(:base, "cannot be longer than a year") - end - if start_date >= end_date - errors.add(:end_date, "cannot be before or equal to the start_date") - end - end - end - - def more_than_a_year(from_time, to_time = 0) - to_time > from_time + 1.year + 1.day # allow 1 day's leeway - end end diff --git a/app/models/topical_event_featuring.rb b/app/models/topical_event_featuring.rb deleted file mode 100644 index fa2e9b39799..00000000000 --- a/app/models/topical_event_featuring.rb +++ /dev/null @@ -1,72 +0,0 @@ -# LEGACY TOPICAL EVENTS ONLY -class TopicalEventFeaturing < ApplicationRecord - belongs_to :edition, inverse_of: :topical_event_featurings - belongs_to :offsite_link - belongs_to :topical_event, inverse_of: :topical_event_featurings - belongs_to :image, class_name: "TopicalEventFeaturingImageData", foreign_key: :topical_event_featuring_image_data_id - - accepts_nested_attributes_for :image, reject_if: :all_blank - - validate :image_is_present - validates :alt_text, presence: true, allow_blank: true - validates :alt_text, length: { maximum: 255 } - - validates :topical_event, :ordering, presence: true - - validates :edition_id, uniqueness: { scope: :topical_event_id }, unless: :offsite? - - after_save :republish_topical_event_to_publishing_api - after_destroy :republish_topical_event_to_publishing_api - - def title - if offsite? - offsite_link.title - else - edition.title - end - end - - def summary - if offsite? - offsite_link.summary - else - edition.summary - end - end - - def url - if offsite? - offsite_link.url - else - edition.base_path - end - end - - def offsite? - edition.nil? - end - - def public_timestamp - if offsite? - offsite_link.date - else - edition.public_timestamp - end - end - - def display_type - if offsite? - offsite_link.display_type - else - edition.display_type - end - end - - def republish_topical_event_to_publishing_api - Whitehall::PublishingApi.republish_async(topical_event) - end - - def image_is_present - errors.add(:"image.file", :blank) if image.blank? - end -end diff --git a/app/models/topical_event_featuring_image_data.rb b/app/models/topical_event_featuring_image_data.rb deleted file mode 100644 index 425b95890d5..00000000000 --- a/app/models/topical_event_featuring_image_data.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Legacy -class TopicalEventFeaturingImageData < ApplicationRecord - mount_uploader :file, FeaturedImageUploader, mount_on: :carrierwave_image - - include ImageKind - - has_one :topical_event_featuring, inverse_of: :image - has_many :assets, - as: :assetable, - inverse_of: :assetable - - validates :file, presence: true - - delegate :url, to: :file - - def filename - file&.file&.filename - end - - def all_asset_variants_uploaded? - asset_variants = assets.map(&:variant).map(&:to_sym) - required_variants = FeaturedImageUploader.versions.keys.push(:original) - - (required_variants - asset_variants).empty? - end - - def republish_on_assets_ready - if all_asset_variants_uploaded? - topical_event_featuring.topical_event.republish_to_publishing_api_async - end - end -end diff --git a/app/models/topical_event_membership.rb b/app/models/topical_event_membership.rb deleted file mode 100644 index fcf245d6a1e..00000000000 --- a/app/models/topical_event_membership.rb +++ /dev/null @@ -1,23 +0,0 @@ -# Legacy -class TopicalEventMembership < ApplicationRecord - belongs_to :edition - belongs_to :topical_event, inverse_of: :topical_event_memberships - - belongs_to :detailed_guide, foreign_key: :edition_id - belongs_to :speech, foreign_key: :edition_id - belongs_to :publication, foreign_key: :edition_id - belongs_to :consultation, foreign_key: :edition_id - belongs_to :call_for_evidence, foreign_key: :edition_id - - def self.published - joins(:edition).where("editions.state" => "published") - end - - def self.for_type(type) - joins(:edition).where("editions.type" => type) - end - - def edition - Edition.unscoped { super } - end -end diff --git a/app/models/topical_event_organisation.rb b/app/models/topical_event_organisation.rb deleted file mode 100644 index 0db42fa91cb..00000000000 --- a/app/models/topical_event_organisation.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Legacy -class TopicalEventOrganisation < ApplicationRecord - belongs_to :organisation - belongs_to :topical_event -end diff --git a/app/presenters/publishing_api/payload_builder/configurable_document_links.rb b/app/presenters/publishing_api/payload_builder/configurable_document_links.rb index 91176f5a92b..46ba030114a 100644 --- a/app/presenters/publishing_api/payload_builder/configurable_document_links.rb +++ b/app/presenters/publishing_api/payload_builder/configurable_document_links.rb @@ -17,7 +17,7 @@ def self.ministerial_role_appointments(item) end def self.topical_events(item) - topical_events = item.topical_events.map(&:content_id) + item.topical_event_documents.map(&:content_id) + topical_events = item.topical_event_documents.map(&:content_id) { topical_events: } end diff --git a/app/presenters/publishing_api/payload_builder/topical_events.rb b/app/presenters/publishing_api/payload_builder/topical_events.rb index 851e4876144..ee858aee5ea 100644 --- a/app/presenters/publishing_api/payload_builder/topical_events.rb +++ b/app/presenters/publishing_api/payload_builder/topical_events.rb @@ -7,10 +7,9 @@ module PublishingApi module PayloadBuilder class TopicalEvents def self.for(item) - legacy_topical_events = item.topical_events.pluck(:content_id) config_driven_topical_events = item.topical_event_documents.pluck(:content_id) { - topical_events: legacy_topical_events + config_driven_topical_events, + topical_events: config_driven_topical_events, } end end diff --git a/app/presenters/publishing_api/topical_event_about_page_presenter.rb b/app/presenters/publishing_api/topical_event_about_page_presenter.rb deleted file mode 100644 index a5dc9675ebe..00000000000 --- a/app/presenters/publishing_api/topical_event_about_page_presenter.rb +++ /dev/null @@ -1,59 +0,0 @@ -module PublishingApi - class TopicalEventAboutPagePresenter - include GovspeakHelper - attr_accessor :item, :update_type - - def initialize(item, update_type: nil) - self.item = item - self.update_type = update_type || "major" - end - - delegate :content_id, to: :item - - def content - content = BaseItemPresenter.new( - item, - title: item.name, - update_type:, - ).base_attributes - - content.merge!( - description: item.summary, - base_path:, - details:, - document_type: schema_name, - public_updated_at: item.updated_at, - rendering_app: Whitehall::RenderingApp::FRONTEND, - schema_name:, - ) - content.merge!(PayloadBuilder::Routes.for(base_path)) - end - - def links - { parent: [item.topical_event.content_id] } - end - - private - - def schema_name - "topical_event_about_page" - end - - def base_path - item.base_path - end - - def details - { - body:, - read_more: item.read_more_link_text, - }.tap do |details_hash| - details_hash.merge!(PayloadBuilder::Headings.for(item.body)) - end - end - - def body - govspeak_to_html(item.body) - end - end -end diff --git a/app/presenters/publishing_api/topical_event_presenter.rb b/app/presenters/publishing_api/topical_event_presenter.rb deleted file mode 100644 index baf8e051f78..00000000000 --- a/app/presenters/publishing_api/topical_event_presenter.rb +++ /dev/null @@ -1,95 +0,0 @@ -# Legacy -module PublishingApi - class TopicalEventPresenter - include GovspeakHelper - attr_accessor :item, :update_type - - def initialize(item, update_type: nil) - self.item = item - self.update_type = update_type || "major" - end - - delegate :content_id, to: :item - - def content - content = BaseItemPresenter.new( - item, - title: item.name, - update_type:, - ).base_attributes - - content.merge!( - description: item.summary, - details:, - document_type: item.class.name.underscore, - public_updated_at: item.updated_at, - rendering_app: Whitehall::RenderingApp::FRONTEND, - schema_name: "topical_event", - ) - content.merge!(PayloadBuilder::PolymorphicPath.for(item, additional_routes: %w[atom])) - end - - def links - PayloadBuilder::Links.for(item).extract([:organisations]) - end - - private - - def details - {}.tap do |details| - details[:about_page_link_text] = item.topical_event_about_page.read_more_link_text if item.topical_event_about_page && item.topical_event_about_page.read_more_link_text - details[:body] = body - details[:image] = image if item.logo && item.logo.all_asset_variants_uploaded? - details[:start_date] = item.start_date.rfc3339 if item.start_date - details[:end_date] = item.end_date.rfc3339 if item.end_date - details[:ordered_featured_documents] = ordered_featured_documents - details[:social_media_links] = social_media_links - details.merge!(PayloadBuilder::EmphasisedOrganisations.for(item)) - end - end - - def body - govspeak_to_html(item.description) - end - - def image - { - url: item.logo.url(:s300), - medium_resolution_url: item.logo.url(:s630), - high_resolution_url: item.logo.url(:s960), - alt_text: item.logo_alt_text, - } - end - - def ordered_featured_documents - item - .topical_event_featurings - .includes(:image, edition: :document) - .limit(TopicalEvent::MAX_FEATURED_DOCUMENTS) - .select { |feature| feature.image.all_asset_variants_uploaded? } - .map do |feature| - { - title: feature.title, - href: feature.url, - image: { - url: feature.image.url(:s465), - alt_text: feature.alt_text, - }, - summary: feature.summary, - public_updated_at: feature.public_timestamp, - document_type: feature.display_type, - } - end - end - - def social_media_links - item.social_media_accounts.map do |social_media_account| - { - href: social_media_account.url, - service_type: social_media_account.service_name.parameterize, - title: social_media_account.display_name, - } - end - end - end -end diff --git a/app/validators/schema_validator.rb b/app/validators/schema_validator.rb index a172ecaf651..4e6c045a7bf 100644 --- a/app/validators/schema_validator.rb +++ b/app/validators/schema_validator.rb @@ -3,7 +3,7 @@ class SchemaValidator attr_reader :errors, :schema - NON_BLOCK_CONTENT_FIELDS = %w[ministerial_role_appointments topical_events topical_event_documents world_locations lead_organisations supporting_organisations worldwide_organisations].freeze + NON_BLOCK_CONTENT_FIELDS = %w[ministerial_role_appointments topical_event_documents world_locations lead_organisations supporting_organisations worldwide_organisations].freeze def initialize(document) @document = document diff --git a/app/views/admin/editions/_topical_event_fields.html.erb b/app/views/admin/editions/_topical_event_fields.html.erb index aa40883edc4..96799ff125b 100644 --- a/app/views/admin/editions/_topical_event_fields.html.erb +++ b/app/views/admin/editions/_topical_event_fields.html.erb @@ -1,38 +1,19 @@ <% if edition.can_be_associated_with_topical_events? %>

Topical events

- <% cache_if edition.topical_event_ids.empty?, "#{taggable_topical_events_cache_digest}-design-system" do %> - <%= render "govuk_publishing_components/components/select_with_search", { - id: "edition_topical_event_ids", - name: "edition[topical_event_ids][]", - include_blank: true, - label: "Topical events", - heading_size: "m", - options: TopicalEvent.order(:name).map do |topical_event| - { - text: topical_event.name, - value: topical_event.id, - selected: edition.topical_event_ids.include?(topical_event.id), - } - end, - multiple: true, - } %> - <% end %> - <% if Flipflop.enabled?(:configurable_document_types) %> - <%= render "govuk_publishing_components/components/select_with_search", { - id: "edition_topical_event_document_ids", - name: "edition[topical_event_document_ids][]", - include_blank: true, - label: "Topical events (experimental)", - hint: "Topical events created via the documents menu will appear here", - heading_size: "m", - options: StandardEdition.where(configurable_document_type: "topical_event").order(:title).map do |topical_event| - { - text: topical_event.title, - value: topical_event.document_id, - selected: edition.topical_event_document_ids.include?(topical_event.document_id), - } - end, - multiple: true, - } %> - <% end %> + <%= render "govuk_publishing_components/components/select_with_search", { + id: "edition_topical_event_document_ids", + name: "edition[topical_event_document_ids][]", + include_blank: true, + label: "Topical events", + hint: "Topical events created via the documents menu will appear here", + heading_size: "m", + options: StandardEdition.where(configurable_document_type: "topical_event").order(:title).map do |topical_event| + { + text: topical_event.title, + value: topical_event.document_id, + selected: edition.topical_event_document_ids.include?(topical_event.document_id), + } + end, + multiple: true, + } %> <% end %> diff --git a/app/views/admin/feature_lists/_featureable_topical_events.html.erb b/app/views/admin/feature_lists/_featureable_topical_events.html.erb deleted file mode 100644 index e0270041a62..00000000000 --- a/app/views/admin/feature_lists/_featureable_topical_events.html.erb +++ /dev/null @@ -1,44 +0,0 @@ -<%= render "govuk_publishing_components/components/heading", { - text: "Feature topical events", - margin_bottom: 6, -} %> - -<% if featurable_topical_events.any? %> -

- <%= pluralize(number_with_delimiter(featurable_topical_events.count), "document") %> -

- - -<% else %> - <%= render "govuk_publishing_components/components/inset_text", { - text: "There are currently no featurable topical events.", - } %> -<% end %> diff --git a/app/views/admin/features/new.html.erb b/app/views/admin/features/new.html.erb index 4464362c9d4..c1aed2a2a9b 100644 --- a/app/views/admin/features/new.html.erb +++ b/app/views/admin/features/new.html.erb @@ -12,7 +12,6 @@
<%= form_for @feature, url: [:admin, @featurable, @feature_list, @feature], multipart: true do |form| %> <%= form.hidden_field :document_id %> - <%= form.hidden_field :topical_event_id %> <%= form.hidden_field :offsite_link_id %> diff --git a/app/views/admin/more/index.html.erb b/app/views/admin/more/index.html.erb index 398cce0ef63..30045db55fa 100644 --- a/app/views/admin/more/index.html.erb +++ b/app/views/admin/more/index.html.erb @@ -15,7 +15,6 @@ admin_people_link, admin_roles_link, admin_sitewide_settings_link, - admin_topical_events_link, admin_world_location_news_link, admin_worldwide_organisations_link, admin_republish_content_link, diff --git a/app/views/admin/offsite_links/_form.html.erb b/app/views/admin/offsite_links/_form.html.erb index 9f70795251e..0dfdb93dda1 100644 --- a/app/views/admin/offsite_links/_form.html.erb +++ b/app/views/admin/offsite_links/_form.html.erb @@ -84,10 +84,6 @@
<%= render "govuk_publishing_components/components/button", { text: "Save" } %> - <% if parent.is_a?(Organisation) || parent.is_a?(WorldLocationNews) || parent.is_a?(Edition) %> - <%= link_to "Cancel", polymorphic_path([:features, :admin, parent], anchor: "non_govuk_government_links_tab"), class: "govuk-link govuk-link--no-visited-state" %> - <% else %> - <%= link_to "Cancel", polymorphic_path([:admin, parent, :topical_event_featurings], anchor: "non_govuk_government_links_tab"), class: "govuk-link govuk-link--no-visited-state" %> - <% end %> + <%= link_to "Cancel", polymorphic_path([:features, :admin, parent], anchor: "non_govuk_government_links_tab"), class: "govuk-link govuk-link--no-visited-state" %>
<% end %> diff --git a/app/views/admin/offsite_links/confirm_destroy.html.erb b/app/views/admin/offsite_links/confirm_destroy.html.erb index 7233745ac9d..b05ec9d2fe6 100644 --- a/app/views/admin/offsite_links/confirm_destroy.html.erb +++ b/app/views/admin/offsite_links/confirm_destroy.html.erb @@ -13,11 +13,7 @@ text: "Delete", destructive: true, } %> - <% if @parent.is_a?(TopicalEvent) %> - <%= link_to("Cancel", admin_topical_event_topical_event_featurings_path(@parent) + "#non_govuk_government_links_tab", class: "govuk-link govuk-link--no-visited-state") %> - <% else %> - <%= link_to("Cancel", polymorphic_url([:features, :admin, @parent]) + "#non_govuk_government_links_tab", class: "govuk-link govuk-link--no-visited-state") %> - <% end %> + <%= link_to("Cancel", polymorphic_url([:features, :admin, @parent]) + "#non_govuk_government_links_tab", class: "govuk-link govuk-link--no-visited-state") %>
<% end %> diff --git a/app/views/admin/organisations/_form.html.erb b/app/views/admin/organisations/_form.html.erb index e267f0af943..23a7ac8996d 100644 --- a/app/views/admin/organisations/_form.html.erb +++ b/app/views/admin/organisations/_form.html.erb @@ -252,36 +252,6 @@ end, multiple: true, } %> - - <%= render "govuk_publishing_components/components/heading", { - text: "Topical events", - font_size: "m", - margin_bottom: 3, - } %> - - <% form.object.topical_event_organisations.each do |topical_event_organisation| %> - <%= hidden_field_tag "organisation[topical_event_organisations_attributes][][ordering]", topical_event_organisation.ordering %> - <%= hidden_field_tag "organisation[topical_event_organisations_attributes][][id]", topical_event_organisation.id %> - - <%= render "govuk_publishing_components/components/select_with_search", { - label: "Topical Event #{topical_event_organisation.ordering + 1}", - name: "organisation[topical_event_organisations_attributes][][topical_event_id]", - id: "organisation_topical_event_ids_#{topical_event_organisation.ordering}", - heading_size: "s", - include_blank: true, - ga_data: { - document_type: "#{action_name}-#{controller_name}", - section: "Topical Event #{topical_event_organisation.ordering + 1}", - }, - options: TopicalEvent.all.map do |topical_event| - { - text: topical_event.name, - value: topical_event.id, - selected: topical_event.id == topical_event_organisation.topical_event_id, - } - end, - } %> - <% end %> <% end %> <% if can?(:manage_featured_links, @organisation) %> diff --git a/app/views/admin/organisations/features.html.erb b/app/views/admin/organisations/features.html.erb index 6b2ea877676..a49ac48e8f0 100644 --- a/app/views/admin/organisations/features.html.erb +++ b/app/views/admin/organisations/features.html.erb @@ -49,14 +49,6 @@ feature_path: [:new, :admin, @feature_list, :feature], ), }, - { - id: "topical_events_tab", - label: "Topical events", - content: render("admin/feature_lists/featureable_topical_events", - feature_list: @feature_list, - featurable_topical_events: featurable_topical_events_for_feature_list(@featurable_topical_events, @feature_list), - ), - }, { id: "non_govuk_government_links_tab", label: "External websites", diff --git a/app/views/admin/topical_event_about_pages/_form.html.erb b/app/views/admin/topical_event_about_pages/_form.html.erb deleted file mode 100644 index 5abd4f45470..00000000000 --- a/app/views/admin/topical_event_about_pages/_form.html.erb +++ /dev/null @@ -1,54 +0,0 @@ -<%= form_with model: topical_event_about_page, url: admin_topical_event_topical_event_about_pages_path(topical_event_about_page.topical_event) do |form| %> - <%= render "govuk_publishing_components/components/input", { - label: { - text: "Name (required)", - heading_size: "l", - }, - value: topical_event_about_page.name, - name: "topical_event_about_page[name]", - id: "topical_event_about_page_name", - error_items: errors_for(topical_event_about_page.errors, :name), - } %> - <%= render "govuk_publishing_components/components/character_count", { - textarea: { - label: { - text: "Read more link text (required)", - heading_size: "l", - }, - value: topical_event_about_page.read_more_link_text, - name: "topical_event_about_page[read_more_link_text]", - error_items: errors_for(topical_event_about_page.errors, :read_more_link_text), - rows: 4, - }, - maxlength: 255, - id: "topical_event_about_page_read_more_link_text", - } %> - <%= render "govuk_publishing_components/components/textarea", { - label: { - heading_size: "l", - text: "Summary (required)", - }, - value: topical_event_about_page.summary, - heading_size: "l", - name: "topical_event_about_page[summary]", - textarea_id: "topical_event_about_page_summary", - error_items: errors_for(topical_event_about_page.errors, :summary), - } %> - <%= render "components/govspeak_editor", { - label: { - text: "Body (required)", - heading_size: "l", - }, - id: "topical_event_about_page_body", - name: "topical_event_about_page[body]", - value: topical_event_about_page.body, - rows: 20, - error_items: errors_for(topical_event_about_page.errors, :body), - } %> -
- <%= render "govuk_publishing_components/components/button", { - text: "Save", - } %> - <%= link_to("Cancel", admin_topical_event_topical_event_about_pages_path(topical_event_about_page.topical_event), class: "govuk-link") %> -
-<% end %> diff --git a/app/views/admin/topical_event_about_pages/edit.html.erb b/app/views/admin/topical_event_about_pages/edit.html.erb deleted file mode 100644 index c5271f6af42..00000000000 --- a/app/views/admin/topical_event_about_pages/edit.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% content_for :context, "#{@topical_event.name}" %> -<% content_for :page_title, "Edit about page" %> -<% content_for :title, "Edit about page" %> -<% content_for :title_margin_bottom, 6 %> -<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @topical_event_about_page)) %> -
-
- <%= render "govuk_publishing_components/components/warning_text", { - text: "Changes to topical events appear instantly on the live site.", - } %> - <%= render "form", topical_event_about_page: @topical_event_about_page %> -
-
- <%= render "govuk_publishing_components/components/tabs", { - disable_ga4: true, - tabs: [ - { - id: "govspeak_tab", - label: "Help", - content: simple_formatting_sidebar, - }, - ], - } %> -
-
diff --git a/app/views/admin/topical_event_about_pages/new.html.erb b/app/views/admin/topical_event_about_pages/new.html.erb deleted file mode 100644 index d9bdbb081f4..00000000000 --- a/app/views/admin/topical_event_about_pages/new.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% content_for :context, "#{@topical_event.name}" %> -<% content_for :page_title, "New about page" %> -<% content_for :title, "New about page" %> -<% content_for :title_margin_bottom, 6 %> -<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @topical_event_about_page)) %> -
-
- <%= render "govuk_publishing_components/components/warning_text", { - text: "Changes to topical events appear instantly on the live site.", - } %> - <%= render "form", topical_event_about_page: @topical_event_about_page %> -
-
- <%= render "govuk_publishing_components/components/tabs", { - disable_ga4: true, - tabs: [ - { - id: "govspeak_tab", - label: "Help", - content: simple_formatting_sidebar, - }, - ], - } %> -
-
diff --git a/app/views/admin/topical_event_about_pages/show.html.erb b/app/views/admin/topical_event_about_pages/show.html.erb deleted file mode 100644 index b7ed431db19..00000000000 --- a/app/views/admin/topical_event_about_pages/show.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -<% content_for :back_link do %> - <%= render "govuk_publishing_components/components/back_link", { - href: admin_topical_events_path, - } %> -<% end %> -<% content_for :context, "Topical events" %> -<% content_for :page_title, "Read more about #{@topical_event.name}" %> -<% content_for :title, @topical_event.name %> -<% content_for :title_margin_bottom, 4 %> - -

<%= view_on_website_link_for @topical_event, class: "govuk-link" %>

- -
- <%= render "components/secondary_navigation", { - aria_label: "Topical Events navigation", - items: topical_event_nav_items(@topical_event, request.path), - } %> -
-<% if @topical_event_about_page.present? %> - <%= render "govuk_publishing_components/components/summary_list", { - title: "About page", - heading_level: 2, - heading_size: "l", - items: [ - { - field: "Name", - value: @topical_event_about_page.name, - }, - { - field: "Read more link text", - value: @topical_event_about_page.read_more_link_text, - }, - { - field: "Summary", - value: @topical_event_about_page.summary, - }, - { - field: "Body", - value: govspeak_to_html(@topical_event_about_page.body), - }, - ], - edit: { - href: [:edit, :admin, @topical_event, :topical_event_about_pages], - link_text: "Edit", - }, - } %> -<% else %> - <%= render "govuk_publishing_components/components/heading", { - text: "About page", - margin_bottom: 6, - } %> - <%= render "govuk_publishing_components/components/button", { - text: "Create new about page", - href: new_admin_topical_event_topical_event_about_pages_path, - - } %> - <%= render "govuk_publishing_components/components/inset_text", { - text: "There is no about page associated with this topical event.", - } %> -<% end %> diff --git a/app/views/admin/topical_event_featurings/confirm_destroy.html.erb b/app/views/admin/topical_event_featurings/confirm_destroy.html.erb deleted file mode 100644 index 89375576bf2..00000000000 --- a/app/views/admin/topical_event_featurings/confirm_destroy.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<% content_for :context, @topical_event.name %> -<% content_for :page_title, "Unfeature ‘#{@topical_event_featuring.title}’" %> -<% content_for :title, "Unfeature ‘#{@topical_event_featuring.title}’" %> -<% content_for :title_margin_bottom, 6 %> - -
-
- <%= form_with url: admin_topical_event_topical_event_featuring_path(@topical_event, @topical_event_featuring), method: :delete do %> -

Are you sure you want to unfeature ‘<%= @topical_event_featuring.title %>’ for ‘<%= @topical_event.name %>’?

- -
- <%= render "govuk_publishing_components/components/button", { - text: "Unfeature", - destructive: true, - } %> - - <%= link_to("Cancel", admin_topical_event_topical_event_featurings_path(@topical_event), class: "govuk-link govuk-link--no-visited-state") %> -
- <% end %> -
-
diff --git a/app/views/admin/topical_event_featurings/index.html.erb b/app/views/admin/topical_event_featurings/index.html.erb deleted file mode 100644 index 8006b815556..00000000000 --- a/app/views/admin/topical_event_featurings/index.html.erb +++ /dev/null @@ -1,62 +0,0 @@ -<% content_for :back_link do %> - <%= render "govuk_publishing_components/components/back_link", { - href: admin_topical_events_path, - } %> -<% end %> -<% content_for :page_title, @topical_event.name %> -<% content_for :title, @topical_event.name %> -<% content_for :context, "Topical events" %> -<% content_for :title_margin_bottom, 4 %> - -

- <%= link_to "View on website", @topical_event.public_url({locale: params[:locale]}.merge(cachebust_url_options)), class: "govuk-link", target: "_blank", rel: "noopener" %> -

- -
- <%= render "components/secondary_navigation", { - aria_label: "Document navigation", - items: secondary_navigation_tabs_items(@topical_event, request.path), - } %> -
- -<%= render "govuk_publishing_components/components/heading", { - text: "Featured", - font_size: "l", - margin_bottom: 6, -} %> - -<%= render "govuk_publishing_components/components/tabs", { - disable_ga4: true, - tabs: [ - { - id: "currently_featured_tab", - label: "Currently featured", - content: render(Admin::CurrentlyFeaturedTabComponent.new( - featurings: @topical_event_featurings, - maximum_featured_documents: TopicalEvent::MAX_FEATURED_DOCUMENTS, - )), - }, - { - id: "documents_tab", - label: "GOV.UK content", - content: render("admin/shared/featurable_editions", - filter: @filter, - paginator: @tagged_editions, - featurable_editions: @topical_event.featurable_editions(@tagged_editions), - filter_by: [:title, :type, :author, :organisation], - anchor: "#documents_tab", - filter_action: admin_topical_event_topical_event_featurings_url(@topical_event), - feature_path: [:new, :admin, @topical_event, :topical_event_featuring], - ), - }, - { - id: "non_govuk_government_links_tab", - label: "External websites", - content: render("admin/feature_lists/featureable_offsite_links", - model: @topical_event, - featurable_offsite_links: @topical_event.featurable_offsite_links, - featuring_path: [:new, :admin, @topical_event, :topical_event_featuring], - ), - }, - ], -} %> diff --git a/app/views/admin/topical_event_featurings/new.html.erb b/app/views/admin/topical_event_featurings/new.html.erb deleted file mode 100644 index e7d8be4c16d..00000000000 --- a/app/views/admin/topical_event_featurings/new.html.erb +++ /dev/null @@ -1,56 +0,0 @@ -<% content_for :page_title, "Feature document" %> -<% content_for :title do %> - <% if featuring_a_document? %> - Feature ‘<%= @topical_event_featuring.edition.title %>’ within ‘<%= @topical_event.name %>’ - <% else %> - Feature ‘<%= @topical_event_featuring.offsite_link.title %>’ within ‘<%= @topical_event.name %>’ - <% end %> -<% end %> -<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @topical_event_featuring)) %> - -
-
- <%= form_for @topical_event_featuring, url: [:admin, @topical_event, @topical_event_featuring], multipart: true do |form| %> - <% if featuring_a_document? %> - <%= form.hidden_field :edition_id %> - <% else %> - <%= form.hidden_field :offsite_link_id %> - <% end %> - - <%= render "govuk_publishing_components/components/file_upload", { - label: { - text: "Image (required)", - heading_size: "l", - }, - hint: "Select a 960px wide and 640px tall image to be shown when featuring", - name: "topical_event_featuring[image_attributes][file]", - id: "topical_event_featuring_image_file", - error_items: errors_for(@topical_event_featuring.errors, :"image.file"), - } %> - - <%= render "govuk_publishing_components/components/input", { - label: { - text: "Image description (alt text)", - }, - heading_size: "l", - name: "topical_event_featuring[alt_text]", - id: "topical_event_featuring_alt_text", - value: @topical_event_featuring.alt_text, - error_message: errors_for_input(@topical_event_featuring.errors, :alt_text), - } %> - -
- <%= render "govuk_publishing_components/components/button", { - text: "Save", - } %> - <%= link_to "Cancel", - polymorphic_path( - [:admin, @topical_event, :topical_event_featurings], - anchor: featuring_a_document? ? "documents_tab" : "non_govuk_government_links_tab", - reload: true, - ), - class:"govuk-link govuk-link--no-visited-state" %> -
- <% end %> -
-
diff --git a/app/views/admin/topical_event_featurings/reorder.html.erb b/app/views/admin/topical_event_featurings/reorder.html.erb deleted file mode 100644 index 5d89560770c..00000000000 --- a/app/views/admin/topical_event_featurings/reorder.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<% content_for :context, "Currently featured documents" %> -<% content_for :page_title, "Reorder list" %> -<% content_for :title, "Reorder list" %> -<% content_for :title_margin_bottom, 6 %> - -
-
- <%= form_with url: order_admin_topical_event_topical_event_featurings_path(@topical_event), method: :put do %> - <%= render "govuk_publishing_components/components/hint", { - text: "Use the up and down buttons to reorder pages, or select and hold on a page to reorder using drag and drop.", - margin_bottom: 4, - } %> - - <%= render "govuk_publishing_components/components/reorderable_list", { - input_name: "topical_event_featurings[ordering]", - items: @topical_event.topical_event_featurings.map do |featuring| - { - id: featuring.id, - title: featuring.title, - description: featuring_published_on(featuring).present? ? "Published: #{featuring_published_on(featuring)}" : nil, - } - end, - } %> - -
- <%= render "govuk_publishing_components/components/button", { - text: "Update order", - } %> - - <%= link_to("Cancel", admin_topical_event_topical_event_featurings_path(@topical_event), class: "govuk-link govuk-link--no-visited-state") %> -
- <% end %> -
-
diff --git a/app/views/admin/topical_event_organisations/_organisations_table.html.erb b/app/views/admin/topical_event_organisations/_organisations_table.html.erb deleted file mode 100644 index 29c58e604bf..00000000000 --- a/app/views/admin/topical_event_organisations/_organisations_table.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -
"> -
-
- <%= lead ? "Lead organisations" : "Supporting organisations" %> -
- <% if lead && @topical_event.lead_topical_event_organisations.many? %> -
- <%= link_to "Reorder organisations", reorder_admin_topical_event_topical_event_organisations_path(@topical_event), class: "govuk-link" %> -
- <% end %> -
-
- <%= render "govuk_publishing_components/components/table", { - first_cell_is_header: true, - rows: @topical_event.topical_event_organisations.where(lead: lead).order(lead ? :lead_ordering : :ordering).map do |topical_event_organisation| - [{ - text: topical_event_organisation.organisation.name, - }, - { - text: link_to(sanitize("View #{tag.span(topical_event_organisation.organisation.name, class: "govuk-visually-hidden")}"), [:admin, topical_event_organisation.organisation], class: "govuk-link") + - link_to(sanitize((lead ? "Make supporting " : "Make lead ") + tag.span(topical_event_organisation.organisation.name, class: "govuk-visually-hidden")), toggle_lead_admin_topical_event_topical_event_organisation_path(@topical_event, topical_event_organisation), class: "govuk-link govuk-!-margin-left-2"), - }, - ] - end, - } %> -
-
diff --git a/app/views/admin/topical_event_organisations/index.html.erb b/app/views/admin/topical_event_organisations/index.html.erb deleted file mode 100644 index 5fce52dce0c..00000000000 --- a/app/views/admin/topical_event_organisations/index.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -<% content_for :back_link do %> - <%= render "govuk_publishing_components/components/back_link", { - href: admin_topical_events_path, - } %> -<% end %> -<% content_for :page_title, @topical_event.name %> -<% content_for :title, @topical_event.name %> -<% content_for :context, "Topical events" %> -<% content_for :title_margin_bottom, 4 %> - -

<%= view_on_website_link_for @topical_event, class: "govuk-link" %>

- -
- <%= render "components/secondary_navigation", { - aria_label: "Topical Event navigation", - items: secondary_navigation_tabs_items(@topical_event, request.path), - } %> -
- -<%= render "govuk_publishing_components/components/heading", { - text: "Organisations", - heading_level: 2, - font_size: "l", - margin_bottom: @topical_event.topical_event_organisations.any? ? 6 : 0, -} %> - -
-
- <% if @topical_event.lead_topical_event_organisations.any? %> - <%= render "organisations_table", lead: true %> - <% end %> - <% if @topical_event.topical_event_organisations.where(lead: false).any? %> - <%= render "organisations_table", lead: false %> - <% end %> - <% if @topical_event.topical_event_organisations.none? %> - <%= render "govuk_publishing_components/components/inset_text", { - text: "There are no organisations associated with this topical event.", - } %> - <% end %> -
-
diff --git a/app/views/admin/topical_event_organisations/reorder.html.erb b/app/views/admin/topical_event_organisations/reorder.html.erb deleted file mode 100644 index 38ec17dfeb7..00000000000 --- a/app/views/admin/topical_event_organisations/reorder.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -<% content_for :page_title, "Reorder lead organisations list" %> -<% content_for :title, "Reorder lead organisations list" %> -<% content_for :context, @topical_event.name %> -<% content_for :title_margin_bottom, 4 %> - -
-
- <%= form_with url: order_admin_topical_event_topical_event_organisations_path(@topical_event), method: :put do %> - <%= render "govuk_publishing_components/components/hint", { - text: "Use the up and down buttons to reorder pages, or select and hold on a page to reorder using drag and drop.", - margin_bottom: 4, - } %> - - <%= hidden_field_tag "lead", params[:lead] %> - - <%= render "govuk_publishing_components/components/reorderable_list", { - input_name: "topical_event_lead_organisations[ordering]", - items: @topical_event.topical_event_organisations.where(lead: true).order(:lead_ordering).map do |topical_event_organisation| - { - id: topical_event_organisation.id, - title: topical_event_organisation.organisation.name, - value: topical_event_organisation.ordering, - } - end, - } %> - -
- <%= render "govuk_publishing_components/components/button", { - text: "Update order", - } %> - - <%= link_to("Cancel", admin_topical_event_topical_event_organisations_path(@topical_event), class: "govuk-link govuk-link--no-visited-state") %> -
- <% end %> -
-
diff --git a/app/views/admin/topical_events/_form.html.erb b/app/views/admin/topical_events/_form.html.erb deleted file mode 100644 index 26e386e0017..00000000000 --- a/app/views/admin/topical_events/_form.html.erb +++ /dev/null @@ -1,172 +0,0 @@ -<%= form_with model: topical_event, url: [:admin, topical_event], multipart: true do |form| %> - <%= render "govuk_publishing_components/components/input", { - label: { - text: "Name (required)", - heading_size: "l", - }, - value: topical_event.name, - name: "topical_event[name]", - id: "topical_event_name", - error_items: errors_for(topical_event.errors, :name), - } %> - - <%= render "govuk_publishing_components/components/character_count", { - textarea: { - label: { - text: "Summary (required)", - heading_size: "l", - }, - value: topical_event.summary, - name: "topical_event[summary]", - rows: 4, - error_items: errors_for(topical_event.errors, :summary), - }, - maxlength: MaxLengths::SUMMARY, - id: "topical_event_summary", - } %> - - <%= render "components/govspeak_editor", { - label: { - heading_size: "l", - text: "Description (required)", - }, - value: topical_event.description, - heading_size: "l", - name: "topical_event[description]", - id: "topical_event_description", - rows: 20, - error_items: errors_for(topical_event.errors, :description), - margin_bottom: 8, - } %> - -
- <%= form.fields_for :logo do |_image_fields| %> - <%= render "components/single_image_upload", { - title: "Logo", - name: "topical_event[logo_attributes]", - image_id: "topical_event_logo_file", - image_name: "topical_event[logo_attributes][file]", - alt_text_name: "topical_event[logo_alt_text]", - alt_text_id: "topical_event_logo_alt_text", - filename: topical_event.logo.filename, - page_errors: topical_event.errors.any?, - error_items: errors_for(topical_event.errors, :"logo.file"), - image_src: topical_event.logo.url, - image_alt: topical_event.logo_alt_text, - image_cache_name: "topical_event[logo_attributes][file_cache]", - image_cache: topical_event.logo.file_cache.presence, - image_uploaded: topical_event.logo.all_asset_variants_uploaded?, - } %> - <% end %> -
- -
- <%= render "govuk_publishing_components/components/fieldset", { - legend_text: "Duration", - heading_size: "l", - margin_bottom: 2, - } do %> - <%= render "components/datetime_fields", { - ga4_section: "Duration", - date_only: true, - prefix: "topical_event", - field_name: "start_date", - id: "topical_event_start_date", - heading_size: "m", - date_hint: "For example, 01 08 2015", - date_heading: "Start date", - margin_bottom: 2, - year: { - id: "topical_event_start_date(1i)", - name: "topical_event[start_date(1i)]", - value: params.dig("topical_event", "start_date(1i)") || topical_event.start_date&.year, - label: "Year", - width: 4, - }, - month: { - id: "topical_event_start_date(2i)", - name: "topical_event[start_date(2i)]", - value: params.dig("topical_event", "start_date(2i)") || topical_event.start_date&.month, - label: "Month", - width: 2, - }, - day: { - id: "topical_event_start_date(3i)", - name: "topical_event[start_date(3i)]", - value: params.dig("topical_event", "start_date(3i)") || topical_event.start_date&.day, - label: "Day", - width: 2, - }, - error_items: errors_for(topical_event.errors, :start_date), - } %> - - <%= render "components/datetime_fields", { - ga4_section: "Duration", - date_only: true, - prefix: "topical_event", - field_name: "end_date", - id: "topical_event_end_date", - heading_size: "m", - date_hint: "For example, 01 08 2022", - date_heading: "End date", - year: { - id: "topical_event_end_date(1i)", - name: "topical_event[end_date(1i)]", - value: params.dig("topical_event", "end_date(1i)") || topical_event.end_date&.year, - label: "Year", - width: 4, - }, - month: { - id: "topical_event_end_date(2i)", - name: "topical_event[end_date(2i)]", - value: params.dig("topical_event", "end_date(2i)") || topical_event.end_date&.month, - label: "Month", - width: 2, - }, - day: { - id: "topical_event_end_date(3i)", - name: "topical_event[end_date(3i)]", - value: params.dig("topical_event", "end_date(3i)") || topical_event.end_date&.day, - label: "Day", - width: 2, - }, - error_items: errors_for(topical_event.errors, :end_date), - } %> - <% end %> -
- - <%= render "govuk_publishing_components/components/fieldset", { - legend_text: "Social media accounts", - heading_size: "l", - data_attributes: { - ga4_section: "Social media accounts", - }, - } do %> - <%= render "govuk_publishing_components/components/add_another", { - fieldset_legend: "Account", - add_button_text: "Add account", - items: form.object.social_media_accounts.each_with_index.map do |social_media_account, index| - { - fields: render(partial: "admin/topical_events/social_media_account_fields", locals: { form:, social_media_account:, index: }), - destroy_checkbox: render("govuk_publishing_components/components/checkboxes", { name: "topical_event[social_media_accounts_attributes][#{index}][_destroy]", items: [{label: "Delete", value: "1" }]}), - } - end, - empty: render(partial: "admin/topical_events/social_media_account_fields", locals: { form:, social_media_account: SocialMediaAccount.new, index: form.object.social_media_accounts.length }), - data_attributes: { - ga4_start_index: 0, - }, - } %> - <% end %> - -
- <%= render "govuk_publishing_components/components/button", { - text: "Save", - } %> - - <% if @topical_event.persisted? %> - <%= link_to("Cancel", admin_topical_event_path(@topical_event), class: "govuk-link") %> - <% else %> - <%= link_to("Cancel", admin_topical_events_path, class: "govuk-link") %> - <% end %> -
-<% end %> diff --git a/app/views/admin/topical_events/_social_media_account_fields.html.erb b/app/views/admin/topical_events/_social_media_account_fields.html.erb deleted file mode 100644 index ec285fcb628..00000000000 --- a/app/views/admin/topical_events/_social_media_account_fields.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<%= form.fields_for :social_media_accounts, social_media_account do |social_media_form| %> - <%= render "govuk_publishing_components/components/select", { - id: "topical_event_social_media_accounts_attributes_#{index}_social_media_service_id", - label: "Service (required)", - name: "topical_event[social_media_accounts_attributes][#{index}][social_media_service_id]", - heading_size: "s", - options: [{ text: "", value: "" }] + - SocialMediaService.all.map do |social_media| - { - text: social_media.name, - value: social_media.id, - selected: social_media_form.object.social_media_service_id == social_media.id, - } - end, - full_width: true, - } %> - <%= render "govuk_publishing_components/components/input", { - label: { - text: "URL (required)", - }, - name: "topical_event[social_media_accounts_attributes][#{index}][url]", - id: "topical_event_social_media_accounts_attributes_#{index}_url", - value: social_media_form.object.url, - heading_size: "s", - error_items: errors_for(social_media_form.object.errors, :url), - } %> -<% end %> diff --git a/app/views/admin/topical_events/confirm_destroy.html.erb b/app/views/admin/topical_events/confirm_destroy.html.erb deleted file mode 100644 index 5da8c09975e..00000000000 --- a/app/views/admin/topical_events/confirm_destroy.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<% content_for :context, @topical_event.name %> -<% content_for :page_title, "Delete topical event" %> -<% content_for :title, "Delete topical event" %> -<% content_for :title_margin_bottom, 6 %> - -
-
- <%= form_tag admin_topical_event_path(@topical_event), method: :delete do %> -

Are you sure you want to delete "<%= @topical_event.name %>"?

- -
- <%= render "govuk_publishing_components/components/button", { - text: "Delete", - destructive: true, - } %> - - <%= link_to("Cancel", admin_topical_events_path, class: "govuk-link govuk-link--no-visited-state") %> -
- <% end %> -
-
diff --git a/app/views/admin/topical_events/edit.html.erb b/app/views/admin/topical_events/edit.html.erb deleted file mode 100644 index 9c07bfda5d8..00000000000 --- a/app/views/admin/topical_events/edit.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% content_for :context, "Topical events" %> -<% content_for :page_title, @topical_event.name %> -<% content_for :title, @topical_event.name %> -<% content_for :title_margin_bottom, 6 %> -<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @topical_event)) %> - -
-
- <%= render "govuk_publishing_components/components/warning_text", { - text: "Changes to topical events appear instantly on the live site.", - margin_bottom: 6, - } %> - <%= render "form", topical_event: @topical_event %> -
-
diff --git a/app/views/admin/topical_events/index.html.erb b/app/views/admin/topical_events/index.html.erb deleted file mode 100644 index a25b72feda2..00000000000 --- a/app/views/admin/topical_events/index.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -<% content_for :page_title, "Topical events" %> -<% content_for :title, "Topical events" %> -<% content_for :title_margin_bottom, 4 %> - -<%= render "govuk_publishing_components/components/warning_text", { - text: "Do not create topical events without consulting GDS. New documents will be live immediately on selecting save.", -} %> - -<%= render "govuk_publishing_components/components/button", { - text: "Create topical event", - href: [:new, :admin, :topical_event], - margin_bottom: 8, -} %> -
- <%= render "govuk_publishing_components/components/table", { - filterable: true, - label: "Filter topical events", - head: [ - { - text: "Name", - }, - { - text: "Summary", - }, - - { - text: "Duration", - }, - { - text: "Published guides", - }, - { - text: tag.span("Actions", class: "govuk-visually-hidden"), - }, - ], - rows: @topical_events.map do |event| - [ - { - text: tag.p(event.name, class: "govuk-!-font-weight-bold govuk-!-margin-0"), - }, - { - text: truncate(event.summary, length: 130, separator: " "), - }, - - { - text: duration_row_value(event), - }, - - { - text: event.published_detailed_guides.count, - }, - - { - text: link_to(sanitize("View #{tag.span(event.name, class: 'govuk-visually-hidden')}"), [:admin, event], class: "govuk-link") + - tag.span(link_to(sanitize("Delete #{tag.span(event.name, class: 'govuk-visually-hidden')}"), confirm_destroy_admin_topical_event_path(event),class: "govuk-link govuk-!-margin-left-2 gem-link--destructive")), - }, - ] - end, - } %> -
diff --git a/app/views/admin/topical_events/new.html.erb b/app/views/admin/topical_events/new.html.erb deleted file mode 100644 index 0b374932cfd..00000000000 --- a/app/views/admin/topical_events/new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% content_for :context, "Topical events" %> -<% content_for :page_title, "New topical event" %> -<% content_for :title, "New topical event" %> -<% content_for :title_margin_bottom, 6 %> -<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @topical_event)) %> - -
-
- <%= render "govuk_publishing_components/components/warning_text", { - text: "Changes to topical events appear instantly on the live site.", - margin_bottom: 6, - } %> - <%= render "form", topical_event: @topical_event %> -
-
diff --git a/app/views/admin/topical_events/show.html.erb b/app/views/admin/topical_events/show.html.erb deleted file mode 100644 index 1c7310cf71c..00000000000 --- a/app/views/admin/topical_events/show.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<% content_for :back_link do %> - <%= render "govuk_publishing_components/components/back_link", { - href: admin_topical_events_path, - } %> -<% end %> -<% content_for :context, "Topical events" %> -<% content_for :page_title, @topical_event.name %> -<% content_for :title, @topical_event.name %> -<% content_for :title_margin_bottom, 4 %> - -

<%= view_on_website_link_for @topical_event, class: "govuk-link" %>

- -
- <%= render "components/secondary_navigation", { - aria_label: "Topical Events navigation", - items: topical_event_nav_items(@topical_event, request.path), - } %> -
- -<%= render "govuk_publishing_components/components/summary_list", { - title: "Details", - heading_level: 2, - heading_size: "l", - items: [ - { field: "Summary", value: @topical_event.summary }, - { field: "Description", value: govspeak_to_html(@topical_event.description) }, - { field: "Details", value: topical_event_contents_breakdown(@topical_event) }, - { field: "Duration", - value: ("#{@topical_event.start_date} to #{@topical_event.end_date}" if @topical_event.start_date && @topical_event.end_date), - }, - ], - edit: { - href: [:edit, :admin, @topical_event], - link_text: "Edit", - link_text_no_enhance: true, - }, -} %> diff --git a/app/views/admin/world_location_news/features.html.erb b/app/views/admin/world_location_news/features.html.erb index 28f81a130d9..6d5a6419338 100644 --- a/app/views/admin/world_location_news/features.html.erb +++ b/app/views/admin/world_location_news/features.html.erb @@ -49,14 +49,6 @@ feature_path: [:new, :admin, @feature_list, :feature], ), }, - { - id: "topical_events_tab", - label: "Topical events", - content: render("admin/feature_lists/featureable_topical_events", - feature_list: @feature_list, - featurable_topical_events: featurable_topical_events_for_feature_list(@featurable_topical_events, @feature_list), - ), - }, { id: "non_govuk_government_links_tab", label: "External websites", diff --git a/config/brakeman.ignore b/config/brakeman.ignore index ff21d13cd5c..0f5896450be 100644 --- a/config/brakeman.ignore +++ b/config/brakeman.ignore @@ -80,40 +80,6 @@ ], "note": "" }, - { - "warning_type": "Cross-Site Scripting", - "warning_code": 4, - "fingerprint": "350182256fb694cc2d01dd7ef57fb80d62ed9a456d33d673eed24b02739f4b56", - "check_name": "LinkToHref", - "message": "Potentially unsafe model attribute in `link_to` href", - "file": "app/views/admin/topical_event_featurings/index.html.erb", - "line": 12, - "link": "https://brakemanscanner.org/docs/warning_types/link_to_href", - "code": "link_to(\"View on website\", TopicalEvent.find(params[:topical_event_id]).public_url({ :locale => params[:locale] }.merge(cachebust_url_options)), :class => \"govuk-link\", :target => \"_blank\", :rel => \"noopener\")", - "render_path": [ - { - "type": "controller", - "class": "Admin::TopicalEventFeaturingsController", - "method": "index", - "line": 21, - "file": "app/controllers/admin/topical_event_featurings_controller.rb", - "rendered": { - "name": "admin/topical_event_featurings/index", - "file": "app/views/admin/topical_event_featurings/index.html.erb" - } - } - ], - "location": { - "type": "template", - "template": "admin/topical_event_featurings/index" - }, - "user_input": "TopicalEvent.find(params[:topical_event_id]).public_url({ :locale => params[:locale] }.merge(cachebust_url_options))", - "confidence": "Weak", - "cwe_id": [ - 79 - ], - "note": "" - }, { "warning_type": "Cross-Site Scripting", "warning_code": 4, diff --git a/config/routes.rb b/config/routes.rb index 09ac0d71f60..e944cb32303 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -186,24 +186,6 @@ def redirect(path, options = { prefix: Whitehall.router_prefix }) end resources :operational_fields, except: [:show] - resources :topical_events, path: "topical-events" do - resource :topical_event_about_pages, path: "about" - resources :topical_event_featurings, path: "featurings" do - get :reorder, on: :collection - put :order, on: :collection - get :confirm_destroy, on: :member - end - resources :topical_event_organisations, path: "organisations" do - get :reorder, on: :collection - put :order, on: :collection - get :toggle_lead, on: :member - end - resources :offsite_links do - get :confirm_destroy, on: :member - end - get :confirm_destroy, on: :member - end - resources :editions, only: [:index], concerns: %i[attachable attachable_with_html attachable_with_external] do resource :tags, only: %i[edit update], controller: :edition_tags resource :legacy_associations, only: %i[edit update], controller: :edition_legacy_associations diff --git a/features/organisations.feature b/features/organisations.feature index c3c8db56a13..a22cc0db19b 100644 --- a/features/organisations.feature +++ b/features/organisations.feature @@ -27,13 +27,6 @@ Feature: Administering Organisations When I add the offsite link "Offsite Thing" of type "Alert" to the organisation "Ministry of Pop" Then I should see the edit offsite link "Offsite Thing" on the "Ministry of Pop" organisation page - # Delete when we've migrated legacy topical events - Scenario: Featuring a (legacy) topical event for an organisation - When an active topical event called "Super topical" exists - And I visit the the organisation feature page for "Ministry of Pop" - And I feature "Super topical" - Then I see that "Super topical" has been featured - Scenario: Featuring a config-driven document on an organisation When a config-driven document called "Super topical" exists And I visit the the organisation feature page for "Ministry of Pop" diff --git a/features/step_definitions/organisation_steps.rb b/features/step_definitions/organisation_steps.rb index b1cceae8049..d6880c211ad 100644 --- a/features/step_definitions/organisation_steps.rb +++ b/features/step_definitions/organisation_steps.rb @@ -233,10 +233,6 @@ def navigate_to_organisation(page_name) end end -Given(/^an active topical event called "([^"]*)" exists$/) do |name| - create(:topical_event, :active, name:) -end - Given(/^a config-driven document called "([^"]*)" exists$/) do |name| create(:published_standard_edition, configurable_document_type: "test_type", title: name, lead_organisations: [@organisation]) end diff --git a/features/step_definitions/topical_event_featurings_steps.rb b/features/step_definitions/topical_event_featurings_steps.rb deleted file mode 100644 index e7b2b45ba28..00000000000 --- a/features/step_definitions/topical_event_featurings_steps.rb +++ /dev/null @@ -1,40 +0,0 @@ -Given(/^the topical event has an offsite link with the title "([^"]*)"$/) do |title| - create(:offsite_link, topical_events: [@topical_event], title:) -end - -When(/^I visit the topical event featuring index page$/) do - visit admin_topical_event_topical_event_featurings_path(@topical_event) -end - -Given(/^the topical event has an edition with the title "([^"]*)"$/) do |title| - edition = create(:publication, :published, title:) - create(:topical_event_membership, edition:, topical_event: @topical_event) -end - -And(/^two featurings exist for "([^"]*)"$/) do |name| - topical_event = TopicalEvent.find_by(name:) - offsite_link1 = create(:offsite_link, topical_events: [topical_event], title: "Featured link 1") - offsite_link2 = create(:offsite_link, topical_events: [topical_event], title: "Featured link 2") - create(:offsite_topical_event_featuring, topical_event:, offsite_link: offsite_link1) - create(:offsite_topical_event_featuring, topical_event:, offsite_link: offsite_link2) -end - -And(/^I set the order of the topical event featurings to:$/) do |featurings_order| - click_link "Reorder pages" - - featurings_order.hashes.each do |hash| - featuring = @topical_event.topical_event_featurings.select { |f| f.title == hash[:title] }.first - fill_in "topical_event_featurings[ordering][#{featuring.id}]", with: hash[:order] - end - - click_button "Update order" -end - -Then(/^the topical event featurings should be in the following order:$/) do |featurings_titles| - featuring_titles = all("table td:first").map(&:text) - - featurings_titles.hashes.each_with_index do |hash, index| - featuring = @topical_event.topical_event_featurings.select { |f| f.title == hash[:title] }.first - expect(featuring.title).to eq(featuring_titles[index]) - end -end diff --git a/features/step_definitions/topical_event_organisations_steps.rb b/features/step_definitions/topical_event_organisations_steps.rb deleted file mode 100644 index 5f26f98c3e1..00000000000 --- a/features/step_definitions/topical_event_organisations_steps.rb +++ /dev/null @@ -1,47 +0,0 @@ -And(/^the topical event has a (lead|supporting) organisation called "([^"]*)"$/) do |organisation_type, name| - organisation = create(:organisation, name:) - @topical_event_organisation = create(:topical_event_organisation, organisation:, topical_event: @topical_event, lead: organisation_type == "lead") -end - -When(/^I visit the topical event organisations index page$/) do - visit admin_topical_event_topical_event_organisations_path(@topical_event) -end - -Then(/^I can see the (lead|supporting) organisation with the name "([^"]*)"$/) do |organisation_type, name| - within "##{organisation_type}_organisations" do - organisations = all("table th").map(&:text) - expect(organisations).to include name - end -end - -And(/^I set the order of lead organisations to:$/) do |organisations_order| - within "#lead_organisations" do - click_link "Reorder organisations" - end - - organisations_order.hashes.each do |hash| - topical_event_organisation = @topical_event.topical_event_organisations.where(lead: true).select { |f| f.organisation.name == hash[:name] }.first - fill_in "topical_event_lead_organisations[ordering][#{topical_event_organisation.id}]", with: hash[:order] - end - - click_button "Update order" -end - -Then(/^the lead organisations should be in the following order:$/) do |expected_organisations_order| - within "#lead_organisations" do - actual_organisations_order = all("table th").map(&:text) - - expected_organisations_order.hashes.each_with_index do |hash, index| - topical_event_organisation = @topical_event.topical_event_organisations.where(lead: true).select { |f| f.organisation.name == hash[:name] }.first - expect(topical_event_organisation.organisation.name).to eq(actual_organisations_order[index]) - end - end -end - -And(/^I make "([^"]*)" a (lead|supporting) organisation$/) do |name, organisation_type| - click_link "Make #{organisation_type} #{name}" -end - -Then(/^I can see a "([^"]*)" success notice$/) do |message| - expect(find(".govuk-notification-banner__heading").text).to eq message -end diff --git a/features/step_definitions/topical_event_steps.rb b/features/step_definitions/topical_event_steps.rb deleted file mode 100644 index 4760807340d..00000000000 --- a/features/step_definitions/topical_event_steps.rb +++ /dev/null @@ -1,51 +0,0 @@ -And(/^a topical event called "([^"]*)" exists$/) do |name| - @topical_event = create(:topical_event, name:) -end - -Given(/^a topical event called "(.*?)" with summary "([^"]*)" and description "(.*?)"$/) do |name, summary, description| - @topical_event = create(:topical_event, name:, summary:, description:) - stub_topical_event_in_content_store(name) -end - -When(/^I create a new topical event "([^"]*)" with summary "([^"]*)" and description "([^"]*)"$/) do |name, summary, description| - create_topical_event_and_stub_in_content_store(name:, summary:, description:) -end - -Then(/^I should see the topical event "([^"]*)" in the admin interface$/) do |topical_event_name| - topical_event = TopicalEvent.find_by!(name: topical_event_name) - visit admin_topical_events_path(topical_event) - expect(page).to have_selector(".govuk-table__cell", text: topical_event) -end - -Given(/^I'm administering a topical event$/) do - event = create(:topical_event, name: "Name of event") - stub_topical_event_in_content_store("Name of event") - visit admin_topical_event_path(event) -end - -When(/^I add a page of information about the event$/) do - click_link "About page" - click_link "Create new about page" - fill_in "Name", with: "Page about the event" - fill_in "Read more link text", with: "Read more about this event" - fill_in "Summary", with: "Summary" - fill_in "Body", with: "Body" - click_button "Save" -end - -Then(/^I should be able to edit the event's about page$/) do - click_link "Edit" - fill_in "Name", with: "About the event" - click_button "Save" -end - -Then(/^I should see the about page is updated$/) do - expect(page).to have_text("About page saved") -end - -Then(/^I should be able to delete the topical event "([^"]*)"$/) do |name| - visit admin_topical_events_path - click_link "Delete #{name}" - - expect { click_button "Delete" }.to change(TopicalEvent, :count).by(-1) -end diff --git a/features/step_definitions/world_location_news_steps.rb b/features/step_definitions/world_location_news_steps.rb index 4561e11f047..fcc254d6aad 100644 --- a/features/step_definitions/world_location_news_steps.rb +++ b/features/step_definitions/world_location_news_steps.rb @@ -107,10 +107,6 @@ expect(first_search_result).to have_content(document_title) end -Given(/^there is an active topical event with the name "([^"]*)"$/) do |name| - create(:topical_event, :active, name:) -end - And(/^filter documents by all organisations$/) do select "All locations" click_button "Search" diff --git a/features/support/topical_events_helper.rb b/features/support/topical_events_helper.rb deleted file mode 100644 index 0119484e78f..00000000000 --- a/features/support/topical_events_helper.rb +++ /dev/null @@ -1,39 +0,0 @@ -ParameterType( - name: "topical_event_section", - regexp: /the (announcements|publications|consultations) section/, - transformer: ->(section) { section }, -) -module TopicalEventsHelper - def create_topical_event_and_stub_in_content_store(options = {}) - visit admin_root_path - click_link "More" - click_link "Topical events" - click_link "Create topical event" - fill_in "Name", with: options[:name] || "topic-name" - fill_in "Description", with: options[:description] || "topic-description" - fill_in "Summary", with: options[:description] || "topic-summary" - within "#topical_event_start_date" do - fill_in_date_fields(options[:start_date] || 1.day.ago.to_s) - end - within "#topical_event_end_date" do - fill_in_date_fields(options[:end_date] || 1.month.from_now.to_s) - end - - click_button "Save" - - stub_topical_event_in_content_store(options[:name]) - end - - def stub_topical_event_in_content_store(name) - content_item = { - format: "topical_event", - title: name, - } - - base_path = TopicalEvent.find_by!(name:).base_path - - stub_content_store_has_item(base_path, content_item) - end -end - -World(TopicalEventsHelper) diff --git a/features/topical_event_featurings.feature b/features/topical_event_featurings.feature deleted file mode 100644 index 95afc166f82..00000000000 --- a/features/topical_event_featurings.feature +++ /dev/null @@ -1,49 +0,0 @@ -Feature: - As an Editor. - I want to be able to create and manage topical_event_featurings. - So that I can link users to relevant documents and links. - - Background: - Given I am a GDS admin - And a topical event called "Really topical" exists - - Scenario: Creating a non-GOV.UK link - When I visit the topical event featuring index page - And I create a new a non-GOV.UK link with the title "Featured link" - Then I can see the non-GOV.UK link with the title "Featured link" - - Scenario: Editing a non-GOV.UK link - Given the topical event has an offsite link with the title "Featured link" - When I visit the topical event featuring index page - And I update the title of a featured link from "Featured link" to "New title" - Then I can see the non-GOV.UK link with the title "New title" - - Scenario: Deleting a non-GOV.UK link - Given the topical event has an offsite link with the title "Featured link" - When I visit the topical event featuring index page - And I delete "Featured link" - Then I can see that "Featured link" has been deleted - - Scenario: Featuring a non-GOV.UK link - Given the topical event has an offsite link with the title "Featured link" - When I visit the topical event featuring index page - And I feature "Featured link" - Then I see that "Featured link" has been featured - - Scenario: Featuring an edition - Given the topical event has an edition with the title "Featured edition" - When I visit the topical event featuring index page - And I feature "Featured edition" - Then I see that "Featured edition" has been featured - - Scenario: Reordering currently featured documents - Given two featurings exist for "Really topical" - When I visit the topical event featuring index page - And I set the order of the topical event featurings to: - | title | order | - | Featured link 2 | 0 | - | Featured link 1 | 1 | - Then the topical event featurings should be in the following order: - | title | - | Featured link 2 | - | Featured link 1 | diff --git a/features/topical_event_organisations.feature b/features/topical_event_organisations.feature deleted file mode 100644 index 133bf58a91e..00000000000 --- a/features/topical_event_organisations.feature +++ /dev/null @@ -1,40 +0,0 @@ -Feature: - As an Editor. - I want to be able to view and manage topical_event_organisations. - So that I can order organisations and designate as lead or supporting. - - Background: - Given I am a GDS admin - And a topical event called "Really topical" exists - And the topical event has a lead organisation called "Lead organisation" - And the topical event has a supporting organisation called "Supporting organisation" - - Scenario: View topical event organisations - When I visit the topical event organisations index page - Then I can see the lead organisation with the name "Lead organisation" - And I can see the supporting organisation with the name "Supporting organisation" - - Scenario: Reorder lead organisations - Given the topical event has a lead organisation called "Another lead organisation" - When I visit the topical event organisations index page - And I set the order of lead organisations to: - | name | order | - | Lead organisation | 1 | - | Another lead organisation | 0 | - Then I can see a "Lead organisations have been reordered." success notice - And the lead organisations should be in the following order: - | name | - | Another lead organisation | - | Lead organisation | - - Scenario: Make lead organisation - When I visit the topical event organisations index page - And I make "Supporting organisation" a lead organisation - Then I can see a "Supporting organisation has been assigned as a lead organisation." success notice - And I can see the lead organisation with the name "Supporting organisation" - - Scenario: Make supporting organisation - When I visit the topical event organisations index page - And I make "Lead organisation" a supporting organisation - Then I can see a "Lead organisation has been assigned as a supporting organisation." success notice - And I can see the supporting organisation with the name "Lead organisation" diff --git a/features/topical_events.feature b/features/topical_events.feature deleted file mode 100644 index e67c6d17d57..00000000000 --- a/features/topical_events.feature +++ /dev/null @@ -1,22 +0,0 @@ -Feature: Creating and publishing topical events - As an editor - I want to be able to create and publish topical events - So that I can communicate about them - - Background: - Given I am an editor - Given search returns no results - - Scenario: Adding a new topical event - When I create a new topical event "An Event" with summary "A topical event" and description "About this topical event" - Then I should see the topical event "An Event" in the admin interface - - Scenario: Adding more information about the event - Given I'm administering a topical event - And I add a page of information about the event - Then I should be able to edit the event's about page - And I should see the about page is updated - - Scenario: Deleting a topical event - Given a topical event called "An event" with summary "A topical event" and description "A topical event" - Then I should be able to delete the topical event "An event" diff --git a/features/world-location-news.feature b/features/world-location-news.feature index 52b9d88914d..f8e3fa5067e 100644 --- a/features/world-location-news.feature +++ b/features/world-location-news.feature @@ -45,13 +45,6 @@ Feature: Administering world location news information Then I should be on the Spanish search results page And I should see "Documento destacado" in the document list - # Delete when we've migrated legacy topical events - Scenario: Featuring a (legacy) topical event - Given there is an active topical event with the name "Featured topical event" - When I visit the world location news page - And I feature "Featured topical event" - Then I see that "Featured topical event" has been featured - Scenario: Featuring a non-GOV.UK link Given the world location has an offsite link with the title "Featured link" When I visit the world location news page diff --git a/lib/data_hygiene/topical_event_reslugger.rb b/lib/data_hygiene/topical_event_reslugger.rb deleted file mode 100644 index f11f9fa1c01..00000000000 --- a/lib/data_hygiene/topical_event_reslugger.rb +++ /dev/null @@ -1,48 +0,0 @@ -module DataHygiene - class TopicalEventReslugger - def initialize(topical_event, new_slug) - @topical_event = topical_event - @new_slug = new_slug - @old_slug = @topical_event.slug - @editions = @topical_event.editions - end - - def run! - delete_from_search_index - update_slug - republish - add_to_search_index - update_atom_feed_url - end - - private - - attr_reader :topical_event, :new_slug, :old_slug, :editions - - def delete_from_search_index - topical_event.remove_from_search_index - end - - def update_slug - topical_event.update!(slug: new_slug) - end - - def republish - Whitehall::PublishingApi.republish_async(topical_event) - end - - def add_to_search_index - topical_event.update_in_search_index - end - - def update_atom_feed_url - old_atom_feed_path = "/government/topical-events/#{old_slug}.atom" - new_atom_feed_path = "/government/topical-events/#{new_slug}.atom" - redirects = [{ path: old_atom_feed_path, type: "exact", destination: new_atom_feed_path }] - content_id = SecureRandom.uuid - redirect = Whitehall::PublishingApi::Redirect.new(old_atom_feed_path, redirects) - Services.publishing_api.put_content(content_id, redirect.as_json) - Services.publishing_api.publish(content_id, nil, locale: "en") - end - end -end diff --git a/lib/tasks/reslugging.rake b/lib/tasks/reslugging.rake index b30b295fd7b..af7a5d4d7de 100644 --- a/lib/tasks/reslugging.rake +++ b/lib/tasks/reslugging.rake @@ -28,20 +28,6 @@ namespace :reslug do DataHygiene::RoleReslugger.new(role, args[:new_slug]).run! end - desc "Change a topical_event's slug in whitehall (DANGER!).\n - It performs the following steps: - - changes the topical_events slug - - reindexes the topical_event with its new slug - - republishes the topical_event to Publishing API (automatically handles the redirect)" - task :topical_event, %i[old_slug new_slug] => :environment do |_task, args| - topical_events = TopicalEvent.where(slug: args.old_slug) - raise "Multiple topical_events with slug '#{args.old_slug}'. Use content_id to uniquely identify it." if topical_events.count > 1 - raise "No topical_event with slug '#{args.old_slug}'. Use content_id to uniquely identify it." if topical_events.count < 1 - - topical_event = topical_events.first - DataHygiene::TopicalEventReslugger.new(topical_event, args.new_slug).run! - end - desc "Change a html attachment's slug in whitehall and redirect old slug\n It performs the following steps: - changes a html attachment slug diff --git a/public/configurable-document-type.schema.json b/public/configurable-document-type.schema.json index 0acf475c04a..9817c3b6cc0 100644 --- a/public/configurable-document-type.schema.json +++ b/public/configurable-document-type.schema.json @@ -121,7 +121,6 @@ "roles", "statistical_data_sets", "topical_event_documents", - "topical_events", "world_locations", "worldwide_organisations" ] diff --git a/test/components/admin/currently_featured_tab_component_test.rb b/test/components/admin/currently_featured_tab_component_test.rb index 247769a9b68..7709d034588 100644 --- a/test/components/admin/currently_featured_tab_component_test.rb +++ b/test/components/admin/currently_featured_tab_component_test.rb @@ -101,83 +101,4 @@ class Admin::CurrentlyFeaturedTabComponentTest < ViewComponent::TestCase maximum_featured_documents: @maximum_featured_documents, )) end - - # Delete when legacy topical events are removed. - test "renders link to the reorder legacy topical event featurings page if more than 1 feature_list item" do - topical_event = build_stubbed(:topical_event) - render_inline(Admin::CurrentlyFeaturedTabComponent.new( - featurings: build_stubbed_list(:topical_event_featuring, 2, topical_event:), - maximum_featured_documents: @maximum_featured_documents, - )) - - assert_selector ".govuk-link[href='#{reorder_admin_topical_event_topical_event_featurings_path(topical_event)}']", text: "Reorder pages" - end - - # Delete when legacy topical events are removed. - test "does not render link to the reorder legacy topical event featurings page if less than 2 featurings" do - render_inline(Admin::CurrentlyFeaturedTabComponent.new( - featurings: [build_stubbed(:topical_event_featuring)], - maximum_featured_documents: @maximum_featured_documents, - )) - - assert_selector ".govuk-link", text: "Reorder documents", count: 0 - end - - # Delete when legacy topical events are removed. - test "makes one call to the featurings FeaturedDocumentsTableComponent when legacy topical event featurings count is <= to maximum_featured_documents" do - topical_event = build_stubbed(:topical_event) - featurings = build_stubbed_list(:topical_event_featuring, @maximum_featured_documents, topical_event:) - table_component = Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new(caption: "caption", featurings: []) - - Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent - .expects(:new) - .with(featurings:, caption: nil) - .once - .returns(table_component) - - table_component - .expects(:render) - .returns("") - - render_inline(Admin::CurrentlyFeaturedTabComponent.new( - featurings:, - maximum_featured_documents: @maximum_featured_documents, - )) - end - - # Delete when legacy topical events are removed. - test "makes two calls to the featurings FeaturedDocumentsTableComponent when legacy topical event featurings count is greater than maximum_featured_documents" do - topical_event = build_stubbed(:topical_event) - live_featurings = build_stubbed_list(:topical_event_featuring, @maximum_featured_documents, topical_event:) - remaining_featurings = build_stubbed(:topical_event_featuring, topical_event:) - table_component1 = Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new(caption: "caption1", featurings: []) - table_component2 = Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new(caption: "caption2", featurings: []) - - Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent - .expects(:new) - .with(featurings: live_featurings, caption: nil) - .once - .returns(table_component1) - - table_component1 - .expects(:render) - .once - .returns("") - - Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent - .expects(:new) - .with(featurings: [remaining_featurings], caption: "1 remaining featured page") - .once - .returns(table_component2) - - table_component2 - .expects(:render) - .once - .returns("") - - render_inline(Admin::CurrentlyFeaturedTabComponent.new( - featurings: live_featurings + [remaining_featurings], - maximum_featured_documents: @maximum_featured_documents, - )) - end end diff --git a/test/components/admin/features/featured_table_component_test.rb b/test/components/admin/features/featured_table_component_test.rb index 1302c26b359..2b3e9b8b157 100644 --- a/test/components/admin/features/featured_table_component_test.rb +++ b/test/components/admin/features/featured_table_component_test.rb @@ -46,22 +46,6 @@ class Admin::Features::FeaturedDocumentsTableComponentTest < ViewComponent::Test actions_column.assert_selector "a[href='#{confirm_unfeature_admin_feature_list_feature_path(@feature_list, feature)}']", text: "Unfeature #{title}" end - # Delete when legacy topical events are removed. - test "renders the correct row when the feature list item belongs to a topical event" do - feature = build_stubbed(:feature, :with_topical_event_association, feature_list: @feature_list) - title = feature.topical_event.name - - render_inline(Admin::Features::FeaturedDocumentsTableComponent.new(caption: "caption", features: [feature])) - - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[0].text, title - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[1].text, "Topical Event" - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[2].text, topical_event_dates_string(feature.topical_event) - - actions_column = page.all(".govuk-table .govuk-table__row .govuk-table__cell")[3] - actions_column.assert_selector "a[href='#{edit_admin_topical_event_path(feature.topical_event)}']", text: "Edit #{title}" - actions_column.assert_selector "a[href='#{confirm_unfeature_admin_feature_list_feature_path(feature.feature_list, feature)}']", text: "Unfeature #{title}" - end - test "renders the correct row when the feature list item belongs to a offsite link" do feature = create(:feature, :with_offsite_link_association, feature_list: @feature_list) title = feature.offsite_link.title diff --git a/test/components/admin/organisations/show/summary_list_component_test.rb b/test/components/admin/organisations/show/summary_list_component_test.rb index a1f8ea60635..1624a2681c8 100644 --- a/test/components/admin/organisations/show/summary_list_component_test.rb +++ b/test/components/admin/organisations/show/summary_list_component_test.rb @@ -189,36 +189,6 @@ class Admin::Organisations::Show::SummaryListComponentTest < ViewComponent::Test assert_selector ".govuk-summary-list__row:nth-child(7) .govuk-summary-list__actions a[href='#{parent_organisation2.public_url}']", text: /View/ end - test "renders topical_events_row correctly when one parent org is present" do - topical_event = build_stubbed(:topical_event) - organisation = build_stubbed(:ministerial_department) - organisation.stubs(:topical_events).returns([topical_event]) - - render_inline(Admin::Organisations::Show::SummaryListComponent.new(organisation:)) - - assert_selector ".govuk-summary-list__row", count: 8 - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__key", text: "Topical event" - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__value", text: topical_event.name - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__actions a[href='#{topical_event.public_url}']", text: /View/ - end - - test "renders topical_events_rows correctly when multiple topical events are present" do - topical_event1 = build_stubbed(:topical_event) - topical_event2 = build_stubbed(:topical_event) - organisation = build_stubbed(:ministerial_department) - organisation.stubs(:topical_events).returns([topical_event1, topical_event2]) - - render_inline(Admin::Organisations::Show::SummaryListComponent.new(organisation:)) - - assert_selector ".govuk-summary-list__row", count: 9 - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__key", text: "Topical event 1" - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__value", text: topical_event1.name - assert_selector ".govuk-summary-list__row:nth-child(6) .govuk-summary-list__actions a[href='#{topical_event1.public_url}']", text: /View/ - assert_selector ".govuk-summary-list__row:nth-child(7) .govuk-summary-list__key", text: "Topical event 2" - assert_selector ".govuk-summary-list__row:nth-child(7) .govuk-summary-list__value", text: topical_event2.name - assert_selector ".govuk-summary-list__row:nth-child(7) .govuk-summary-list__actions a[href='#{topical_event2.public_url}']", text: /View/ - end - test "renders featured_link correctly when one featured link is present" do featured_link = build_stubbed(:featured_link) organisation = build_stubbed(:ministerial_department) diff --git a/test/components/admin/topical_events/featurings/featured_documents_table_component_test.rb b/test/components/admin/topical_events/featurings/featured_documents_table_component_test.rb deleted file mode 100644 index 30d4b1c0540..00000000000 --- a/test/components/admin/topical_events/featurings/featured_documents_table_component_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponentTest < ViewComponent::TestCase - include Rails.application.routes.url_helpers - include Admin::EditionRoutesHelper - - test "renders the correct row when the featurable is associated with an edition" do - edition = build_stubbed(:publication, :published, publication_type: PublicationType::Guidance) - topical_event = build_stubbed(:topical_event) - featuring = build_stubbed(:topical_event_featuring, edition:, topical_event:) - title = featuring.title - - render_inline(Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new( - caption: "caption", - featurings: [featuring], - )) - - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[0].text, title - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[1].text, "Guidance (document)" - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[2].text, I18n.localize(edition.major_change_published_at.to_date) - - actions_column = page.all(".govuk-table .govuk-table__row .govuk-table__cell")[3] - actions_column.assert_selector "a[href='#{admin_edition_path(edition)}']", text: "View #{title}" - actions_column.assert_selector "a[href='#{confirm_destroy_admin_topical_event_topical_event_featuring_path(topical_event, featuring)}']", text: "Unfeature #{title}" - end - - test "renders the correct row when the featurable is associated with a standard edition" do - ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type")) - edition = build_stubbed(:published_standard_edition) - topical_event = build_stubbed(:topical_event) - featuring = build_stubbed(:topical_event_featuring, edition:, topical_event:) - title = featuring.title - - render_inline(Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new( - caption: "caption", - featurings: [featuring], - )) - - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[0].text, title - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[1].text, "Test type (document)" - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[2].text, I18n.localize(edition.major_change_published_at.to_date) - - actions_column = page.all(".govuk-table .govuk-table__row .govuk-table__cell")[3] - actions_column.assert_selector "a[href='#{admin_edition_path(edition)}']", text: "View #{title}" - actions_column.assert_selector "a[href='#{confirm_destroy_admin_topical_event_topical_event_featuring_path(topical_event, featuring)}']", text: "Unfeature #{title}" - end - - test "renders the correct row when the featurable is associated with an offsite link" do - topical_event = create(:topical_event) - featuring = create(:offsite_topical_event_featuring, topical_event:) - title = featuring.offsite_link.title - - render_inline(Admin::TopicalEvents::Featurings::FeaturedDocumentsTableComponent.new( - caption: "caption", - featurings: [featuring], - )) - - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[0].text, title - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[1].text, "Alert (offsite link)" - assert_equal page.all(".govuk-table .govuk-table__row .govuk-table__cell")[2].text, "" - - actions_column = page.all(".govuk-table .govuk-table__row .govuk-table__cell")[3] - actions_column.assert_selector "a[href='#{polymorphic_path([:edit, :admin, topical_event, featuring.offsite_link])}']", text: "Edit #{title}" - actions_column.assert_selector "a[href='#{confirm_destroy_admin_topical_event_topical_event_featuring_path(topical_event, featuring)}']", text: "Unfeature #{title}" - end -end diff --git a/test/factories/editions.rb b/test/factories/editions.rb index c68e0f4aea9..4947e97f065 100644 --- a/test/factories/editions.rb +++ b/test/factories/editions.rb @@ -44,17 +44,6 @@ end end - trait(:with_topical_events) do - after :build do |edition, evaluator| - if evaluator.topical_events.empty? - edition.topical_event_memberships.build( - edition:, - topical_event: build(:topical_event), - ) - end - end - end - trait(:draft) { state { "draft" } } trait(:submitted) do diff --git a/test/factories/features.rb b/test/factories/features.rb index aeba5c8b05a..bc751ac2d2a 100644 --- a/test/factories/features.rb +++ b/test/factories/features.rb @@ -3,11 +3,6 @@ document image { build(:featured_image_data) } - trait :with_topical_event_association do - topical_event - document { nil } - end - trait :with_offsite_link_association do association :offsite_link, :for_organisation document { nil } diff --git a/test/factories/offsite_links.rb b/test/factories/offsite_links.rb index 1f7e079208a..99a3e5ff1ab 100644 --- a/test/factories/offsite_links.rb +++ b/test/factories/offsite_links.rb @@ -6,10 +6,6 @@ url { "http://gov.uk/test" } end - trait :for_topical_event do - topical_events { FactoryBot.build_list(:topical_event, 1) } - end - trait :for_world_location_news do world_location_news { FactoryBot.build_list(:world_location_news, 1) } end diff --git a/test/factories/topical_event_about_pages.rb b/test/factories/topical_event_about_pages.rb deleted file mode 100644 index a741b7fb4bf..00000000000 --- a/test/factories/topical_event_about_pages.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryBot.define do - factory :topical_event_about_page do - sequence(:name) { |index| "topical-event-about-page-#{index}" } - read_more_link_text { "Read more" } - summary { "Summary" } - body { "Body" } - topical_event - end -end diff --git a/test/factories/topical_event_featuring_image_data.rb b/test/factories/topical_event_featuring_image_data.rb deleted file mode 100644 index 66f5fe7dca4..00000000000 --- a/test/factories/topical_event_featuring_image_data.rb +++ /dev/null @@ -1,15 +0,0 @@ -FactoryBot.define do - factory :topical_event_featuring_image_data do - file { image_fixture_file } - - after(:build) do |topical_event_featuring_image_data| - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_original", variant: Asset.variants[:original], filename: topical_event_featuring_image_data.filename) - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s960", variant: Asset.variants[:s960], filename: "s960_#{topical_event_featuring_image_data.filename}") - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s712", variant: Asset.variants[:s712], filename: "s712_#{topical_event_featuring_image_data.filename}") - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s630", variant: Asset.variants[:s630], filename: "s630_#{topical_event_featuring_image_data.filename}") - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s465", variant: Asset.variants[:s465], filename: "s465_#{topical_event_featuring_image_data.filename}") - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s300", variant: Asset.variants[:s300], filename: "s300_#{topical_event_featuring_image_data.filename}") - topical_event_featuring_image_data.assets << build(:asset, asset_manager_id: "asset_manager_id_s216", variant: Asset.variants[:s216], filename: "s216_#{topical_event_featuring_image_data.filename}") - end - end -end diff --git a/test/factories/topical_event_featurings.rb b/test/factories/topical_event_featurings.rb deleted file mode 100644 index cd0174107b7..00000000000 --- a/test/factories/topical_event_featurings.rb +++ /dev/null @@ -1,24 +0,0 @@ -FactoryBot.define do - factory :topical_event_featuring do - association :edition, factory: :published_edition - topical_event - sequence(:ordering) { |index| index } - alt_text { "An accessible description of the image" } - - after(:build) do |featuring| - featuring.image = build(:topical_event_featuring_image_data) - end - end - - factory :offsite_topical_event_featuring, class: TopicalEventFeaturing do - offsite_link { FactoryBot.build(:offsite_link, topical_events: [topical_event]) } - topical_event - sequence(:ordering) { |index| index } - edition { nil } - alt_text { "An accessible description of the image" } - - after(:build) do |featuring| - featuring.image = build(:topical_event_featuring_image_data) - end - end -end diff --git a/test/factories/topical_event_memberships.rb b/test/factories/topical_event_memberships.rb deleted file mode 100644 index 570fd9267f8..00000000000 --- a/test/factories/topical_event_memberships.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :topical_event_membership do - publication - topical_event - end -end diff --git a/test/factories/topical_event_organisation.rb b/test/factories/topical_event_organisation.rb deleted file mode 100644 index e2e2a2f76ea..00000000000 --- a/test/factories/topical_event_organisation.rb +++ /dev/null @@ -1,7 +0,0 @@ -FactoryBot.define do - factory :topical_event_organisation do - organisation { FactoryBot.build(:organisation) } - topical_event { FactoryBot.build(:topical_event) } - lead { false } - end -end diff --git a/test/factories/topical_events.rb b/test/factories/topical_events.rb deleted file mode 100644 index 4a3f711fe5b..00000000000 --- a/test/factories/topical_events.rb +++ /dev/null @@ -1,23 +0,0 @@ -FactoryBot.define do - factory :topical_event do - sequence(:name) { |index| "topical-event-#{index}" } - summary { "Topical event summary" } - description { "Topical event description" } - - trait :active do - start_date { Time.zone.today - 1.month } - end_date { Time.zone.today + 1.month } - end - - trait :with_logo do - logo { build(:featured_image_data) } - logo_alt_text { "Alternative text" } - end - - trait :with_social_media_accounts do - after :build do |topical_event| - topical_event.social_media_accounts << build(:social_media_account) - end - end - end -end diff --git a/test/functional/admin/organisations_controller_test.rb b/test/functional/admin/organisations_controller_test.rb index d4ad72ae7e6..4048a98b5d0 100644 --- a/test/functional/admin/organisations_controller_test.rb +++ b/test/functional/admin/organisations_controller_test.rb @@ -68,8 +68,6 @@ def example_organisation_attributes assert_redirected_to admin_organisations_path assert_equal "Organisation created successfully.", flash[:notice] assert organisation = Organisation.last - assert organisation.topical_event_organisations.map(&:ordering).all?(&:present?), "no ordering" - assert_equal organisation.topical_event_organisations.map(&:ordering).sort, organisation.topical_event_organisations.map(&:ordering).uniq.sort assert organisation_top_task = organisation.featured_links.last assert_equal "http://www.gov.uk/mainstream/something", organisation_top_task.url assert_equal "Something on mainstream", organisation_top_task.title @@ -300,34 +298,6 @@ def example_organisation_attributes assert_equal "New title", featured_link.reload.title end - test "PUT on :update handles adding and removing topical event attributes" do - topical_event_one = create(:topical_event) - organisation = create(:organisation, topical_events: [topical_event_one]) - topical_event_two = create(:topical_event) - - put :update, - params: { - id: organisation, - organisation: { - topical_event_organisations_attributes: [ - { - topical_event_id: topical_event_one.id, - ordering: 0, - id: organisation.topical_event_organisations.first.id, - _destroy: "true", - }, - { - topical_event_id: topical_event_two.id, - ordering: 1, - }, - ], - }, - } - - assert_response :redirect - assert_equal [topical_event_two], organisation.reload.topical_events - end - test "GET on :show displays 'image is being processed' flash notice when not all image assets are uploaded" do organisation = build(:organisation, :with_default_news_image) organisation.default_news_image.assets = [] @@ -374,22 +344,6 @@ def example_organisation_attributes assert_response :success end - view_test "GET :features copes with topical events that have no dates" do - topical_event = create(:topical_event) - organisation = create(:organisation) - feature_list = organisation.load_or_create_feature_list("en") - feature_list.features.create!( - topical_event:, - image_attributes: { - file: image_fixture_file, - }, - alt_text: "Image alternative text", - ) - - get :features, params: { id: organisation, locale: "en" } - assert_response :success - end - view_test "GET :features without an organisation defaults to the user organisation" do organisation = create(:organisation) diff --git a/test/functional/admin/speeches_controller_test.rb b/test/functional/admin/speeches_controller_test.rb index 5ab02f38514..c2ed1c004ad 100644 --- a/test/functional/admin/speeches_controller_test.rb +++ b/test/functional/admin/speeches_controller_test.rb @@ -13,7 +13,6 @@ class Admin::SpeechesControllerTest < ActionController::TestCase should_allow_association_between_world_locations_and :speech should_allow_scheduled_publication_of :speech should_allow_access_limiting_of :speech - should_allow_association_with_topical_events :speech should_allow_association_with_topical_event_documents_when_configurable_document_types_enabled :speech view_test "new displays speech fields" do diff --git a/test/functional/admin/topical_event_about_pages_controller_test.rb b/test/functional/admin/topical_event_about_pages_controller_test.rb deleted file mode 100644 index 9bc0f80de7b..00000000000 --- a/test/functional/admin/topical_event_about_pages_controller_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class Admin::TopicalEventAboutPagesControllerTest < ActionController::TestCase - def setup - @topical_event = create(:topical_event) - login_as :writer - end - - view_test "GET show prompts user to create an about page" do - get :show, params: { topical_event_id: @topical_event.to_param } - assert_response :success - assert_select "h1", @topical_event.name - assert_select ".govuk-inset-text", "There is no about page associated with this topical event." - end - - view_test "GET new allows user to enter copy for new about page" do - get :new, params: { topical_event_id: @topical_event.to_param } - assert_select 'textarea[name*="summary"]' - end - - test "POST create saves a new about page" do - assert_difference "TopicalEventAboutPage.count" do - post :create, params: { topical_event_id: @topical_event.to_param, topical_event_about_page: attributes_for(:topical_event_about_page) } - end - @topical_event.reload - assert_not_nil @topical_event.topical_event_about_page, "expected topical event to have an about page" - end - - view_test "GET edit shows the form for editing an about page" do - create(:topical_event_about_page, topical_event: @topical_event) - get :edit, params: { topical_event_id: @topical_event.to_param } - assert_select 'textarea[name*="summary"]' - end - - test "PUT update saves changes to the about page" do - about = create(:topical_event_about_page, topical_event: @topical_event) - put :update, params: { topical_event_id: @topical_event.to_param, topical_event_about_page: { name: "New name" } } - assert_equal "New name", about.reload.name - end -end diff --git a/test/functional/admin/topical_event_featurings_controller_test.rb b/test/functional/admin/topical_event_featurings_controller_test.rb deleted file mode 100644 index 250865d05f1..00000000000 --- a/test/functional/admin/topical_event_featurings_controller_test.rb +++ /dev/null @@ -1,243 +0,0 @@ -require "test_helper" - -class Admin::TopicalEventFeaturingsControllerTest < ActionController::TestCase - should_be_an_admin_controller - - extend Minitest::Spec::DSL - - setup do - @topical_event = create(:topical_event) - login_as :writer - end - - test "GET :index assigns tagged_editions with a paginated collection of published editions related to the topical_event ordered by most recently created editions first" do - publication1 = create(:published_publication, topical_events: [@topical_event]) - publication2 = Timecop.travel(10.minutes) { create(:published_publication, topical_events: [@topical_event]) } - _draft_publication = create(:draft_publication, topical_events: [@topical_event]) - _unrelated_publication = create(:draft_publication, topical_events: [create(:topical_event)]) - - get :index, params: { topical_event_id: @topical_event, page: 1 } - - tagged_editions = assigns(:tagged_editions) - assert_equal [publication2, publication1], tagged_editions - assert_equal 1, tagged_editions.current_page - assert_equal 1, tagged_editions.total_pages - assert_equal 15, tagged_editions.limit_value - end - - test "GET :index assigns a filtered list to tagged_editions when given a title" do - create(:published_publication, topical_events: [@topical_event]) - publication = create(:published_publication, topical_events: [@topical_event], title: "Specific title") - _unrelated_publication = create(:published_publication, :with_topical_events, title: "Specific title") - - get :index, params: { topical_event_id: @topical_event, title: "specific" } - - tagged_editions = assigns(:tagged_editions) - assert_equal [publication], tagged_editions - end - - test "GET :index assigns a filtered list to tagged_editions when given an organisation" do - create(:published_publication, topical_events: [@topical_event]) - org = create(:organisation) - publication = create(:published_publication, topical_events: [@topical_event]) - publication.organisations << org - - get :index, params: { topical_event_id: @topical_event, organisation: org.id } - - tagged_editions = assigns(:tagged_editions) - assert_equal [publication], tagged_editions - end - - test "GET :index assigns a filtered list to tagged_editions when given an author" do - create(:published_publication, topical_events: [@topical_event]) - publication = create(:published_publication, topical_events: [@topical_event]) - user = create(:user) - create(:edition_author, edition: publication, user:) - - get :index, params: { topical_event_id: @topical_event, author: user.id } - - tagged_editions = assigns(:tagged_editions) - assert_equal [publication], tagged_editions - end - - test "GET :index assigns a filtered list to tagged_editions when given a document type" do - publication = create(:published_publication, topical_events: [@topical_event]) - - get :index, params: { topical_event_id: @topical_event, type: publication.display_type_key } - - tagged_editions = assigns(:tagged_editions) - assert_equal [publication], tagged_editions - end - - view_test "GET :index contains a message when no results matching search criteria were found" do - create(:published_publication, topical_events: [@topical_event]) - - get :index, params: { topical_event_id: create(:topical_event) } - - assert_equal 0, assigns(:tagged_editions).count - assert_match "No pages found", response.body - end - - test "PUT :order saves the new order of featurings" do - feature1 = create(:topical_event_featuring, topical_event: @topical_event) - feature2 = create(:topical_event_featuring, topical_event: @topical_event) - feature3 = create(:topical_event_featuring, topical_event: @topical_event) - - Whitehall::PublishingApi.expects(:republish_async).with(@topical_event).once - - put :order, - params: { topical_event_id: @topical_event, - topical_event_featurings: { - ordering: { - feature1.id.to_s => "1", - feature2.id.to_s => "2", - feature3.id.to_s => "0", - }, - } } - - assert_response :redirect - assert_equal [feature3, feature1, feature2], @topical_event.reload.topical_event_featurings - end - - view_test "GET :new renders only image fields if featuring an edition" do - edition = create :edition - get :new, params: { topical_event_id: @topical_event.id, edition_id: edition.id } - - assert_select "#topical_event_featuring_image_file" - assert_select "#topical_event_featuring_alt_text" - end - - view_test "GET :new renders all fields if not featuring an edition" do - offsite_link = create(:offsite_link, topical_events: [@topical_event]) - get :new, params: { topical_event_id: @topical_event.id, offsite_link_id: offsite_link.id } - - assert_select "#topical_event_featuring_image_file" - assert_select "#topical_event_featuring_alt_text" - end - - test "DELETE :destroy unfeatures edition and redirects to topical_event" do - featuring = create(:topical_event_featuring, - topical_event: create(:topical_event)) - - assert_difference("TopicalEventFeaturing.count", -1) do - delete :destroy, params: { - topical_event_id: featuring.topical_event.id, id: featuring.id - } - end - - assert_response :redirect - end - - test "DELETE :destroy unfeatures offsite link and redirects to topical_event" do - offsite_featuring = create(:offsite_topical_event_featuring, - topical_event: create(:topical_event)) - - assert_difference("TopicalEventFeaturing.count", -1) do - delete :destroy, params: { - topical_event_id: offsite_featuring.topical_event.id, id: offsite_featuring.id - } - end - - assert_response :redirect - end - - test "POST :create saves the topical event featuring with image" do - topical_event = create(:topical_event) - offsite_link = create(:offsite_link, topical_events: [topical_event]) - - assert_difference("TopicalEventFeaturing.count") do - post :create, params: { - topical_event_id: topical_event.id, - topical_event_featuring: { - alt_text: "Alt Text", - offsite_link_id: offsite_link.id, - image_attributes: { - file: upload_fixture("images/960x640_jpeg.jpg"), - }, - }, - } - end - - assert_response :redirect - - topical_event_featuring = TopicalEventFeaturing.last - assert_equal "Alt Text", topical_event_featuring.alt_text - assert_equal "960x640_jpeg.jpg", topical_event_featuring.image.filename - end - - context "can feature standard editions" do - setup do - ConfigurableDocumentType.setup_test_types( - build_configurable_document_type("test_type"), - ) - end - - test "GET :index, when featuring standard editions, assigns a filtered list to tagged_editions when given a title" do - create(:published_standard_edition, topical_events: [@topical_event]) - standard_edition = create(:published_standard_edition, topical_events: [@topical_event], title: "Specific title") - _unrelated_standard_edition = create(:published_standard_edition, :with_topical_events, title: "Specific title") - - get :index, params: { topical_event_id: @topical_event, title: "specific" } - - tagged_editions = assigns(:tagged_editions) - assert_equal [standard_edition], tagged_editions - end - - test "GET :index, when featuring standard editions, assigns tagged_editions with a paginated collection of published editions related to the topical_event ordered by most recently created editions first" do - standard_edition1 = create(:published_standard_edition, topical_events: [@topical_event]) - standard_edition2 = Timecop.travel(10.minutes) { create(:published_standard_edition, topical_events: [@topical_event]) } - _draft_standard_edition = create(:draft_standard_edition, topical_events: [@topical_event]) - _unrelated_standard_edition = create(:draft_standard_edition, topical_events: [create(:topical_event)]) - - get :index, params: { topical_event_id: @topical_event, page: 1 } - - tagged_editions = assigns(:tagged_editions) - assert_equal [standard_edition2, standard_edition1], tagged_editions - assert_equal 1, tagged_editions.current_page - assert_equal 1, tagged_editions.total_pages - assert_equal 15, tagged_editions.limit_value - end - - test "GET :index, when featuring standard editions, assigns a filtered list to tagged_editions when given an organisation" do - create(:published_standard_edition, topical_events: [@topical_event]) - org = create(:organisation) - standard_edition = create(:published_standard_edition, topical_events: [@topical_event]) - standard_edition.organisations << org - - get :index, params: { topical_event_id: @topical_event, organisation: org.id } - - tagged_editions = assigns(:tagged_editions) - assert_equal [standard_edition], tagged_editions - end - - test "GET :index, when featuring standard editions, assigns a filtered list to tagged_editions when given an author" do - create(:published_standard_edition, topical_events: [@topical_event]) - standard_edition = create(:published_standard_edition, topical_events: [@topical_event]) - user = create(:user) - create(:edition_author, edition: standard_edition, user:) - - get :index, params: { topical_event_id: @topical_event, author: user.id } - - tagged_editions = assigns(:tagged_editions) - assert_equal [standard_edition], tagged_editions - end - - test "GET :index, when featuring standard editions, assigns a filtered list to tagged_editions when given a document type" do - standard_edition = create(:published_standard_edition, topical_events: [@topical_event]) - - get :index, params: { topical_event_id: @topical_event, type: standard_edition.display_type_key } - - tagged_editions = assigns(:tagged_editions) - assert_equal [standard_edition], tagged_editions - end - - view_test "GET :index, when featuring standard editions, contains a message when no results matching search criteria were found" do - create(:published_standard_edition, topical_events: [@topical_event]) - - get :index, params: { topical_event_id: create(:topical_event) } - - assert_equal 0, assigns(:tagged_editions).count - assert_match "No pages found", response.body - end - end -end diff --git a/test/functional/admin/topical_event_organisations_controller_test.rb b/test/functional/admin/topical_event_organisations_controller_test.rb deleted file mode 100644 index 314ba3018fc..00000000000 --- a/test/functional/admin/topical_event_organisations_controller_test.rb +++ /dev/null @@ -1,127 +0,0 @@ -require "test_helper" - -class Admin::TopicalEventOrganisationsControllerTest < ActionController::TestCase - should_be_an_admin_controller - - setup do - @topical_event = create(:topical_event) - login_as :writer - end - - view_test "GET :index renders headings and links" do - get :index, params: { topical_event_id: @topical_event } - - assert_template :index - assert_response :success - assert_select "a[href=?]", admin_topical_events_path, text: "Back" - assert_select "h1", @topical_event.name - assert_select "a[href=?]", @topical_event.public_url({ cachebust: Time.zone.now.getutc.to_i }), text: "View on website" - assert_select "a[href=?]", admin_topical_event_topical_event_organisations_path(@topical_event), text: "Organisations" - end - - view_test "GET :index renders lead organisations only" do - lead_topical_event_organisations = create_list(:topical_event_organisation, 2, topical_event: @topical_event, lead: true) - get :index, params: { topical_event_id: @topical_event } - - check_topical_event_organisations(lead_topical_event_organisations, "lead") - assert_select "a[href=?]", reorder_admin_topical_event_topical_event_organisations_path(@topical_event), text: "Reorder organisations" - refute_select "#supporting_organisations" - end - - view_test "GET :index renders no reorder link when there is only one lead organisation" do - create_list(:topical_event_organisation, 2, topical_event: @topical_event) - lead_topical_event_organisations = create_list(:topical_event_organisation, 1, topical_event: @topical_event, lead: true) - get :index, params: { topical_event_id: @topical_event } - - check_topical_event_organisations(lead_topical_event_organisations, "lead") - refute_select "a[href=?]", reorder_admin_topical_event_topical_event_organisations_path(@topical_event), text: "Reorder organisations" - end - - view_test "GET :index renders lead supporting organisations only with no reorder link" do - supporting_topical_event_organisations = create_list(:topical_event_organisation, 2, topical_event: @topical_event) - get :index, params: { topical_event_id: @topical_event } - - check_topical_event_organisations(supporting_topical_event_organisations, "supporting") - refute_select "a[href=?]", reorder_admin_topical_event_topical_event_organisations_path(@topical_event) - refute_select "#lead_organisations" - end - - view_test "GET :index renders no organisations banner" do - get :index, params: { topical_event_id: @topical_event } - - assert_template :index - assert_response :success - assert_select ".govuk-inset-text", "There are no organisations associated with this topical event." - end - - view_test "GET :reorder renders reoderable list of lead organisations" do - lead_topical_event_organisations = create_list(:topical_event_organisation, 2, topical_event: @topical_event, lead: true) - get :reorder, params: { topical_event_id: @topical_event } - - assert_template :reorder - assert_response :success - assert_select "h1", "Reorder lead organisations list" - assert_select ".gem-c-reorderable-list", count: 1 - assert_select ".gem-c-reorderable-list__item", count: 2 - assert_select ".gem-c-reorderable-list__title", lead_topical_event_organisations[0].organisation.name - assert_select ".gem-c-reorderable-list__title", lead_topical_event_organisations[1].organisation.name - end - - test "PUT :order saves the new order of lead organisations" do - lead_topical_event_organisations = create_list(:topical_event_organisation, 3, topical_event: @topical_event, lead: true) - - Whitehall::PublishingApi.expects(:republish_async).with(@topical_event).once - - put :order, - params: { topical_event_id: @topical_event, - topical_event_lead_organisations: { - ordering: { - lead_topical_event_organisations[0].id.to_s => "1", - lead_topical_event_organisations[1].id.to_s => "2", - lead_topical_event_organisations[2].id.to_s => "0", - }, - } } - - assert_response :redirect - assert_equal [lead_topical_event_organisations[2], lead_topical_event_organisations[0], lead_topical_event_organisations[1]], @topical_event.reload.topical_event_organisations.where(lead: true).order(:lead_ordering) - end - - test "GET :toggle_lead makes a supporting organisation into a lead with highest lead ordering" do - create_list(:topical_event_organisation, 3, topical_event: @topical_event, lead: true) - topical_event_organisation = create(:topical_event_organisation, topical_event: @topical_event, lead: false) - - Whitehall::PublishingApi.expects(:republish_async).with(@topical_event).once - - get :toggle_lead, - params: { topical_event_id: @topical_event, - id: topical_event_organisation } - - assert_response :redirect - assert topical_event_organisation.reload.lead - assert_equal 3, topical_event_organisation.lead_ordering - end - - test "GET :toggle_lead makes a lead organisation into a supporting organisation" do - topical_event_organisation = create(:topical_event_organisation, topical_event: @topical_event, lead: true) - - Whitehall::PublishingApi.expects(:republish_async).with(@topical_event).once - - get :toggle_lead, - params: { topical_event_id: @topical_event, - id: topical_event_organisation } - - assert_response :redirect - assert_not topical_event_organisation.reload.lead - end - - def check_topical_event_organisations(topical_event_organisations, type) - assert_select "##{type}_organisations" do - assert_select ".govuk-heading-m", "#{type.capitalize} organisations" - topical_event_organisations.each do |topical_event_organisation| - assert_select "th", topical_event_organisation.organisation.name - assert_select "a[href=?]", admin_organisation_path(topical_event_organisation.organisation), text: "View #{topical_event_organisation.organisation.name}" - assert_select "a[href=?]", toggle_lead_admin_topical_event_topical_event_organisation_path(@topical_event, topical_event_organisation), text: "Make #{type == 'lead' ? 'supporting' : 'lead'} #{topical_event_organisation.organisation.name}" - end - end - end -end diff --git a/test/functional/admin/topical_events_controller_test.rb b/test/functional/admin/topical_events_controller_test.rb deleted file mode 100644 index f42bdebd15f..00000000000 --- a/test/functional/admin/topical_events_controller_test.rb +++ /dev/null @@ -1,195 +0,0 @@ -require "test_helper" - -class Admin::TopicalEventsControllerTest < ActionController::TestCase - setup do - login_as :writer - end - - should_be_an_admin_controller - - view_test "GET :show lists the topical event details" do - topical_event = create(:topical_event) - get :show, params: { id: topical_event } - - assert_response :success - assert_select "h1", topical_event.name - end - - view_test "GET :new renders topical event form" do - get :new - - assert_response :success - assert_select "input[name='topical_event[name]']" - end - - test "POST :create saves the topical event" do - assert_difference("TopicalEvent.count") do - post :create, params: { - topical_event: { - name: "Event", - description: "Event description", - summary: "Event summary", - logo_attributes: { - file: upload_fixture("images/960x640_jpeg.jpg"), - }, - }, - } - end - - assert_response :redirect - - topical_event = TopicalEvent.last - assert_equal "Event", topical_event.name - assert_equal "Event description", topical_event.description - assert topical_event.logo.present? - end - - test "POST :create uses the file cache if present" do - cached_logo = build(:featured_image_data, file: upload_fixture("images/960x640_jpeg.jpg")) - - post :create, params: { - topical_event: { - name: "Event", - description: "Event description", - summary: "Event summary", - logo_attributes: { - file_cache: cached_logo.file_cache, - }, - }, - } - - topical_event = TopicalEvent.last - assert_equal "960x640_jpeg.jpg", topical_event.logo.filename - end - - test "POST :create discards the file cache if file is present" do - cached_logo = build(:featured_image_data, file: upload_fixture("images/960x640_jpeg.jpg")) - - AssetManagerCreateAssetJob.expects(:perform_async).with(regexp_matches(/960x640_jpeg.jpg/), anything, anything, anything, anything, anything).never - AssetManagerCreateAssetJob.expects(:perform_async).with(regexp_matches(/big-cheese.960x640.jpg/), anything, anything, anything, anything, anything).times(7) - - post :create, params: { - topical_event: { - name: "Event", - description: "Event description", - summary: "Event summary", - logo_attributes: { - file: upload_fixture("big-cheese.960x640.jpg"), - file_cache: cached_logo.file_cache, - }, - }, - } - - topical_event = TopicalEvent.last - assert_equal "big-cheese.960x640.jpg", topical_event.logo.filename - end - - test "GET :index lists the topical events" do - topical_event_c = create(:topical_event, name: "Topic C") - topical_event_a = create(:topical_event, name: "Topic A") - topical_event_b = create(:topical_event, name: "Topic B") - - get :index - - assert_response :success - assert_equal(assigns(:topical_events), [topical_event_a, topical_event_b, topical_event_c]) - end - - view_test "GET :index page has the View link to show page" do - topical_event = create(:topical_event) - get :index - assert_select "a[href=?]", admin_topical_event_path(topical_event), text: /View/ - end - - view_test "GET :edit renders the topical event form" do - topical_event = create(:topical_event) - get :edit, params: { id: topical_event } - - assert_response :success - assert_select "input[name='topical_event[name]'][value='#{topical_event.name}']" - end - - view_test "GET :edit renders id for logo model if it exists" do - topical_event = create(:topical_event, :with_logo) - - get :edit, params: { id: topical_event } - - expected_hidden_field_name = "topical_event[logo_attributes][id]" - expected_hidden_field_value = topical_event.logo.id - assert_select "input[name='#{expected_hidden_field_name}'][value='#{expected_hidden_field_value}']" - end - - view_test "GET :edit shows processing label if logo assets are not available" do - topical_event = build(:topical_event, :with_logo) - topical_event.logo.assets = [] - topical_event.save! - - get :edit, params: { id: topical_event } - - assert_select "span[class='govuk-tag govuk-tag--green']", text: "Processing", count: 1 - end - - test "PUT :update saves changes to the topical event" do - topical_event = create(:topical_event, :with_logo) - logo = topical_event.logo - - put :update, params: { - id: topical_event, - topical_event: { - name: "New name", - logo_attributes: { - id: logo.id, - file: upload_fixture("images/960x640_jpeg.jpg"), - }, - }, - } - - assert_response :redirect - assert_equal "New name", topical_event.reload.name - assert_equal logo.id, topical_event.reload.logo.id - assert_equal "960x640_jpeg.jpg", topical_event.reload.logo.filename - end - - test "PUT :update discards the file cache if file is present" do - topical_event = create(:topical_event, :with_logo) - cached_logo = build(:featured_image_data, file: upload_fixture("images/960x640_jpeg.jpg")) - - AssetManagerCreateAssetJob.expects(:perform_async).with(regexp_matches(/960x640_jpeg.jpg/), anything, anything, anything, anything, anything).never - AssetManagerCreateAssetJob.expects(:perform_async).with(regexp_matches(/big-cheese.960x640.jpg/), anything, anything, anything, anything, anything).times(7) - - put :update, params: { - id: topical_event, - topical_event: { - logo_attributes: { - id: topical_event.logo.id, - file: upload_fixture("big-cheese.960x640.jpg"), - file_cache: cached_logo.file_cache, - }, - }, - } - - topical_event = TopicalEvent.last - assert_equal "big-cheese.960x640.jpg", topical_event.logo.filename - end - - test "GET :confirm_destroy calls correctly" do - topical_event = create(:topical_event) - - get :confirm_destroy, params: { id: topical_event.id } - - assert_response :success - assert_equal topical_event, assigns(:topical_event) - end - - test "DELETE :destroy deletes the topical event but keeps the logo image as some other pages might depend on it" do - topical_event = create(:topical_event, :with_logo, :with_social_media_accounts) - logo = topical_event.logo - social_media_account = topical_event.social_media_accounts.first - delete :destroy, params: { id: topical_event } - - assert_response :redirect - assert_nil TopicalEvent.find_by(id: topical_event.id) - assert_nil SocialMediaAccount.find_by(id: social_media_account.id) - assert FeaturedImageData.find_by(id: logo.id) - end -end diff --git a/test/integration/page_title_test.rb b/test/integration/page_title_test.rb index 7efe79d21de..887a3540120 100644 --- a/test/integration/page_title_test.rb +++ b/test/integration/page_title_test.rb @@ -3,8 +3,6 @@ class PageTitleTest < ActiveSupport::TestCase EXCLUDED_TEMPLATES = %w[ authentications/failure.html.erb - admin/topical_event_about_pages/edit.html.erb - admin/topical_event_about_pages/new.html.erb admin/edition_audit_trail/index.html.erb admin/preview/preview.html.erb layouts/home.html.erb diff --git a/test/integration/topical_event_about_page_test.rb b/test/integration/topical_event_about_page_test.rb deleted file mode 100644 index 237628bb710..00000000000 --- a/test/integration/topical_event_about_page_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "test_helper" -require "gds_api/test_helpers/publishing_api" - -class TopicalEventAboutPageTest < ActiveSupport::TestCase - setup do - stub_any_publishing_api_call - @topical_event_about_page = build(:topical_event_about_page) - end - - test "TopicalEventAboutPage is published to the Publishing API on save" do - Sidekiq::Testing.inline! do - presenter = PublishingApiPresenters.presenter_for(@topical_event_about_page) - - @topical_event_about_page.save! - - expected_json = presenter.content.merge( - # This is to simulate what the time public timestamp will be after the - # page has been published - public_updated_at: Time.zone.now.as_json, - ) - - assert_publishing_api_put_content(@topical_event_about_page.content_id, expected_json) - assert_publishing_api_publish( - @topical_event_about_page.content_id, - { - update_type: nil, - locale: "en", - }, - 1, - ) - end - end - - test "TopicalEventAboutPage publishes gone route to the Publishing API on destroy" do - Sidekiq::Testing.inline! do - @topical_event_about_page.save! - - gone_request = stub_publishing_api_unpublish( - @topical_event_about_page.content_id, - body: { - type: "gone", - locale: "en", - discard_drafts: true, - }, - ) - - @topical_event_about_page.destroy! - assert_requested gone_request - end - end - - test "TopicalEventAboutPage is published to the Publishing API when updated" do - Sidekiq::Testing.inline! do - @topical_event_about_page.save! - @topical_event_about_page.read_more_link_text = "New read more link text" - @topical_event_about_page.save! - presenter = PublishingApiPresenters.presenter_for(@topical_event_about_page) - - expected_json = presenter.content.merge( - # This is to simulate what the time public timestamp will be after the - # page has been published - public_updated_at: Time.zone.now.as_json, - ) - - assert_publishing_api_put_content(@topical_event_about_page.content_id, expected_json) - assert_publishing_api_publish( - @topical_event_about_page.content_id, - { - update_type: nil, - locale: "en", - }, - 2, - ) - end - end -end diff --git a/test/support/admin_edition_controller_test_helpers.rb b/test/support/admin_edition_controller_test_helpers.rb index e11614f4662..94a8c4a06ff 100644 --- a/test/support/admin_edition_controller_test_helpers.rb +++ b/test/support/admin_edition_controller_test_helpers.rb @@ -1011,81 +1011,8 @@ def should_allow_access_limiting_of(edition_type) end end - def should_allow_association_with_topical_events(edition_type) - edition_class = class_for(edition_type) - - view_test "new should display topical events field" do - get :new - - assert_select "form#new_edition" do - assert_select "label[for=edition_topical_event_ids]", text: "Topical events" - - assert_select "#edition_topical_event_ids" do |elements| - assert_equal 1, elements.length - end - end - end - - test "create should associate topical events with the edition" do - first_topical_event = create(:topical_event) - second_topical_event = create(:topical_event) - attributes = controller_attributes_for(edition_type) - - post :create, - params: { - edition: attributes.merge( - topical_event_ids: [first_topical_event.id, second_topical_event.id], - ), - } - - edition = edition_class.last! - assert_equal [first_topical_event, second_topical_event], edition.topical_events - end - - view_test "edit should display topical events field" do - edition = create("draft_#{edition_type}") - - get :edit, params: { id: edition } - - assert_select "form#edit_edition" do - assert_select "label[for=edition_topical_event_ids]", text: "Topical events" - - assert_select "#edition_topical_event_ids" do |elements| - assert_equal 1, elements.length - end - end - end - - test "update should associate topical events with the edition" do - first_topical_event = create(:topical_event) - second_topical_event = create(:topical_event) - - edition = create("draft_#{edition_type}", topical_events: [first_topical_event]) - - put :update, - params: { - id: edition, - edition: { - topical_event_ids: [second_topical_event.id], - }, - } - - edition.reload - assert_equal [second_topical_event], edition.topical_events - end - end - def should_allow_association_with_topical_event_documents_when_configurable_document_types_enabled(edition_type) edition_class = class_for(edition_type) - view_test "new should not display topical event documents field" do - get :new - - assert_select "form#new_edition" do - assert_select "label[for=edition_topical_event_document_ids]", text: "Topical events (experimental)", count: 0 - assert_select "#edition_topical_event_document_ids", count: 0 - end - end - view_test "new should display topical event documents field" do test_strategy = Flipflop::FeatureSet.current.test! test_strategy.switch!(:configurable_document_types, true) @@ -1094,7 +1021,7 @@ def should_allow_association_with_topical_event_documents_when_configurable_docu get :new assert_select "form#new_edition" do - assert_select "label[for=edition_topical_event_document_ids]", text: "Topical events (experimental)" + assert_select "label[for=edition_topical_event_document_ids]", text: "Topical events" assert_select "#edition_topical_event_document_ids" do |elements| assert_equal 1, elements.length @@ -1134,7 +1061,7 @@ def should_allow_association_with_topical_event_documents_when_configurable_docu get :edit, params: { id: edition } assert_select "form#edit_edition" do - assert_select "label[for=edition_topical_event_document_ids]", text: "Topical events (experimental)" + assert_select "label[for=edition_topical_event_document_ids]", text: "Topical events" assert_select "#edition_topical_event_document_ids" do |elements| assert_equal 1, elements.length diff --git a/test/support/css_selectors.rb b/test/support/css_selectors.rb index 2f8f7dd0045..f3501e784a7 100644 --- a/test/support/css_selectors.rb +++ b/test/support/css_selectors.rb @@ -49,10 +49,6 @@ def organisation_type_list_selector "select[name='organisation[organisation_type_id]']" end - def organisation_topics_list_selector - "select[name='organisation[topical_event_organisations_attributes][][topical_event_id]']" - end - def organisation_govuk_status_selector "select[name='organisation[govuk_status]']" end diff --git a/test/unit/app/helpers/admin/organisation_helper_test.rb b/test/unit/app/helpers/admin/organisation_helper_test.rb index 40cdc6f7ce4..8be3489b3c8 100644 --- a/test/unit/app/helpers/admin/organisation_helper_test.rb +++ b/test/unit/app/helpers/admin/organisation_helper_test.rb @@ -1,24 +1,6 @@ require "test_helper" class Admin::OrganisationHelperTest < ActionView::TestCase - test "#topical_event_dates_string handles a topical event with a start date but no end date" do - topical_event = create(:topical_event, start_date: Time.zone.today) - - assert_equal "11 November 2011", topical_event_dates_string(topical_event) - end - - test "#topical_event_dates_string handles a topical event with start and end dates" do - topical_event = create(:topical_event, start_date: Time.zone.today, end_date: Time.zone.today + 1.week) - - assert_equal "11 November 2011 to 18 November 2011", topical_event_dates_string(topical_event) - end - - test "#topical_event_dates_string handles a topical event with no dates" do - topical_event = create(:topical_event) - - assert_equal "", topical_event_dates_string(topical_event) - end - test "#organisation_nav_items when organisation doesn't have a translation" do organisation = build_stubbed(:organisation) current_path = admin_organisation_corporate_information_pages_path(organisation) diff --git a/test/unit/app/helpers/admin/taggable_content_helper_test.rb b/test/unit/app/helpers/admin/taggable_content_helper_test.rb index bd15da154fe..0aaf00d1dcb 100644 --- a/test/unit/app/helpers/admin/taggable_content_helper_test.rb +++ b/test/unit/app/helpers/admin/taggable_content_helper_test.rb @@ -1,19 +1,6 @@ require "test_helper" class Admin::TaggableContentHelperTest < ActionView::TestCase - test "#taggable_topical_events_container returns an array of select options for all topical events ordered by name" do - event_c = create(:topical_event, name: "event C") - event_b = create(:topical_event, name: "event B") - event_a = create(:topical_event, name: "event A") - - assert_equal [ - { text: "event A", value: event_a.id, selected: false }, - { text: "event B", value: event_b.id, selected: true }, - { text: "event C", value: event_c.id, selected: false }, - ], - taggable_topical_events_container([event_b.id]) - end - test "#taggable_topical_event_documents_container returns an array of select options for all topical event documents" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) event_c = create(:standard_edition, title: "event C", configurable_document_type: "topical_event") diff --git a/test/unit/app/models/admin/edition_filter_test.rb b/test/unit/app/models/admin/edition_filter_test.rb index ac17cd62644..963d6eaabd1 100644 --- a/test/unit/app/models/admin/edition_filter_test.rb +++ b/test/unit/app/models/admin/edition_filter_test.rb @@ -222,15 +222,6 @@ class Admin::EditionFilterTest < ActiveSupport::TestCase assert_equal [newer_publication], Admin::EditionFilter.new(Edition, @current_user, from_date: 2.days.ago.to_date.to_fs(:short)).editions end - test "can filter by topical_events" do - topical_event = create(:topical_event) - tagged_news = create(:published_publication, topical_events: [topical_event]) - _not_tagged = create(:published_publication) - filter = Admin::EditionFilter.new(Edition, @current_user, topical_event: topical_event.to_param) - - assert_equal [tagged_news], filter.editions - end - test "should filter by invalid, non-superseded editions" do # rubocop:disable Lint/UselessAssignment valid_draft_edition = create(:draft_edition, revalidated_at: Time.zone.now) diff --git a/test/unit/app/models/call_for_evidence_test.rb b/test/unit/app/models/call_for_evidence_test.rb index 40fc81e209b..e66925b5f67 100644 --- a/test/unit/app/models/call_for_evidence_test.rb +++ b/test/unit/app/models/call_for_evidence_test.rb @@ -306,15 +306,6 @@ class CallForEvidenceTest < ActiveSupport::TestCase assert_equal "Call for evidence outcome", call_for_evidence.display_type end - # To be deleted after legacy topical events have been migrated. - # It has a config-driven equivalent test below it which should be kept. - test "can associate calls for evidence with (legacy) topical events" do - call_for_evidence = create(:call_for_evidence) - assert call_for_evidence.can_be_associated_with_topical_events? - assert topical_event = call_for_evidence.topical_events.create!(name: "Test", description: "Test", summary: "Test") - assert_equal [topical_event], call_for_evidence.reload.topical_events - end - test "can associate calls for evidence with topical events" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) call_for_evidence = create(:call_for_evidence) diff --git a/test/unit/app/models/consultation_test.rb b/test/unit/app/models/consultation_test.rb index 3a31527c025..952586e438d 100644 --- a/test/unit/app/models/consultation_test.rb +++ b/test/unit/app/models/consultation_test.rb @@ -346,15 +346,6 @@ class ConsultationTest < ActiveSupport::TestCase assert_equal "Consultation outcome", consultation.display_type end - # To be deleted after legacy topical events have been migrated. - # It has a config-driven equivalent test below it which should be kept. - test "can associate consultations with (legacy) topical events" do - consultation = create(:consultation) - assert consultation.can_be_associated_with_topical_events? - assert topical_event = consultation.topical_events.create!(name: "Test", description: "Test", summary: "Test") - assert_equal [topical_event], consultation.reload.topical_events - end - test "can associate consultations with topical events" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) consultation = create(:consultation) diff --git a/test/unit/app/models/detailed_guide_test.rb b/test/unit/app/models/detailed_guide_test.rb index 61b76aa3f5a..f362b7719b6 100644 --- a/test/unit/app/models/detailed_guide_test.rb +++ b/test/unit/app/models/detailed_guide_test.rb @@ -61,15 +61,6 @@ class DetailedGuideTest < ActiveSupport::TestCase assert guide.has_additional_related_mainstream_content? end - # To be deleted after legacy topical events have been migrated. - # It has a config-driven equivalent test below it which should be kept. - test "can be associated with (legacy) topical events" do - detailed_guide = create(:detailed_guide) - assert detailed_guide.can_be_associated_with_topical_events? - assert topical_event = detailed_guide.topical_events.create!(name: "Test", description: "Test", summary: "Test") - assert_equal [topical_event], detailed_guide.reload.topical_events - end - test "can associate detailed guides with topical events" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) detailed_guide = create(:detailed_guide) diff --git a/test/unit/app/models/edition/topical_events_test.rb b/test/unit/app/models/edition/topical_events_test.rb deleted file mode 100644 index 95481d53f94..00000000000 --- a/test/unit/app/models/edition/topical_events_test.rb +++ /dev/null @@ -1,87 +0,0 @@ -require "test_helper" - -class Edition::TopicalEventsTest < ActiveSupport::TestCase - # Legacy - to be deleted when we migrate to config-driven topical events. - test "#destroy should also remove the topical event membership relationship" do - topical_event = create(:topical_event) - edition = create(:published_speech, topical_events: [topical_event]) - relation = edition.topical_event_memberships.first - edition.destroy! - assert_not TopicalEventMembership.find_by(id: relation.id) - end - - # Legacy - to be deleted when we migrate to config-driven topical events. - test "new edition of document that is a member of a topical event should remain a member of that topical event" do - topical_event = create(:topical_event) - edition = create(:published_speech, topical_events: [topical_event]) - - new_edition = edition.create_draft(create(:writer)) - new_edition.change_note = "change-note" - force_publish(new_edition) - - assert_equal topical_event, new_edition.topical_events.first - end - - # Legacy - to be deleted when we migrate to config-driven topical events. - test "#destroy should also remove the topical event featuring relationship" do - topical_event = create(:topical_event) - edition = create(:published_speech) - _rel = topical_event.feature(edition_id: edition.id, alt_text: "Woooo", image: create(:topical_event_featuring_image_data)) - relation = edition.topical_event_featurings.first - edition.destroy! - assert_not TopicalEventFeaturing.find_by(id: relation.id) - end - - # Legacy - to be deleted when we migrate to config-driven topical events. - test "new edition of document featured in topical event should remain featured in that topic event with image, alt text and ordering" do - featured_image = create(:topical_event_featuring_image_data) - topical_event = create(:topical_event) - edition = create(:published_speech) - topical_event.feature(edition_id: edition.id, image: featured_image, alt_text: "alt-text", ordering: 12) - - new_edition = edition.create_draft(create(:writer)) - new_edition.change_note = "change-note" - force_publish(new_edition) - - featuring = new_edition.topical_event_featurings.first - assert featuring.persisted? - assert_equal featured_image, featuring.image - assert_equal "alt-text", featuring.alt_text - assert_equal 12, featuring.ordering - assert_equal topical_event, featuring.topical_event - end - - test "new edition of document that is associated with a topical event document should retain that association" do - ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - topical_event = create(:standard_edition, configurable_document_type: "topical_event") - edition = create(:published_speech, topical_event_documents: [topical_event.document]) - - new_edition = edition.create_draft(create(:writer)) - new_edition.change_note = "change-note" - force_publish(new_edition) - - assert_equal topical_event.document, new_edition.topical_event_documents.first - end - - test "can_be_associated_with_topical_events? returns true for legacy content types that include the module" do - self.class.const_set("DummyLegacyEdition", Class.new(Edition) do - include Edition::TopicalEvents - end) - - edition = DummyLegacyEdition.new - assert edition.can_be_associated_with_topical_events? - end - - test "can_be_associated_with_topical_events? can be overridden by the class that includes it (e.g. to make its return value config-driven)" do - self.class.const_set("DummyStandardEdition", Class.new(Edition) do - include Edition::TopicalEvents - - def can_be_associated_with_topical_events? - false - end - end) - - edition = DummyStandardEdition.new - assert_not edition.can_be_associated_with_topical_events? - end -end diff --git a/test/unit/app/models/edition_test.rb b/test/unit/app/models/edition_test.rb index 481dee9d666..afe70a70a54 100644 --- a/test/unit/app/models/edition_test.rb +++ b/test/unit/app/models/edition_test.rb @@ -846,15 +846,6 @@ class EditionTest < ActiveSupport::TestCase assert_equal [], non_attachable_edition.attachables end - test "republishes a linked Topical Event when the edition is changed" do - edition = create(:edition, :draft) - topical_event = create(:topical_event, :active) - create(:topical_event_featuring, topical_event:, edition:) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event).once - edition.update!(title: "some updated title") - end - test "#versioning_completed? returns true if change note is not required" do edition = build(:edition, change_note: nil, minor_change: false) edition.stubs(:change_note_required?).returns(false) diff --git a/test/unit/app/models/offsite_link_test.rb b/test/unit/app/models/offsite_link_test.rb index 5b21a9b3046..99a862f277f 100644 --- a/test/unit/app/models/offsite_link_test.rb +++ b/test/unit/app/models/offsite_link_test.rb @@ -135,13 +135,9 @@ class OffsiteLinkTest < ActiveSupport::TestCase end test "#parents returns all associated parents" do - offsite_link_for_legacy_document = create(:offsite_link, :for_topical_event) - topical_event = offsite_link_for_legacy_document.topical_events.first - offsite_link_for_standard_edition = create(:offsite_link, :for_standard_edition) standard_edition = offsite_link_for_standard_edition.editions.first - assert_equal [topical_event], offsite_link_for_legacy_document.parents assert_equal [standard_edition], offsite_link_for_standard_edition.parents end diff --git a/test/unit/app/models/organisation_test.rb b/test/unit/app/models/organisation_test.rb index 03336d0446a..c08735a821f 100644 --- a/test/unit/app/models/organisation_test.rb +++ b/test/unit/app/models/organisation_test.rb @@ -382,14 +382,6 @@ class OrganisationTest < ActiveSupport::TestCase assert_equal 0, EditionOrganisation.count end - test "destroy removes topical_event relationships" do - organisation = create(:organisation) - topical_event = create(:topical_event) - topical_event.organisations << organisation - organisation.destroy! - assert_equal 0, TopicalEventOrganisation.count - end - test "destroy unsets user organisation" do organisation = create(:organisation) user = create(:writer, organisation:) @@ -485,15 +477,6 @@ class OrganisationTest < ActiveSupport::TestCase assert_equal "FOO123", organisation.reload.analytics_identifier end - test "topical_events are explicitly ordered" do - topical_events = [create(:topical_event), create(:topical_event)] - organisation = create(:organisation) - organisation.topical_event_organisations.create!(topical_event_id: topical_events[0].id, ordering: 2) - organisation.topical_event_organisations.create!(topical_event_id: topical_events[1].id, ordering: 1) - assert_match %r{order by}i, organisation.topical_events.to_sql - assert_equal [topical_events[1], topical_events[0]], organisation.topical_events - end - test "destroy deletes related contacts" do organisation = create(:organisation) contact = create(:contact, contactable: organisation) diff --git a/test/unit/app/models/publication_test.rb b/test/unit/app/models/publication_test.rb index 434e13d34e3..97df0f2c8a0 100644 --- a/test/unit/app/models/publication_test.rb +++ b/test/unit/app/models/publication_test.rb @@ -147,15 +147,6 @@ class PublicationTest < ActiveSupport::TestCase assert_not build(:publication, primary_locale: :es).translatable? end - # To be deleted after legacy topical events have been migrated. - # It has a config-driven equivalent test below it which should be kept. - test "can associate publications with (legacy) topical events" do - publication = create(:publication) - assert publication.can_be_associated_with_topical_events? - assert topical_event = publication.topical_events.create!(name: "Test", description: "Test", summary: "Test") - assert_equal [topical_event], publication.reload.topical_events - end - test "can associate publications with topical events" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) publication = create(:publication) diff --git a/test/unit/app/models/simple_workflow_test.rb b/test/unit/app/models/simple_workflow_test.rb deleted file mode 100644 index f8cadb5b08a..00000000000 --- a/test/unit/app/models/simple_workflow_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require "test_helper" - -class SimpleWorkflowTest < ActiveSupport::TestCase - test "should be current when newly created" do - assert_equal :current, create(:topical_event).current_state - end - - test "should call destroyable? when trying to delete" do - topic = create(:topical_event) - topic.stubs(:destroyable?).returns(true) - topic.delete! - assert_equal :deleted, topic.reload.current_state - end - - test "should not delete if destroyable returns false" do - topic = create(:topical_event) - topic.stubs(:destroyable?).returns(false) - topic.delete! - assert_equal :current, topic.current_state - end - - test "should remove from search index on delete if Searchable is included" do - topic = create(:topical_event) - Whitehall::SearchIndex.expects(:delete).with(topic) - topic.delete! - assert_equal :deleted, topic.current_state - end - - test "should not call search_api if Searchable is not included" do - topic = create(:topical_event) - TopicalEvent.any_instance.stubs(:remove_from_search_index).returns(NameError) - Whitehall::SearchIndex.expects(:delete).never - topic.delete! - assert_equal :deleted, topic.current_state - end - - test "should exclude deleted topics by default" do - current_topic = create(:topical_event) - create(:topical_event, state: "deleted") - assert_equal [current_topic], TopicalEvent.all - end -end diff --git a/test/unit/app/models/speech_test.rb b/test/unit/app/models/speech_test.rb index 17c628a931b..9587bf298b4 100644 --- a/test/unit/app/models/speech_test.rb +++ b/test/unit/app/models/speech_test.rb @@ -111,13 +111,6 @@ class SpeechTest < ActiveSupport::TestCase assert_not build(:speech, role_appointment: build(:board_member_role_appointment)).delivered_by_minister? end - test "can associate a speech with a (legacy) topical event" do - speech = create(:speech) - speech.topical_events << TopicalEvent.new(name: "foo", description: "bar", summary: "test") - assert speech.can_be_associated_with_topical_events? - assert_equal 1, speech.topical_events.size - end - test "can associate publications with topical events" do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) speech = create(:speech) diff --git a/test/unit/app/models/standard_edition_test.rb b/test/unit/app/models/standard_edition_test.rb index 488f9242484..6c94c5edf02 100644 --- a/test/unit/app/models/standard_edition_test.rb +++ b/test/unit/app/models/standard_edition_test.rb @@ -459,32 +459,6 @@ class StandardEditionTest < ActiveSupport::TestCase assert_not StandardEdition.new(configurable_document_type: "test_type_without_topical_events").can_be_associated_with_topical_events? end - # Legacy: delete when topical events have been migrated - test "it allows topical event associations if the configurable document type configuration references legacy topical events" do - test_type_with_legacy_topical_events = - build_configurable_document_type( - "test_type_with_legacy_topical_events", { - "forms" => { - "documents" => { - "fields" => { - "topical_events" => { - "title" => "Topical events", - "block" => "select_with_search_tagging", - "container" => "topical_events", - "attribute_path" => %w[topical_event_ids], - "translatable" => false, - }, - }, - }, - }, - } - ) - - ConfigurableDocumentType.setup_test_types(test_type_with_legacy_topical_events) - - assert StandardEdition.new(configurable_document_type: "test_type_with_legacy_topical_events").can_be_associated_with_topical_events? - end - test "conditionally requires worldwide organisation and world location associations" do test_type = build_configurable_document_type( "test_type", { diff --git a/test/unit/app/models/topical_event_about_page_test.rb b/test/unit/app/models/topical_event_about_page_test.rb deleted file mode 100644 index 183a70db520..00000000000 --- a/test/unit/app/models/topical_event_about_page_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "test_helper" - -class TopicalEventAboutPageTest < ActiveSupport::TestCase - test "public_path returns the correct path" do - object = create(:topical_event, slug: "foo", topical_event_about_page: create(:topical_event_about_page)) - assert_equal "/government/topical-events/foo/about", object.topical_event_about_page.public_path - end - - test "public_path returns the correct path with options" do - object = create(:topical_event, slug: "foo", topical_event_about_page: create(:topical_event_about_page)) - assert_equal "/government/topical-events/foo/about?cachebust=123", object.topical_event_about_page.public_path(cachebust: "123") - end - - test "public_url returns the correct path with options" do - object = create(:topical_event, slug: "foo", topical_event_about_page: create(:topical_event_about_page)) - assert_equal "https://www.test.gov.uk/government/topical-events/foo/about?cachebust=123", object.topical_event_about_page.public_url(cachebust: "123") - end - - should_not_accept_footnotes_in :body - - test "republishes topical event when its about page is created" do - topical_event = create(:topical_event) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event) - - create(:topical_event_about_page, topical_event:) - end - - test "republishes topical event when its about page is updated" do - topical_event = create(:topical_event) - about_page = create(:topical_event_about_page, topical_event:) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event) - - about_page.save! - end - - test "republishes topical event when its about page is destroyed" do - topical_event = create(:topical_event) - about_page = create(:topical_event_about_page, topical_event:) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event) - - about_page.destroy! - end -end diff --git a/test/unit/app/models/topical_event_featuring_image_data_test.rb b/test/unit/app/models/topical_event_featuring_image_data_test.rb deleted file mode 100644 index 0dfe0d0b341..00000000000 --- a/test/unit/app/models/topical_event_featuring_image_data_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "test_helper" - -class TopicalEventFeaturingImageDataTest < ActiveSupport::TestCase - test "rejects SVG logo uploads" do - svg_image = File.open(Rails.root.join("test/fixtures/images/test-svg.svg")) - image_data = build(:topical_event_featuring_image_data, file: svg_image) - - assert_not image_data.valid? - assert_includes image_data.errors.map(&:full_message), "File is of not allowed type \"svg\", allowed types: jpg, jpeg, gif, png" - end - - test "rejects non-image file uploads" do - non_image_file = File.open(Rails.root.join("test/fixtures/folders.zip")) - topical_event_featuring_image_data = build(:topical_event_featuring_image_data, file: non_image_file) - - assert_not topical_event_featuring_image_data.valid? - assert_includes topical_event_featuring_image_data.errors.map(&:full_message), "File is of not allowed type \"zip\", allowed types: jpg, jpeg, gif, png" - end - - test "accepts valid image uploads" do - jpg_image = File.open(Rails.root.join("test/fixtures/big-cheese.960x640.jpg")) - topical_event_featuring_image_data = build(:topical_event_featuring_image_data, file: jpg_image) - - assert topical_event_featuring_image_data - assert_empty topical_event_featuring_image_data.errors - end - - test "#all_asset_variants_uploaded? returns true if all assets present" do - topical_event_featuring_image_data = build(:topical_event_featuring_image_data) - - assert topical_event_featuring_image_data.all_asset_variants_uploaded? - end - - test "#all_asset_variants_uploaded? returns false if an asset variant is missing" do - topical_event_featuring_image_data = build(:topical_event_featuring_image_data) - topical_event_featuring_image_data.assets = [] - - assert_not topical_event_featuring_image_data.all_asset_variants_uploaded? - end - - test "should republish topical event when assets are ready" do - topical_event = create(:topical_event) - topical_event_featuring = topical_event.feature(image: build(:topical_event_featuring_image_data)) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event).once - - topical_event_featuring.image.republish_on_assets_ready - end -end diff --git a/test/unit/app/models/topical_event_featuring_test.rb b/test/unit/app/models/topical_event_featuring_test.rb deleted file mode 100644 index 6ce3c76bea2..00000000000 --- a/test/unit/app/models/topical_event_featuring_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class TopicalEventFeaturingTest < ActiveSupport::TestCase - include ActionDispatch::TestProcess - - test "should build an image using nested attributes" do - topical_event_featuring = build(:topical_event_featuring) - topical_event_featuring.image_attributes = { - file: upload_fixture("minister-of-funk.960x640.jpg", "image/jpg"), - } - topical_event_featuring.save! - - topical_event_featuring = TopicalEventFeaturing.find(topical_event_featuring.id) - - assert_match(/minister-of-funk/, topical_event_featuring.image.file.url) - end - - test "republishes a linked Topical Event when the feature is changed" do - topical_event = create(:topical_event, :active) - feature = create(:topical_event_featuring, topical_event:) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event).once - feature.update!(alt_text: "some updated text") - end - - test "republishes a linked Topical Event when the feature is deleted" do - topical_event = create(:topical_event, :active) - feature = create(:topical_event_featuring, topical_event:) - - Whitehall::PublishingApi.expects(:republish_async).with(topical_event).once - feature.destroy! - end - - test "is not valid without an image" do - feature = build(:topical_event_featuring) - feature.image = nil - - assert_not feature.valid? - end -end diff --git a/test/unit/app/models/topical_event_test.rb b/test/unit/app/models/topical_event_test.rb deleted file mode 100644 index 22db66aec46..00000000000 --- a/test/unit/app/models/topical_event_test.rb +++ /dev/null @@ -1,283 +0,0 @@ -require "test_helper" - -class TopicalEventTest < ActiveSupport::TestCase - should_protect_against_xss_and_content_attacks_on :topical_event, :name, :description - - test "includes PublishesToPublishingApi" do - topical_event = TopicalEvent.new - assert topical_event.is_a?(PublishesToPublishingApi) - end - - test "should be invalid without a name" do - topical_event = build(:topical_event, name: nil) - assert_not topical_event.valid? - end - - test "should be invalid without a summary" do - topical_event = build(:topical_event, summary: nil) - assert_not topical_event.valid? - end - - test "should be invalid with an unsupported state" do - topical_event = build(:topical_event, state: "foobar") - assert_not topical_event.valid? - end - - test "should be invalid without a unique name" do - existing_topical_event = create(:topical_event) - new_topical_event = build(:topical_event, name: existing_topical_event.name) - assert_not new_topical_event.valid? - end - - test "should be invalid without a description" do - topical_event = build(:topical_event, description: nil) - assert_not topical_event.valid? - end - - test "#latest should return specified number of associated published editions in reverse chronological order" do - ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type")) - - topical_event = create(:topical_event) - other_topical_event = create(:topical_event) - expected_order = [ - create(:published_publication, topical_events: [topical_event], first_published_at: 1.day.ago), - create(:published_standard_edition, topical_events: [topical_event], first_published_at: 1.week.ago), - create(:published_publication, topical_events: [topical_event], first_published_at: 2.weeks.ago), - create(:published_standard_edition, topical_events: [topical_event], first_published_at: 3.weeks.ago), - create(:published_publication, topical_events: [topical_event], first_published_at: 4.weeks.ago), - ] - create(:draft_speech, topical_events: [topical_event], first_published_at: 2.days.ago) - create(:published_speech, topical_events: [other_topical_event], first_published_at: 2.days.ago) - - assert_equal expected_order, topical_event.latest(10) - end - - test "an unfeatured edition is not featured" do - topical_event = create(:topical_event) - edition = build(:publication) - assert_not topical_event.featured?(edition) - end - - test "a featured edition is featured" do - topical_event = create(:topical_event) - edition = create(:published_publication) - image = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition.id, alt_text: "A thing", image:) - featuring = topical_event.featuring_of(edition) - assert featuring - assert_equal 0, featuring.ordering - assert topical_event.featured?(edition) - end - - test "a featured edition is no longer featured when it is superseded" do - topical_event = create(:topical_event) - edition = create(:published_speech) - image = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition.id, alt_text: "A thing", image:) - edition.supersede! - - featuring = topical_event.reload.featuring_of(edition) - assert_not featuring - assert_not topical_event.featured?(edition) - end - - test "#featured_editions returns featured editions by ordering" do - topical_event = create(:topical_event) - _alpha = topical_event.feature(edition_id: create(:edition, title: "Alpha").id, ordering: 1, alt_text: "A thing", image: create(:topical_event_featuring_image_data)) - beta = topical_event.feature(edition_id: create(:published_publication, title: "Beta").id, ordering: 2, alt_text: "A thing", image: create(:topical_event_featuring_image_data)) - gamma = topical_event.feature(edition_id: create(:published_publication, title: "Gamma").id, ordering: 3, alt_text: "A thing", image: create(:topical_event_featuring_image_data)) - delta = topical_event.feature(edition_id: create(:published_publication, title: "Delta").id, ordering: 0, alt_text: "A thing", image: create(:topical_event_featuring_image_data)) - - assert_equal [delta.edition, beta.edition, gamma.edition], topical_event.featured_editions - end - - test "#featured_editions includes the newly published version of a featured edition, but not the original" do - topical_event = create(:topical_event) - old_version = topical_event.feature(edition_id: create(:published_publication, title: "Gamma").id, ordering: 3, alt_text: "A thing", image: create(:topical_event_featuring_image_data)).edition - - editor = create(:departmental_editor) - new_version = old_version.create_draft(editor) - new_version.change_note = "New stuffs!" - new_version.save! - force_publish(new_version) - - assert_not topical_event.featured_editions.include?(old_version) - assert topical_event.featured_editions.include?(new_version) - end - - test "#next_ordering gives a value of 0 when there are no existing features" do - topical_event = create(:topical_event) - - assert_equal 0, topical_event.next_ordering - end - - test "#next_ordering gives the next value when there are existing features" do - topical_event = create(:topical_event) - - edition_1 = create(:published_publication) - image_1 = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition_1.id, alt_text: "A thing", image: image_1) - - edition_2 = create(:published_publication) - image_2 = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition_2.id, alt_text: "A thing", image: image_2) - - assert_equal 2, topical_event.next_ordering - end - - test "#next_ordering gives the next value when there are existing features that have been reordered" do - topical_event = create(:topical_event) - - edition_1 = create(:published_publication) - image_1 = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition_1.id, alt_text: "A thing", image: image_1, ordering: 1) - - edition_2 = create(:published_publication) - image_2 = create(:topical_event_featuring_image_data) - topical_event.feature(edition_id: edition_2.id, alt_text: "A thing", image: image_2, ordering: 0) - - assert_equal 2, topical_event.next_ordering - end - - should_not_accept_footnotes_in :description - - test "should include slug in search_index data" do - topical_event = create(:topical_event, name: "mazzops 2013") - assert_equal "mazzops-2013", topical_event.search_index["slug"] - end - - test "should not last more than a year" do - topical_event = build(:topical_event, start_date: 3.days.ago.to_date, end_date: (Time.zone.today + 1.year)) - assert_not topical_event.valid? - end - - test "requires a start_date if end_date is set" do - topical_event = build(:topical_event, end_date: (Time.zone.today + 1.year)) - assert_not topical_event.valid? - end - - test "can be a year long" do - topical_event = build(:topical_event, start_date: Time.zone.today, end_date: (Time.zone.today + 1.year)) - assert topical_event.valid? - end - - test "can be a year with a day leeway" do - topical_event = build(:topical_event, start_date: 1.day.ago.to_date, end_date: (Time.zone.today + 1.year)) - assert topical_event.valid? - end - - test "should not end before it starts" do - topical_event = build(:topical_event, start_date: Time.zone.today, end_date: 1.day.ago.to_date) - assert_not topical_event.valid? - end - - test "should be longer than a day" do - topical_event = build(:topical_event, start_date: Time.zone.today, end_date: Time.zone.today) - assert_not topical_event.valid? - end - - test "start and end dates are considered indexable for search" do - start_date = Date.new(2016, 1, 1) - end_date = Date.new(2017, 1, 1) - topical_event = create(:topical_event, start_date:, end_date:) - search_api_payload = topical_event.search_index - - assert_equal start_date, search_api_payload["start_date"] - assert_equal end_date, search_api_payload["end_date"] - end - - test "#destroy also destroys 'featured topical event' associations" do - topical_event = create(:topical_event) - feature = create(:feature, topical_event:) - feature_list = create(:feature_list, features: [feature]) - - feature_list.reload - assert_equal 1, feature_list.features.size - - topical_event.destroy! - - feature_list.reload - assert_equal 0, feature_list.features.size - end - - test "#save republishes any organisations that feature the topical event" do - topical_event = create(:topical_event) - organisation = create(:organisation, :with_feature_list) - - create(:feature, feature_list: organisation.feature_lists.first, topical_event:) - - Whitehall::PublishingApi.expects(:publish).with(topical_event).once - Whitehall::PublishingApi.expects(:republish_async).with(organisation).once - - topical_event.save! - end - - test "public_path returns the correct path" do - object = create(:topical_event, slug: "foo") - assert_equal "/government/topical-events/foo", object.public_path - end - - test "public_path returns the correct path with options" do - object = create(:topical_event, slug: "foo") - assert_equal "/government/topical-events/foo?cachebust=123", object.public_path(cachebust: "123") - end - - test "public_url returns the correct path" do - object = create(:topical_event, slug: "foo") - assert_equal "https://www.test.gov.uk/government/topical-events/foo", object.public_url - end - - test "public_url returns the correct path with options" do - object = create(:topical_event, slug: "foo") - assert_equal "https://www.test.gov.uk/government/topical-events/foo?cachebust=123", object.public_url(cachebust: "123") - end - - test "#featurable_offsite_links returns associated offsite links that do not belong to a topical event featuring" do - topical_event = build(:topical_event) - offsite_link1 = build(:offsite_link) - offsite_link2 = build(:offsite_link) - topical_event_featuring = build(:topical_event_featuring, offsite_link: offsite_link1) - - topical_event.stubs(:offsite_links).returns([offsite_link1, offsite_link2]) - topical_event.stubs(:topical_event_featurings).returns([topical_event_featuring]) - - assert_equal [offsite_link2], topical_event.featurable_offsite_links - end - - test "#featurable_editions returns editions that do not belong to a topical event featuring" do - topical_event = build(:topical_event) - edition1 = build(:edition) - edition2 = build(:edition) - topical_event_featuring = build(:topical_event_featuring, edition: edition1) - - topical_event.stubs(:editions).returns([edition1, edition2]) - topical_event.stubs(:topical_event_featurings).returns([topical_event_featuring]) - - assert_equal [edition2], topical_event.featurable_editions([edition1, edition2]) - end - - test "rejects SVG logo uploads" do - svg_logo = File.open(Rails.root.join("test/fixtures/images/test-svg.svg")) - logo = build(:featured_image_data, file: svg_logo) - topical_event = build(:topical_event, logo:) - - assert_not topical_event.valid? - assert_equal topical_event.errors.first.full_message, "Logo file is of not allowed type \"svg\", allowed types: jpg, jpeg, gif, png" - end - - test "rejects non-image file uploads" do - non_image_file = File.open(Rails.root.join("test/fixtures/folders.zip")) - logo = build(:featured_image_data, file: non_image_file) - topical_event = build(:topical_event, logo:) - - assert_not topical_event.valid? - assert_includes topical_event.errors.map(&:full_message), "Logo file is of not allowed type \"zip\", allowed types: jpg, jpeg, gif, png" - end - - test "accepts valid image uploads" do - topical_event = build(:topical_event, :with_logo) - - assert topical_event - assert_empty topical_event.errors - end -end diff --git a/test/unit/app/presenters/publishing_api/call_for_evidence_presenter_test.rb b/test/unit/app/presenters/publishing_api/call_for_evidence_presenter_test.rb index 6beb978a368..a3f855c2a80 100644 --- a/test/unit/app/presenters/publishing_api/call_for_evidence_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/call_for_evidence_presenter_test.rb @@ -576,14 +576,11 @@ class CallForEvidenceWithTopicalEvents < TestCase ) ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - topical_event = create(:topical_event) # Delete when legacy topical events have been migrated topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - call_for_evidence.topical_event_memberships.create!(topical_event_id: topical_event.id) # Delete when legacy topical events have been migrated call_for_evidence.topical_event_documents << topical_event_document expected_content_ids = [ - topical_event.content_id, # Delete when legacy topical events have been migrated topical_event_document.content_id, ] diff --git a/test/unit/app/presenters/publishing_api/consultation_presenter_test.rb b/test/unit/app/presenters/publishing_api/consultation_presenter_test.rb index 11f7f51dc60..1f4419804e0 100644 --- a/test/unit/app/presenters/publishing_api/consultation_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/consultation_presenter_test.rb @@ -625,14 +625,11 @@ class ConsultationWithTopicalEvents < TestCase ) ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - topical_event = create(:topical_event) # Delete when legacy topical events have been migrated topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - consultation.topical_event_memberships.create!(topical_event_id: topical_event.id) # Delete when legacy topical events have been migrated consultation.topical_event_documents << topical_event_document expected_content_ids = [ - topical_event.content_id, # Delete when legacy topical events have been migrated topical_event_document.content_id, ] diff --git a/test/unit/app/presenters/publishing_api/detailed_guide_presenter_test.rb b/test/unit/app/presenters/publishing_api/detailed_guide_presenter_test.rb index 44d722bad25..e053fb3e7d5 100644 --- a/test/unit/app/presenters/publishing_api/detailed_guide_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/detailed_guide_presenter_test.rb @@ -34,10 +34,8 @@ def present(edition) ) ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - topical_event = create(:topical_event) # Delete when legacy topical events have been migrated topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - detailed_guide.topical_event_memberships.create!(topical_event_id: topical_event.id) # Delete when legacy topical events have been migrated detailed_guide.topical_event_documents << topical_event_document public_path = detailed_guide.public_path @@ -77,7 +75,6 @@ def present(edition) related_mainstream_content: [], government: [government.content_id], topical_events: [ - topical_event.content_id, # Delete when legacy topical events have been migrated topical_event_document.content_id, ], }, diff --git a/test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb b/test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb index b23c7c26f43..f79b27a4d45 100644 --- a/test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/document_collection_presenter_test.rb @@ -265,13 +265,6 @@ class PublishingApi::PublishedDocumentCollectionPresenterEditionLinksTest < Acti @presented_links[:organisations], ) end - - test "it presents the topical_events content_ids as links, topical_events" do - assert_equal( - @document_collection.topical_events.map(&:content_id), - @presented_links[:topical_events], - ) - end end class PublishingApi::PublishedDocumentCollectionPresenterDuplicateDocumentsTest < ActiveSupport::TestCase @@ -303,10 +296,8 @@ class PublishingApi::PublishedDocumentCollectionPresenterTopicalEventsLinksTest document_collection = create(:document_collection) ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - @topical_event = create(:topical_event) # Delete when legacy topical events have been migrated @topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - document_collection.topical_event_memberships.create!(topical_event_id: @topical_event.id) # Delete when legacy topical events have been migrated document_collection.topical_event_documents << @topical_event_document @presented_document_collection = PublishingApi::DocumentCollectionPresenter.new(document_collection) @@ -315,7 +306,6 @@ class PublishingApi::PublishedDocumentCollectionPresenterTopicalEventsLinksTest test "it presents the topical events as links, topical_events" do assert_equal( [ - @topical_event.content_id, # Delete when legacy topical events have been migrated @topical_event_document.content_id, ], @presented_document_collection.links[:topical_events], @@ -325,7 +315,6 @@ class PublishingApi::PublishedDocumentCollectionPresenterTopicalEventsLinksTest test "it presents the topical events as content, links, topical_events" do assert_equal( [ - @topical_event.content_id, # Delete when legacy topical events have been migrated @topical_event_document.content_id, ], @presented_document_collection.content[:links][:topical_events], diff --git a/test/unit/app/presenters/publishing_api/featured_documents_presenter_test.rb b/test/unit/app/presenters/publishing_api/featured_documents_presenter_test.rb index b5d3be2fd96..4c74259d5c4 100644 --- a/test/unit/app/presenters/publishing_api/featured_documents_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/featured_documents_presenter_test.rb @@ -49,39 +49,6 @@ class Presenters::PublishingApi::FeaturedDocumentsHelperTest < ActiveSupport::Te end end - test("determines ordered featured documents in different locales for topical events") do - topical_event = create(:topical_event, name: "topical_event_1", start_date: 1.year.ago.to_date) - feature = build(:feature, document: nil, topical_event:, ordering: 1) - featured_documents_display_limit = 5 - - organisation = create(:organisation) - - locales = [ - { code: "en", suffix: "" }, - { code: "fr", suffix: ".fr" }, - ] - - locales.each do |locale| - I18n.with_locale(locale[:code]) do - create(:feature_list, locale: locale[:code], featurable: organisation, features: [feature]) - - expected_ordered_featured_documents = [ - { title: topical_event.name, - href: "/government/topical-events/topical_event_1#{locale[:suffix]}", - image: { url: "#{Plek.asset_root}/media/asset_manager_id_original/minister-of-funk.960x640.jpg", - medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg", - high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg", - alt_text: "" }, - summary: govspeak_to_html(topical_event.summary), - public_updated_at: topical_event.start_date, - document_type: nil }, - ] - - assert_equal expected_ordered_featured_documents, featured_documents(organisation, featured_documents_display_limit) - end - end - end - test("determines ordered featured documents in different locales for offsite links") do organisation = create(:organisation) offsite_link = create(:offsite_link, organisations: [organisation], date: 1.year.ago.to_date) diff --git a/test/unit/app/presenters/publishing_api/payload_builder/configurable_document_links_test.rb b/test/unit/app/presenters/publishing_api/payload_builder/configurable_document_links_test.rb index 942523ceb9c..e415862298f 100644 --- a/test/unit/app/presenters/publishing_api/payload_builder/configurable_document_links_test.rb +++ b/test/unit/app/presenters/publishing_api/payload_builder/configurable_document_links_test.rb @@ -119,17 +119,13 @@ class PublishingApi::PayloadBuilder::ConfigurableDocumentLinksTest < ActiveSuppo end test "it presents the selected topical event links" do - topical_events = create_list(:topical_event, 3) topical_event_documents = create_list(:standard_edition, 3, configurable_document_type: "topical_event") edition = create(:draft_standard_edition, { - topical_events: [topical_events.first, topical_events.last], topical_event_documents: [topical_event_documents.first.document, topical_event_documents.last.document], }) links = PublishingApi::PayloadBuilder::ConfigurableDocumentLinks.for(edition) expected_links = [ - topical_events.first.content_id, - topical_events.last.content_id, topical_event_documents.first.document.content_id, topical_event_documents.last.document.content_id, ] diff --git a/test/unit/app/presenters/publishing_api/payload_builder/topical_events_test.rb b/test/unit/app/presenters/publishing_api/payload_builder/topical_events_test.rb deleted file mode 100644 index dbc5d709bd5..00000000000 --- a/test/unit/app/presenters/publishing_api/payload_builder/topical_events_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "test_helper" - -module PublishingApi - module PayloadBuilder - class PayloadBuilderTopicalEventTest < ActiveSupport::TestCase - setup do - ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - @publication = create(:publication) - @topical_event = build(:topical_event) - @topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - @publication.topical_events << @topical_event - @publication.topical_event_documents << @topical_event_document - end - - test "returns_content_ids_for_supplied_edition" do - expected_result = { topical_events: [@topical_event.content_id, @topical_event_document.content_id] } - actual_result = PublishingApi::PayloadBuilder::TopicalEvents.for(@publication) - assert_equal expected_result, actual_result - end - end - end -end diff --git a/test/unit/app/presenters/publishing_api/publication_presenter_test.rb b/test/unit/app/presenters/publishing_api/publication_presenter_test.rb index 45675f0b0bc..7e3aba57609 100644 --- a/test/unit/app/presenters/publishing_api/publication_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/publication_presenter_test.rb @@ -55,9 +55,7 @@ def present(edition) } ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - topical_event = create(:topical_event) # Delete when legacy topical events have been migrated topical_event_document = create(:standard_edition, configurable_document_type: "topical_event").document - publication.topical_event_memberships.create!(topical_event_id: topical_event.id) # Delete when legacy topical events have been migrated publication.topical_event_documents << topical_event_document expected_links = { government: [publication.government.content_id], @@ -66,7 +64,6 @@ def present(edition) related_statistical_data_sets: [statistical_data_set.content_id], world_locations: [], topical_events: [ - topical_event.content_id, # Delete when legacy topical events have been migrated topical_event_document.content_id, ], roles: publication.role_appointments.map(&:role).collect(&:content_id), diff --git a/test/unit/app/presenters/publishing_api/speech_presenter_test.rb b/test/unit/app/presenters/publishing_api/speech_presenter_test.rb index 331a34fd625..70ab966d384 100644 --- a/test/unit/app/presenters/publishing_api/speech_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/speech_presenter_test.rb @@ -93,13 +93,11 @@ def iso8601_regex describe "links" do let(:policy_content_id) { SecureRandom.uuid } - let(:topical_event) { create(:topical_event) } # Delete when legacy topical events have been migrated let(:world_location) { create(:world_location) } let(:topical_event_document) { create(:standard_edition, configurable_document_type: "topical_event").document } before do ConfigurableDocumentType.setup_test_types(build_configurable_document_type("topical_event")) - speech.topical_events << topical_event # Delete when legacy topical events have been migrated speech.topical_event_documents << topical_event_document speech.world_locations << world_location end @@ -107,7 +105,6 @@ def iso8601_regex it "contains the expected keys and values" do assert_includes(presented.links.keys, :organisations) assert_includes(presented.links.keys, :speaker) - assert_includes(presented.links.keys, :topical_events) assert_includes(presented.links.keys, :people) assert_includes(presented.links.keys, :roles) assert_includes(presented.links.keys, :world_locations) @@ -115,7 +112,6 @@ def iso8601_regex assert_includes(presented.links[:organisations], speech.organisations.first.content_id) assert_includes(presented.links[:speaker], person.content_id) - assert_includes(presented.links[:topical_events], topical_event.content_id) # Delete when legacy topical events have been migrated assert_includes(presented.links[:topical_events], topical_event_document.content_id) assert_includes(presented.links[:roles], speech.role_appointment.role.content_id) assert_includes(presented.links[:people], person.content_id) diff --git a/test/unit/app/presenters/publishing_api/topical_event_about_page_presenter_test.rb b/test/unit/app/presenters/publishing_api/topical_event_about_page_presenter_test.rb deleted file mode 100644 index cdf4f6c2f78..00000000000 --- a/test/unit/app/presenters/publishing_api/topical_event_about_page_presenter_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "test_helper" - -class PublishingApi::TopicalEventAboutPagePresenterTest < ActiveSupport::TestCase - def present(record) - PublishingApi::TopicalEventAboutPagePresenter.new(record) - end - - test "topical event about page presentation includes the correct values" do - topical_event_about_page = create(:topical_event_about_page) - - expected_hash = { - base_path: topical_event_about_page.base_path, - title: topical_event_about_page.name, - description: "Summary", - schema_name: "topical_event_about_page", - document_type: "topical_event_about_page", - locale: "en", - public_updated_at: topical_event_about_page.updated_at, - publishing_app: Whitehall::PublishingApp::WHITEHALL, - rendering_app: "frontend", - routes: [ - { path: topical_event_about_page.base_path, type: "exact" }, - ], - redirects: [], - update_type: "major", - details: { - body: "

Body

", - read_more: "Read more", - }, - } - - presented_item = present(topical_event_about_page) - presented_content = presented_item.content - - assert_valid_against_publisher_schema(presented_item.content, "topical_event_about_page") - assert_valid_against_links_schema({ links: presented_item.links }, "topical_event_about_page") - assert_equal topical_event_about_page.topical_event.content_id, presented_item.links[:parent][0] - - # We test for HTML equivalance rather than string equality to get around - # inconsistencies with line breaks between different XML libraries - assert_equivalent_html expected_hash[:details].delete(:body), - presented_content[:details].delete(:body) - - assert_equal expected_hash, presented_content - end - - test "it includes headers when headers are present in body" do - topical_event_about_page = create( - :topical_event_about_page, - body: "##Some header\n\nSome content", - ) - - presented_topical_event_about_page = PublishingApi::TopicalEventAboutPagePresenter.new(topical_event_about_page) - - expected_headers = [ - { - text: "Some header", - level: 2, - id: "some-header", - }, - ] - - assert_equal expected_headers, presented_topical_event_about_page.content[:details][:headers] - end - - test "it does not include headers when headers are not present in body" do - topical_event_about_page = create( - :topical_event_about_page, - body: "Some content", - ) - - presented_topical_event_about_page = PublishingApi::TopicalEventAboutPagePresenter.new(topical_event_about_page) - - assert_nil presented_topical_event_about_page.content[:details][:headers] - end -end diff --git a/test/unit/app/presenters/publishing_api/topical_event_presenter_test.rb b/test/unit/app/presenters/publishing_api/topical_event_presenter_test.rb deleted file mode 100644 index b1700b77c35..00000000000 --- a/test/unit/app/presenters/publishing_api/topical_event_presenter_test.rb +++ /dev/null @@ -1,188 +0,0 @@ -require "test_helper" - -class PublishingApi::TopicalEventPresenterTest < ActiveSupport::TestCase - include GovspeakHelper - test "presents a valid topical_event content item" do - topical_event = create( - :topical_event, - :with_logo, - :active, - name: "Humans going to Mars", - description: "A topical event description with [a link](http://www.gov.uk)", - ) - create(:topical_event_about_page, topical_event:, read_more_link_text: "Read more about this event") - - first_lead_org = create(:organisation) - first_lead_org.topical_event_organisations.create!(topical_event_id: topical_event.id, lead: true, lead_ordering: 1) - second_lead_org = create(:organisation) - second_lead_org.topical_event_organisations.create!(topical_event_id: topical_event.id, lead: true, lead_ordering: 2) - - public_path = "/government/topical-events/humans-going-to-mars" - - feature = create(:topical_event_featuring, topical_event:, ordering: 1) - offsite_feature = create(:offsite_topical_event_featuring, topical_event:, ordering: 0) - - social_media_service = create(:social_media_service, name: "Facebook") - social_media_account = create(:social_media_account, social_media_service:) - topical_event.social_media_accounts = [social_media_account] - - expected_hash = { - base_path: public_path, - publishing_app: Whitehall::PublishingApp::WHITEHALL, - rendering_app: "frontend", - schema_name: "topical_event", - document_type: "topical_event", - title: "Humans going to Mars", - description: topical_event.summary, - locale: "en", - routes: [ - { - path: public_path, - type: "exact", - }, - { - path: "#{public_path}.atom", - type: "exact", - }, - ], - update_type: "major", - redirects: [], - public_updated_at: topical_event.updated_at, - details: { - about_page_link_text: topical_event.topical_event_about_page.read_more_link_text, - body: govspeak_to_html(topical_event.description), - emphasised_organisations: [first_lead_org.content_id, second_lead_org.content_id], - image: { - url: topical_event.logo.file.url(:s300), - medium_resolution_url: topical_event.logo.file.url(:s630), - high_resolution_url: topical_event.logo.file.url(:s960), - alt_text: topical_event.logo_alt_text, - }, - start_date: topical_event.start_date.rfc3339, - end_date: topical_event.end_date.rfc3339, - ordered_featured_documents: [ - { - title: offsite_feature.title, - href: offsite_feature.url, - image: { - url: offsite_feature.image.file.url(:s465), - alt_text: offsite_feature.alt_text, - }, - summary: offsite_feature.summary, - public_updated_at: offsite_feature.public_timestamp, - document_type: offsite_feature.display_type, - }, - { - title: feature.title, - href: feature.url, - image: { - url: feature.image.file.url(:s465), - alt_text: feature.alt_text, - }, - summary: feature.summary, - public_updated_at: feature.public_timestamp, - document_type: feature.display_type, - }, - ], - social_media_links: [ - { - href: social_media_account.url, - service_type: social_media_account.service_name.parameterize, - title: social_media_account.display_name, - }, - ], - }, - } - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event) - - assert_equal expected_hash, presenter.content - assert_valid_against_publisher_schema(presenter.content, "topical_event") - assert_valid_against_links_schema({ links: presenter.links }, "topical_event") - end - - test "handles topical events without dates" do - topical_event = create(:topical_event, name: "Humans going to Mars") - public_path = "/government/topical-events/humans-going-to-mars" - - expected_hash = { - base_path: public_path, - publishing_app: Whitehall::PublishingApp::WHITEHALL, - rendering_app: "frontend", - schema_name: "topical_event", - document_type: "topical_event", - title: "Humans going to Mars", - description: topical_event.summary, - locale: "en", - routes: [ - { - path: public_path, - type: "exact", - }, - { - path: "#{public_path}.atom", - type: "exact", - }, - ], - update_type: "major", - redirects: [], - public_updated_at: topical_event.updated_at, - details: { - body: govspeak_to_html(topical_event.description), - emphasised_organisations: [], - ordered_featured_documents: [], - social_media_links: [], - }, - } - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event) - - assert_equal expected_hash, presenter.content - assert_valid_against_publisher_schema(presenter.content, "topical_event") - assert_valid_against_links_schema({ links: presenter.links }, "topical_event") - end - - test "handles topical events without an end_date" do - topical_event = create(:topical_event, start_date: Time.zone.today) - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event) - - assert_equal({ - body: govspeak_to_html(topical_event.description), - start_date: Time.zone.today.rfc3339, - emphasised_organisations: [], - ordered_featured_documents: [], - social_media_links: [], - }, presenter.content[:details]) - assert_valid_against_publisher_schema(presenter.content, "topical_event") - assert_valid_against_links_schema({ links: presenter.links }, "topical_event") - end - - test "it limits the number of featured items" do - topical_event = create(:topical_event, start_date: Time.zone.today) - create_list(:topical_event_featuring, TopicalEvent::MAX_FEATURED_DOCUMENTS + 1, topical_event:) - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event) - - assert_equal TopicalEvent::MAX_FEATURED_DOCUMENTS, presenter.content.dig(:details, :ordered_featured_documents).length - end - - test "it ignores featured items if image variants are missing" do - topical_event_featuring = build(:topical_event_featuring) - topical_event_featuring.image.assets = [] - topical_event_featuring.save! - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event_featuring.topical_event) - - assert_empty presenter.content.dig(:details, :ordered_featured_documents) - end - - test "it ignores the logo if variants are missing" do - topical_event = create(:topical_event, :with_logo) - topical_event.logo.assets.destroy_all - - presenter = PublishingApi::TopicalEventPresenter.new(topical_event) - - assert_nil presenter.content.dig(:details, :image) - end -end diff --git a/test/unit/app/presenters/publishing_api_presenters_test.rb b/test/unit/app/presenters/publishing_api_presenters_test.rb index d000ed37d72..34adc0c08a6 100644 --- a/test/unit/app/presenters/publishing_api_presenters_test.rb +++ b/test/unit/app/presenters/publishing_api_presenters_test.rb @@ -69,11 +69,6 @@ class PublishingApiPresentersTest < ActiveSupport::TestCase assert_equal PublishingApi::PolicyGroupPresenter, presenter.class end - test ".presenter_for returns TopicalEvent placeholder for a TopicalEvent" do - presenter = PublishingApiPresenters.presenter_for(TopicalEvent.new) - assert_equal PublishingApi::TopicalEventPresenter, presenter.class - end - test ".presenter_for returns a HtmlAttachment presenter for `HtmlAttachment`" do presenter = PublishingApiPresenters.presenter_for(build(:html_attachment)) assert_equal PublishingApi::HtmlAttachmentPresenter, presenter.class diff --git a/test/unit/app/sidekiq/search_index_add_job_test.rb b/test/unit/app/sidekiq/search_index_add_job_test.rb index cb0ceafa56a..97367733a07 100644 --- a/test/unit/app/sidekiq/search_index_add_job_test.rb +++ b/test/unit/app/sidekiq/search_index_add_job_test.rb @@ -15,10 +15,11 @@ class SearchIndexAddJobTest < ActiveSupport::TestCase end test "#perform indexes searchable instances" do - event = create(:topical_event) + event = create(:operational_field) attributes_for_indexing_mock = mock - TopicalEvent.any_instance.stubs(:search_index).returns(attributes_for_indexing_mock) + OperationalField.any_instance.stubs(:search_index).returns(attributes_for_indexing_mock) + Whitehall::SearchIndex.indexer_class.any_instance.expects(:add).with(attributes_for_indexing_mock) SearchIndexAddJob.new.perform(event.class.name, event.id) end diff --git a/test/unit/lib/data_hygiene/topical_event_reslugger_test.rb b/test/unit/lib/data_hygiene/topical_event_reslugger_test.rb deleted file mode 100644 index bb419201a1c..00000000000 --- a/test/unit/lib/data_hygiene/topical_event_reslugger_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "test_helper" -require "gds_api/test_helpers/search" - -class TopicalEventResluggerTest < ActiveSupport::TestCase - include GdsApi::TestHelpers::Search - - setup do - @old_slug = "old-slug" - @new_slug = "new-slug" - @topical_event = FactoryBot.create(:topical_event, slug: @old_slug) - - @detailed_guide = FactoryBot.create(:published_detailed_guide) - @topical_event.expects(:editions).returns([@detailed_guide]) - - @reslugger = DataHygiene::TopicalEventReslugger.new(@topical_event, @new_slug) - end - - test "updates the topical_event's slug" do - assert_changes -> { @topical_event.slug }, from: @old_slug, to: @new_slug do - @reslugger.run! - end - end - - test "republishes the topical_event to Publishing API" do - Whitehall::PublishingApi.expects(:republish_async).with(@topical_event) - - @reslugger.run! - end - - test "reindexes the topical_event" do - [@topical_event].each do |object| - object.stubs(:remove_from_search_index) - object.stubs(:update_in_search_index) - - object.expects(:remove_from_search_index) - object.expects(:update_in_search_index) - end - - @reslugger.run! - end -end