Skip to content

fix: check the column passed to the ordered test matcher - #500

Open
yskttm wants to merge 1 commit into
ClosureTree:masterfrom
yskttm:fix/matcher-ordered-column
Open

yskttm wants to merge 1 commit into
ClosureTree:masterfrom
yskttm:fix/matcher-ordered-column

Conversation

@yskttm

@yskttm yskttm commented Dec 2, 2026 •

Copy link
Copy Markdown

What this fixes

be_a_closure_tree.ordered(:column) ignores the column, so it passes for a tree ordered by any column:

# Metal is ordered by sort_order
expect(Metal).to be_a_closure_tree.ordered(:value) # passes

matches? has never compared the column. Since the matcher was added in 6f14804, ordered has stored the argument in @order_colum (missing n), which nothing reads.

The fix

  • Store the argument in @order_column.
  • When a column is given, compare it with _ct.order_column and fail with expected Metal to be ordered by value, but it is ordered by sort_order. A string or a symbol works, and ordered with no argument behaves as before.

Testing

  • Added ordered matcher checks the given order column to test/closure_tree/matcher_test.rb. It runs the matcher itself, since the existing tests use a local assert_closure_tree helper. It fails on master and passes with the fix.
  • The full suite passes on PostgreSQL, MySQL and SQLite (370 runs, 0 failures).

be_a_closure_tree.ordered(:column) stored the column in a misspelled
instance variable (@order_colum) that was never read, so the matcher
passed for any ordered model regardless of the column given.
@yskttm
yskttm marked this pull request as ready for review December 2, 2026 15:12

This branch has not been deployed

No deployments
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.

1 participant