pyromaniac/mongoid_orderable — pull request #16 by johnnyshields (2013-10-11 04:03:31+00:00)
Title: Fix for Mongoid Identity map combined with Scoped Orderable

I found an edge case when using Mongoid Identity Map combined with Scoped Orderable. Scoped Orderable uses a method `orderable_scope_changed?` which uses a db query to check for the presence of the item on the original scope. However, when the Identity Map is enabled, this query is intercepted and it uses the (now stale) cached object, which still appears to be in the previous scope.

The solution is to wrap the query in a Mongoid.unit_of_work block to bypass the identity map on a one-off basis. See http://mongoid.org/en/mongoid/docs/identity_map.html.

I've committed the specs before the code fix so you can checkout commit ef3bb39 and replay the failing case.