From 26a2650f4599156f2e7342756b34a6d0594d73f3 Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Thu, 1 Aug 2024 10:37:55 +0100 Subject: [PATCH] Allow previously redirected manuals to be removed If a manual or a section has been previously redirected, it has a schema of `redirect`. This means we cannot subsequently remove the manual or the redirect, as the new content item won't be valid. Therefore allowing a schema of `redirect` for us to be able to remove a manual or a section that has previously been redirected. --- app/models/publishing_api_removed_manual.rb | 2 +- app/models/publishing_api_removed_section.rb | 2 +- spec/models/publishing_api_removed_manual_spec.rb | 6 ++++++ spec/models/publishing_api_removed_section_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/publishing_api_removed_manual.rb b/app/models/publishing_api_removed_manual.rb index 4e8217dd..fa20ae97 100644 --- a/app/models/publishing_api_removed_manual.rb +++ b/app/models/publishing_api_removed_manual.rb @@ -6,7 +6,7 @@ class PublishingAPIRemovedManual validates :slug, format: { with: ValidSlug::PATTERN, message: "should match the pattern: #{ValidSlug::PATTERN}" } validates_with InContentStoreValidator, - schema_names: [MANUAL_SCHEMA_NAME], + schema_names: [MANUAL_SCHEMA_NAME, "redirect"], content_store: Services.content_store, unless: -> { errors[:slug].present? } diff --git a/app/models/publishing_api_removed_section.rb b/app/models/publishing_api_removed_section.rb index a2dc0744..c21000da 100644 --- a/app/models/publishing_api_removed_section.rb +++ b/app/models/publishing_api_removed_section.rb @@ -6,7 +6,7 @@ class PublishingAPIRemovedSection validates :manual_slug, :section_slug, format: { with: ValidSlug::PATTERN, message: "should match the pattern: #{ValidSlug::PATTERN}" } validates_with InContentStoreValidator, - schema_names: [SECTION_SCHEMA_NAME], + schema_names: [SECTION_SCHEMA_NAME, "redirect"], content_store: Services.content_store, unless: -> { errors[:manual_slug].present? || errors[:section_slug].present? } diff --git a/spec/models/publishing_api_removed_manual_spec.rb b/spec/models/publishing_api_removed_manual_spec.rb index 53afbf7d..1a0a530b 100644 --- a/spec/models/publishing_api_removed_manual_spec.rb +++ b/spec/models/publishing_api_removed_manual_spec.rb @@ -34,6 +34,12 @@ expect(subject).to be_valid end + it 'is valid when the slugs represent a "redirect" piece of content' do + content_item = hmrc_manual_content_item_for_base_path(manual_path).merge("schema_name" => "redirect") + stub_content_store_has_item(manual_path, content_item) + expect(subject).to be_valid + end + it "is invalid when the slug represents a piece of content with any other schema_name" do stub_content_store_has_item(manual_path) expect(subject).not_to be_valid diff --git a/spec/models/publishing_api_removed_section_spec.rb b/spec/models/publishing_api_removed_section_spec.rb index 6d79f4c3..ded637e7 100644 --- a/spec/models/publishing_api_removed_section_spec.rb +++ b/spec/models/publishing_api_removed_section_spec.rb @@ -59,6 +59,12 @@ expect(subject).to be_valid end + it 'is valid when the slugs represent a "redirect" piece of content' do + content_item = hmrc_manual_section_content_item_for_base_path(section_path).merge("schema_name" => "redirect") + stub_content_store_has_item(section_path, content_item) + expect(subject).to be_valid + end + it "is invalid when the slugs represents a piece of content with any other schema_name" do stub_content_store_has_item(section_path) expect(subject).not_to be_valid