brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Using `top_of_list` set to 1 and setting a record to index 0 triggers a `PG::UniqueViolation` #322

Closed TheNeikos closed 6 years ago

TheNeikos commented 6 years ago

I've had quite a headache trying to use this gem, until I saw that top_of_list defaults to 1 and I try starting at 0.

This in turn caused a PG::UniqueViolation due to the incorrect swapping of objects. I think this could be prevented by raising an exception when trying to set an index that is lower than top_of_list ? (Which should be an error anyway imo)

Once I changed that setting the Exception went away, so I assumed that to be the cause.


So my suggestion would be to raise an error when an incorrect position is given

brendon commented 6 years ago

Hi @TheNeikos :) We're keen to help improve things. Would you like to look at putting together a PR to add this exception along with a test?

TheNeikos commented 6 years ago

@brendon I've opened a PR, let me know if you want anything changed!

brendon commented 6 years ago

Roger, will look at this tomorrow :D

TheNeikos commented 6 years ago

Ping :grin:

brendon commented 6 years ago

Sorry about the delay :)