locomotivecms/engine — pull request #254 by Robsteranium (2011-12-14 11:27:59+00:00)
Title: Previous comparison method failed when the sort column is a date with Nil

If you have a custom field that is of type "date" then it can give rise to this error if any of the custom instances have a nil value in the field.

ArgumentError: comparison of ContentContentType4ee756f9e5c4e656a5000192 with ContentContentType4ee756f9e5c4e656a5000192 failed
from ~/.rvm/gems/ruby-1.8.7-p352/gems/mongoid-2.0.2/lib/mongoid/relations/proxy.rb:111:in `sort'
from ~/.rvm/gems/ruby-1.8.7-p352/gems/mongoid-2.0.2/lib/mongoid/relations/proxy.rb:111:in `send'
from ~/.rvm/gems/ruby-1.8.7-p352/gems/mongoid-2.0.2/lib/mongoid/relations/proxy.rb:111:in `method_missing'
from ~/.rvm/gems/ruby-1.8.7-p352/gems/mongoid-2.0.2/lib/mongoid/relations/embedded/many.rb:354:in `method_missing'
from (irb):33
from :0

This arise from this comparison method:
https://github.com/locomotivecms/engine/blob/master/app/models/content_type.rb#L103

Which fails to compare a date with a fixnum (i.e. the 0 assigned to Nils).

This revision doesn't really sort Nils, rather ignore them.