-
Notifications
You must be signed in to change notification settings - Fork 864
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
Accept arguments for #count
#303
Conversation
Why do you need to count distinct entries on a paginated collection? will_paginate's testing conventions aren't anything special. You set up some data in the database (I use fixtures), then call the method and assert that you got the value you expected. I'm not happy with the current hack I did for |
I came up with a request which I have to denote Honestly, I believe that it is a bug of ActiveRecord ( So, for now I should write tests and it will be enough, correct? |
If AR Relation accepts arguments to |
Ok! I'll be back with tests soon. |
+1 Want to be able to pass |
Need to same feature for the same reason as @cyrusstoller. Thanks @DanielVartanov. |
@DanielVartanov Are you adding tests for this and rebasing to master? |
@nathany procrastinating, unfortunately. I publicly announce, that it will be done by June 2nd, 00:00 UTC. I offer to put me in shame if I don't! But I will :-) |
😄 |
@mislav Please review the updated commit (sorry for a force-push). |
Thanks @DanielVartanov. There is still another issue with count internally from will_paginate if there is a select scope. It can be fixed with |
@@ -205,6 +205,11 @@ | |||
$query_sql.last.should_not =~ /\ORDER\b/ | |||
end | |||
|
|||
it "accepts arguments for #count" do | |||
Project.page(1).count(distinct: true) |
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.
I wish this test was more solid. It should assert the result of count
. The data and the query should be set up in a way that makes count()
yield different results depending on whether it was with or without arguments. This way we're sure that the arguments really got forwarded and that the correct SQL query was executed. Then there will be no need for inspecting the query directly on the next line.
Also, if such test passes on CI, we are confident that it works in all combinations of Active Record + db adapter versions.
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.
In the end I removed this test before merging, since it didn't yield the same results on all Rails versions that we test with (~ half of them failed)
Sometimes it is needed to call
relation.count(distinct: true)
. I am not sure what is the best way to test it within will_paginate's testing conventions. Can you guys give me some advice?Thanks in advance.