From 7f1246f42f91c6c0884d7c70be24f9511d40892d Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Sat, 3 Jan 2015 18:11:47 -0500 Subject: [PATCH] Make User.projects.actionize deterministic Add project.id to the comparison to ensure consistent order when counts are identical. --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index e5456c27..49bc4c2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -62,7 +62,7 @@ class User < ActiveRecord::Base end def actionize(scope_conditions = {}) todos_in_project = where(scope_conditions).includes(:todos) - todos_in_project.to_a.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) } + todos_in_project.to_a.sort_by!{ |x| [-x.todos.active.count, -x.id] } todos_in_project.reject{ |p| p.todos.active.count > 0 } sorted_project_ids = todos_in_project.map {|p| p.id}