Closed alexanderholder closed 2 months ago
This feels like a race condition but perhaps instead of having randomly computed position updates, try to find a sequence that always fails so that it gives us something to reliably test against.
Also have a look at my other gem: https://github.com/brendon/positioning
It uses an advisory lock to ensure sequential list actions across processes.
Actually your testing problem stems from stale data. As you move through the items and update their position one at a time, ActsAsList is moving the other items out of the way but you're not reloading the future items before acting on them so ActsAsList thinks their current position is something other than what it really is. The tests always pass if you just do:
project_item.reload.update!(position: rand(1..5))
Hope that helps. I'm not sure there's a way to ensure all in-memory instances of an object are updated to be current with the database, and I'm sure that would become unwieldily eventually anyway.
oh of course! thanks for the speedy reply!
No worries! :)
Steps to reproduce
Using
update
seems to have issues inserting sometimes, where asinsert_at
seems to work. Keen to understand if these should behave the same as we currently would just useupdate
in our controllers.Expected behavior
update
should always work - it sometimes works (I used the10.times
to ensure it fails)Actual behavior
update
seems to error every now and then, whereinsert_at
seems to workSystem configuration
Rails version: 7.1+
Ruby version: 3.3.4