-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Resource#sorted_attributes behaves differently across Ruby versions #3152
Comments
robinboening
added a commit
to robinboening/alchemy_cms
that referenced
this issue
Jan 21, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes AlchemyCMS#3152
robinboening
added a commit
to robinboening/alchemy_cms
that referenced
this issue
Jan 23, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes AlchemyCMS#3152
alchemycms-bot
pushed a commit
that referenced
this issue
Jan 24, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes #3152 (cherry picked from commit 5d397f5)
alchemycms-bot
pushed a commit
that referenced
this issue
Jan 24, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes #3152 (cherry picked from commit 5d397f5)
alchemycms-bot
pushed a commit
that referenced
this issue
Jan 24, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes #3152 (cherry picked from commit 5d397f5)
alchemycms-bot
pushed a commit
that referenced
this issue
Jan 24, 2025
Chaining sort_by methods caused issues because each subsequent sort_by effectively overrides the previous sort order by re-sorting the entire array based solely on the new condition. This can disrupt the prioritization of earlier sorting criteria. Interestingly, chaining multiple sort_by calls has been working as expected in Ruby versions prior to 3.3.1, as the underlying behavior of Array#sort_by appears to have been consistent in preserving the prioritization of earlier steps. Switching to a single sort_by call ensures the logic remains robust and compatible across Ruby versions, including 3.3.1. Fixes #3152 (cherry picked from commit 5d397f5)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
I’ve encountered inconsistent behavior in
Resource#sorted_attributes
based on the Ruby version being used. This method relies onArray#sort_by
, and the sorting results vary with arrays of certain sizes when using different Ruby versions.Observed Behavior
I tested the behavior with three different Ruby versions and got the following results:
Existing RSpec Test Case
The existing RSpec test case for
Resource#sorted_attributes
is valid, but only includes 4 elements, which does not detect the discrepancy observed with larger arrays. The test case can be found here.Script to Reproduce
Steps to Reproduce
Expected Behavior
Resource#sorted_attributes should sort the attributes in a specific order:
The sorting behavior should remain consistent across all Ruby versions, regardless of array size.
Additional Notes
Array#sort_by
.The text was updated successfully, but these errors were encountered: