-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use unscoped blocks instead of chaining #121
Conversation
Chaining unscoped with further scopes negates the unscoped call as per the documentation: http://apidock.com/rails/ActiveRecord/Base/unscoped/class
My testing of this in my app confirms it's now working properly. |
There are loads of Rails 4 errors in the test suite. Can you please look into them ? |
It's failing because of another bug: #119. Do you want to merge that pull request in or do you want that fixed as part of this pull request? |
Ok, this is messy, I'm getting random test failures. Sometimes I get a full passing suite, other times lots of failures. I think something fishy is going on with the database cleaning here? With regards to #119 you can probably do: Here's my gems list if it helps:
Running |
Ok, I've fixed a couple of bugs in the tests, but there is still something funky going on with Rails 4. I suspect some kind of caching in the connection? It randomly returns different results (sometimes everything passes, sometimes things are out of order). I think the acts_as_list code itself is fine, it's down at the connection layer that things are going awry. I've spent a morning trying things (connection pool to 1, forcing only one connection, only creating the tables once at the start of the test and then truncating them using database_cleaner. Nothing works. Maybe there is a bug with the sqlite memory interface? |
Unless the position is explicitly supplied when changing scopes, the item should be added to the end of the list. To do this, we need to keep track of whether the position column has been set. Merely tracking _changed doesn’t cut it as sometimes we will supply a new position that was the same as the position the item had in the old scope. increment_positions_on_lower_items now has an avoid clause and I’ve fixed a buggy test and adjusted the expectations of another to reflect the proper logic.
Ok, I've spent waaaaay too long on this! I hope you don't mind me bundling these clarifications in, but changing scopes wasn't being handled properly when it came to keeping the position values clean between scopes. If you moved an item from a scope that had many items to a scope that had fewer, the position wouldn't be updated to be the next integer at the bottom of the list, it'd remain at its large value. I've updated the code to handle this situation better. You also had a broken test that only passed because you moved an item that would have had the same position in both scopes (co-incidence). I think there are few more tests like this in the suite - fortunately too because one failing test taught me that one can't rely on the dirty functionality of active record if the position is explicitly set to what it already was. Anyway, all the tests pass in Rails 3. I did't write any new tests as there doesn't seem to be anything new to test. With regards to the failures in Rails 4, It looks like the tests aren't being executed in the same order each time. Perhaps some assumption in the test suits is causing them to fail in this case. Maybe the included shared tests aren't being included in the same order each time? |
I've done some extra testing. Rails 4 seems to cause these tests to fail on occasion due to the testing of the default column value. Re-creating the table with or without the default value doesn't seem to be enough to clear whatever cache exists, and so sometimes records that should be created without a default value on the position column, get a default value of 1. That's not even what the default value is set to in the table definition, but that's what's happening. I'd appreciate your help on this if you wouldn't mind. :) |
Sorry for not responding yet, I've been out of action for over a week now. On Thu, May 29, 2014 at 12:31 AM, Brendon Muir notifications@github.comwrote:
|
Thanks for that. I've found the main problem is that after changing the table (by removing and recreating it with the modified default value, we're not calling |
- Force Minitest 5+ to reveal test ordering issues - Use new Minitest class name - Fix check_top_position to not clip the position value if a default column is in play
Ok, the tests pass now. Not sure what the rbx stuff is all about, but Rails 3 and 4 with MRI pass fine. As you can see from the latest commit, there was a bug in the code relating to the highest position ceiling and default column values. I've also forced Minitest 5 which was what the Rails 4 tests were using (which is why the Rails 3 tests passed). I think they changed the way test ordering was decided between 4 and 5. Calling |
Hi Swanand, are you able to look at merging this in? It passes all the tests and even fixes some bugs that currently existing master. Let me know if you have any questions. |
ok, trying this now. |
Thanks Swanand :) |
@@ -155,7 +155,7 @@ def test_update_position_when_scope_changes | |||
assert_equal 3, ListMixin.where(id: 4).first.pos | |||
|
|||
ListMixin.where(id: 2).first.move_within_scope(5) | |||
assert_equal [1, 2, 3, 4], ListMixin.where(parent_id: 5).order('pos').map(&:id) | |||
assert_equal [1, 3, 4, 2], ListMixin.where(parent_id: 5).order('pos').map(&:id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendon : This seems a bit suspicious. Why would we need to change the order ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Swanand, this is because moving a node into a new scope should add the node to the end of the list unless the position is explicitly specified in the update. Seems like the most reasonable expectation :)
This is great, thanks @brendon for the hard work |
I added you as a collaborator on the repo. |
Thanks Swanand :) Glad to be able to help! |
Would it be possible to have a new gem release now that #119 is able to be closed? |
Chaining unscoped with further scopes negates the unscoped call as per
the documentation: http://apidock.com/rails/ActiveRecord/Base/unscoped/class
Issue: #120