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

Improve auto generation of slugs #359

Merged
merged 11 commits into from Jan 27, 2015
Merged

Improve auto generation of slugs #359

merged 11 commits into from Jan 27, 2015

Conversation

@fofr
Copy link
Contributor

@fofr fofr commented Jan 25, 2015

When editing part titles on new editions of published guides, the slug was auto updating. This change of slug would go unnoticed and lead to those old URLs no longer working (they redirect to the guide's first page rather than 404ing). This breaks a lot of cross-linking between editions and can take a user out of the context of what they are doing.

Change the auto slug generation behaviour to:

  • only update the slug if the slug is empty or has a data attribute "accepts-generated-value"
  • use this data attribute to continue auto generating slug values on first editions
  • if the slug started empty (eg a new part), then all subsequent changes before saving continue to generate slugs (eg typo correction in title)

This PR also moves a lot of the parts javascript into a module with tests. It includes:

  • testing part re-ordering using jquery.simulate.drag-sortable.js as a helper
  • testing part re-ordering after adding parts

https://www.agileplannerapp.com/boards/244464/cards/8236

fofr added 9 commits Jan 25, 2015
Nowhere in publisher was using this confirm message.
Create a testable module for handling parts and move sorting to it.

* Use jquery.simulate.drag-sortable.js helper to simulate sorting
* Test that the value of the order elements changes as expected
The move cursor wasn’t being added to new parts correctly.
Until now it was adding the class to the same element once for every
part on the page.
Use a single event listener on a parent element, rather than having to
add new listeners each time a part is added or removed.
Check whether a slug field is empty or accepts generated values before
updating it.

* When a slug begins as empty, then it is accepted that all future
edits should also generate a new slug. eg when fixing a typo.
* Use the flag `accepts-generated-value` to designate that a slug can
be auto updated at any time. eg the edition isn’t yet published
Move functionality into module and test.

fill_in 'Title', :with => 'Part One changed'
fill_in 'Body', :with => 'Body text'
assert_equal 'part-one-changed', find(:css, ".slug").value
end

This comment has been minimized.

@alext

alext Jan 27, 2015
Contributor

Is it worth a corresponding test that a version 2 doesn't get the slug updated?

This comment has been minimized.

@fofr

fofr Jan 27, 2015
Author Contributor

Yep, it was worth adding, done so in 9504c0d

fofr added 2 commits Jan 25, 2015
When an edition hasn’t yet been published, we don’t need to worry about
conserving existing URLs. Instead maintain the old behaviour of
updating the slug whenever the title changes.
Make it more apparent when the slug has been generated based on a title
change.
@fofr fofr force-pushed the slug-auto branch from 93293e0 to dfdceec Jan 27, 2015
alext added a commit that referenced this pull request Jan 27, 2015
Improve auto generation of slugs
@alext alext merged commit a2b64ca into master Jan 27, 2015
1 check passed
1 check passed
default "Build #615 succeeded on Jenkins"
Details
@alext alext deleted the slug-auto branch Jan 27, 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

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