Skip to content

Commit

Permalink
Merge pull request #8141 from alphagov/ensure-document-slug-does-not-…
Browse files Browse the repository at this point in the history
…change-once-published

Ensure document slug can never change once an edition has been published
  • Loading branch information
ryanb-gds authored Aug 18, 2023
2 parents dd0b1a2 + e605db6 commit f25ec4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def should_generate_new_friendly_id?
end

def update_slug_if_possible(new_title)
return if live? || invalid?
return if ever_published_editions.present? || invalid?

candidate_slug = normalize_friendly_id(new_title)
unless candidate_slug == slug
Expand Down
9 changes: 9 additions & 0 deletions test/unit/app/models/edition/identifiable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ class Edition::IdentifiableTest < ActiveSupport::TestCase
assert_equal "this-is-my-publication", existing_edition.document.reload.slug
end

test "should not update slug when after an edition has been unpublished" do
unpublished_edition = create(:superseded_publication, title: "This is my publication")
draft_edition = create(:draft_publication, title: "This is my publication", document: unpublished_edition.document)

draft_edition.title = "New title"
draft_edition.save!
assert_equal "this-is-my-publication", draft_edition.document.reload.slug
end

test "updating an edition updates the parent document timestamp" do
edition = create(:edition)

Expand Down

0 comments on commit f25ec4c

Please sign in to comment.