Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected changes in HTML attachment slugs #2357

Merged
merged 3 commits into from Oct 13, 2015
Merged

Conversation

@fofr
Copy link
Contributor

@fofr fofr commented Oct 13, 2015

HTML publication slugs change unexpectedly given the following scenario:

  • Create a new edition of a published document and alter the HTML attachment title
  • Publish the document, at this point the HTML attachment slug is still correct
  • Create another new edition, when this edition is created the attachment slug changes to one based on the edited title.

Because the slug comes from an extended class it is not included when running dup. Whenever a new edition with an HTML attachment is created, because the slug is nil, a new one is generated based on the title. If the attachment title changed then subsequent editions would have different slugs.

  • Demonstrate this with two failing tests
  • Explicitly copy the slug when deep cloning the attachment so a new one isn't generated and the slug doesn't unexpectedly change.

"When using dup, any modules that the object has been extended with will not be copied."
http://ruby-doc.org/core-2.1.6/Object.html#method-i-dup

https://trello.com/c/Y2rdmCTE/132-changing-the-title-of-an-html-pub-changes-the-slug-but-doesn-t-automatically-create-a-redirect-medium

fofr added 3 commits Oct 12, 2015
HTML publication slugs change unexpectedly given the following scenario:
* Create a new edition of a published document and alter the HTML
attachment title
* Publish the document, at this point the HTML attachment slug is still
correct
* Create another new edition, when this edition is created the
attachment slug changes to one based on the edited title.

This test demonstrates that bug.
When deep cloning an attachment, the slug is not carried across.

Because the slug is nil, friendly_id generates a new slug based on the
title. If the title has changed in the past, then at this point the
slug changes.
Because the slug comes from an extended class it is not included
when running `dup`. Whenever a new edition with an HTML attachment
was created the slug was regenerated based on the title. If the
attachment title changed then subsequent editions would have
different slugs.

Explicitly copy the slug to the new attachment so a new one isn't
generated.

"When using dup, any modules that the object has been extended with
will not be copied."
http://ruby-doc.org/core-2.1.6/Object.html#method-i-dup
@boffbowsh
Copy link
Contributor

@boffbowsh boffbowsh commented Oct 13, 2015

💥 👍

fofr added a commit that referenced this pull request Oct 13, 2015
Fix unexpected changes in HTML attachment slugs
@fofr fofr merged commit bbed449 into master Oct 13, 2015
1 check passed
1 check passed
default Build #6773 succeeded on Jenkins
Details
@fofr fofr deleted the dont-alter-html-pub-slugs branch Oct 13, 2015
@jamiecobbett
Copy link
Contributor

@jamiecobbett jamiecobbett commented Oct 14, 2015

🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.