I have this array returned by a activerecord query:
SELECT id, value FROM table ORDER BY value DESC
[1054, 86], [1062, 86], [1059, 84]
And I've created a simple array to compare with the first array:
array.sort_by! { |object| object.access_count }.reverse }
But when I compare the two arrays the result is different:
activerecord => [1054, 86], [1062, 86], [1059, 84]
array.sort_by! => [[1062, 86], [1054, 86], [1059, 84]
So in some cases the compare doesn't work because activerecord sorts one way and sort_by! sorts another.
How can I solve that ? Thanks.
ordermethod of Active record. Actually in RSpec we are responsible to test the code written by us. You no need to test order here. In case you are necessary to write test case for order, In the spec you can make a query likerecords = Model.only(:id, :name).order(:desc)and check like thisexpected(response_records).to eq(records)