mixonic/ranked-model — pull request #54 by jamesalmond (2013-09-25 09:55:04+00:00)
Title: Ranking models against others that don't have a rank

#32 discusses a need for a default column value, but I'm still getting problems when I try and set the position of an item to an integer position where some records don't a rank (i.e. I want to do Model.update_attributes rank_position: 1).

I'm using ranked-model in a new codebase that uses pre-existing model data. It's also possible to update the records in that table outside of the codebase that includes ranked-model. This is resulting in the rank being nil for some records.

So, when a model is ranked and its neighbours don't have a rank set (https://github.com/mixonic/ranked-model/blob/master/lib/ranked-model/ranker.rb#L131) you can't subtract the min and max.

I've added a spec that demonstrates the error when ranked-model is added to a model without a default column value, and also a possible fix. Let me know what you think!