Closed jmuheim closed 7 years ago
Hi @jmuheim, can you upgrade to the latest 0.8.x version and see if you're experiencing the same failure?
Yes I do.
Ok, thanks for that. Are you able to isolate this failure so that you don't rely on acts_as_tree
? That gem might be calling another callback that modify's the position again. Take a look at the SQL executed and that might also give us a clue as to what's going on.
@jmuheim, can you let us know where you're at, or close the issue if you've managed to sort it out :)
@jmuheim, I'm closing this for now. Let me know if you want to reopen it. Also, try master
and see if that fixes the problem.
I'm sorry for not responding. The problem has disappeared with the newest version.
Thank you.
Great to hear! :)
Just in case anyone else ends up here.
I was upgrading from 0.6 and tests started to fail when going from 0.7.2 to 0.7.4. All list items had position "1".
We are using Factory Girl 4.5 and Rails 4.2. This is how the code looks that was creating the list items list.items << create(:item)
Once I changed it to create(:item, list: list)
things started to work again.
Note that we are using acts_as_list with a scope.
Looks like the position is first calculated when the list item is created (with scope "list_id = nil") which gives position "1". Appending the item to a list (using "<<") does not re-compute the position. So, supplying a list when the item is created fixes the problem.
Could be an issue with FactoryGirl that has been corrected long time ago.
That's a strange one. Changing the list and re-saving the item should change the position to the next available position in the list. But you're right, supplying the list on create will give you correct positions :)
@calleo, looking at this further, I'm wondering if <<
runs any callbacks on the item being appended to the list? It needs to run the callbacks to pick up the change in scope, otherwise its position will remain as it is.
If you wanted to look into this further, feel free :) I'm happy to provide some guidance if necessary :)
I have the following model:
With the following test:
end
With
acts_as_list
v0.7.2, it passes:With v0.7.4, it doesn't:
Any idea what's going on here?