Make User.projects.actionize deterministic

Add project.id to the comparison to ensure consistent order when
counts are identical.
This commit is contained in:
Dan Rice 2015-01-03 18:11:47 -05:00
parent 0d6e0efcee
commit 7f1246f42f

View file

@ -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}