[#86778] Unreconciled order_detail sorting

This is to address the sorting/grouping issues seen on stage, though I can't say for sure if this will resolve it because I haven't been able to reproduce it locally (both with MySQL and Oracle). That change is in c52330e133749d60a2086f8bfc958effafb856a8.

The rest of the commits refactor and add tests.
So in Rails 3.2, `Relation#all` makes it an array? I forget when they made it return a relation.