Repository navigation
fix(adjacency): order by the position method when adjacent_by has no within - #223
Merged
eelcoj merged 1 commit intoNov 16, 2026
Conversation
…within adjacent_by returned early when within was blank, so adjacent_by :position on a flat collection was a no-op and next/previous kept using the collection order. Sort by the position method in that case. The two flat tests assumed the old order, so they now expect the order by position.
eelcoj
force-pushed
the
fix/adjacent-by-position-without-within
branch
from
November 16, 2026 10:47
4df3594 to
8de9c82
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
adjacent_by :positionwithoutwithin:has no effect today. The method returns early whenwithinis blank, sonextandpreviousfall back to the default collection order (by id) and the position method is never read. The docs say the default order is by id and thatadjacent_by :positionconfigures your own order, so a flat collection that sets it is expected to followposition.Fix: when there is no grouping,
nextandprevioussort by the position method. Grouped behaviour (within: :section/within: { section: [...] }) is untouched.Existing tests changed:
flat: next returns the following resourceandflat: previous returns previous in natural orderencoded the old behaviour.Content::Docusesadjacent_by :position, and the tests expectedinstallation -> quickstart, which are positions 1 and 5, i.e. the order by id. They now expect the order by position (installation -> configuration,configurationprevious isinstallation,installationprevious isnil). This is a behaviour change for anyone relying on the old order withadjacent_by :positionand nowithin; if you would rather keep the old order for that case, say so and I will drop this.New test: a standalone class whose
allis out of order (positions 3, 1, 2) checks next/previous follow position. It fails on main and passes now.adjacency_test.rb: 15 runs, 0 failures.This change was prepared with the assistance of an AI coding tool.
🤖 Generated with Claude Code