Skip to content

fix(adjacency): order by the position method when adjacent_by has no within - #223

Merged
eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/adjacent-by-position-without-within
Nov 16, 2026
Merged

eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/adjacent-by-position-without-within

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

adjacent_by :position without within: has no effect today. The method returns early when within is blank, so next and previous fall 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 that adjacent_by :position configures your own order, so a flat collection that sets it is expected to follow position.

Fix: when there is no grouping, next and previous sort by the position method. Grouped behaviour (within: :section / within: { section: [...] }) is untouched.

Existing tests changed: flat: next returns the following resource and flat: previous returns previous in natural order encoded the old behaviour. Content::Doc uses adjacent_by :position, and the tests expected installation -> quickstart, which are positions 1 and 5, i.e. the order by id. They now expect the order by position (installation -> configuration, configuration previous is installation, installation previous is nil). This is a behaviour change for anyone relying on the old order with adjacent_by :position and no within; if you would rather keep the old order for that case, say so and I will drop this.

New test: a standalone class whose all is 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

…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
eelcoj force-pushed the fix/adjacent-by-position-without-within branch from 4df3594 to 8de9c82 Compare November 16, 2026 10:47
@eelcoj
eelcoj merged commit d2235c3 into Rails-Designer:main Nov 16, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants