diff --git a/app/models/document.rb b/app/models/document.rb index 8e0f69ff8f0..f30d30e8c18 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -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 diff --git a/test/unit/app/models/edition/identifiable_test.rb b/test/unit/app/models/edition/identifiable_test.rb index 6747909073c..0b8aad75f96 100644 --- a/test/unit/app/models/edition/identifiable_test.rb +++ b/test/unit/app/models/edition/identifiable_test.rb @@ -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)