Skip to content

Commit

Permalink
Allow previously redirected manuals to be removed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brucebolt committed Aug 1, 2024
1 parent c0ba00a commit 26a2650
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/publishing_api_removed_manual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? }

Expand Down
2 changes: 1 addition & 1 deletion app/models/publishing_api_removed_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? }

Expand Down
6 changes: 6 additions & 0 deletions spec/models/publishing_api_removed_manual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/models/publishing_api_removed_section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26a2650

Please sign in to comment.