Skip to content

Commit

Permalink
Merge pull request #1156 from alphagov/fix-gone-unpublish
Browse files Browse the repository at this point in the history
Fix issue with former redirects being unable to be unpublished
  • Loading branch information
brucebolt authored Sep 28, 2023
2 parents 43b8024 + aa00d00 commit 7d85096
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/route_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.from_content_item(item)
routes = item.routes.map(&:to_h).map(&:deep_symbolize_keys)
end

redirects = item.redirects.map(&:to_h).map(&:deep_symbolize_keys)
redirects = Array(item.redirects).map(&:to_h).map(&:deep_symbolize_keys)

new(
routes:,
Expand Down
22 changes: 22 additions & 0 deletions spec/models/route_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@
]

route_set = RouteSet.from_content_item(item)

expect(route_set.is_gone).to eq(true)
expected_routes = [
{ path: "/path", type: "exact" },
{ path: "/path.json", type: "exact" },
{ path: "/path/subpath", type: "prefix" },
]
expect(route_set.routes).to eq([])
expect(route_set.gone_routes).to match_array(expected_routes)
expect(route_set.redirects).to eq([])
end

it "constructs a route set from a gone content item with nil redirects" do
item = build(:gone_content_item, base_path: "/path", redirects: nil)
item.routes = [
{ "path" => "/path", "type" => "exact" },
{ "path" => "/path.json", "type" => "exact" },
{ "path" => "/path/subpath", "type" => "prefix" },
]

route_set = RouteSet.from_content_item(item)

expect(route_set.is_gone).to eq(true)
expected_routes = [
{ path: "/path", type: "exact" },
Expand Down

0 comments on commit 7d85096

Please sign in to comment.