Skip to content

Functional tests for sorting on the /people page #9589

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

Closed
wants to merge 3 commits into from

Conversation

Manasa2850
Copy link
Member

@Manasa2850 Manasa2850 commented May 1, 2021

Partially Fixes #9411 (<=== Add issue number here)

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@gitpod-io
Copy link

gitpod-io bot commented May 1, 2021

@codecov
Copy link

codecov bot commented May 1, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@c958118). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 886ebec differs from pull request most recent head 3cabaf8. Consider uploading reports for the commit 3cabaf8 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9589   +/-   ##
=======================================
  Coverage        ?   49.41%           
=======================================
  Files           ?       98           
  Lines           ?     6122           
  Branches        ?        0           
=======================================
  Hits            ?     3025           
  Misses          ?     3097           
  Partials        ?        0           

@Manasa2850 Manasa2850 requested a review from a team as a code owner May 1, 2021 13:35
@Manasa2850
Copy link
Member Author

@jywarren @cesswairimu some observations that I made from this PR.
The test for sorting the /people page based on last_activity fails saying Expected false to be truthy. The test passes if we have "i.updated_at" <= "j.updated_at" but this is not observed in the page i.e the results are not sorted based on ascending order of last_activity too. It's randomly displayed. Not sure why the test passes but the displayed results are different.

get :list, params: { sort: 'last_activity' }

assert_response :success
assert assigns(:users).each_cons(2).all?{|i,j| "i.updated_at" >= "j.updated_at" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @Manasa2850. With the test at line 316 and 323, should the signs >= be the inverse of each other? If alphabetical and ascending, then the i should be lower than the j? j.node_revisions.username" <= "i.node_revisions.username"

And for the last activity in descending order, it does make sense for the to be greater than j as you have written..

I haven't worked with that kind of comparison before, please let me know if what I am saying does not make sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RuthNjeri since we want the username to be sorted in ascending order, I've written j.node_revisions.username" >= "i.node_revisions.username where j refers to the second entry and i to the first one.
In line 323 it is i.updated_at" >= "j.updated_at which is the same as j.updated_at" <= "i.updated_at and is the reverse of what is there in line 316.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, I think I missed the I and j difference, thanks for the clarification.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manasa2850 Maybe here we can try with i.node_revisions.maximum("timestamp")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I'll try that out!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tlazypanda it shows the same result Expected false to be truthy and the test passes on interchanging the values of i and j.

Copy link
Collaborator

@cesswairimu cesswairimu Jun 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Manasa2850, I think removing the quotes around the comparison assert assigns(:users).each_cons(2).all?{|i,j| i.updated_at >= j.updated_at } might solve this, since its a time comparison. Thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cesswairimu! That worked 🎉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great 🎉 🎉

@@ -106,7 +106,7 @@ def list
if sort_param == 'username'
order_string = 'username ASC'
elsif sort_param == 'last_activity'
order_string = 'last_updated DESC'
order_string = 'updated_at DESC'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manasa2850 I am not too sure switching this to updated_at fixes the problem. The updated_at is related to the user details I think, and the last_updated is related to the user's activities.

I could be wrong but that's something you want to confirm, when is the last_updated changed and what changes affect the updated_at in Rails, the updated_at is a default column that updates the timestamp when the user details changes in the other columns which might be unrelated to the changes detected by the last_updated which might be looking at when a user was last active on the site.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RuthNjeri I think you're right with respect to the updated_at column reflecting the timestamp when changes are made in other columns.
I don't find a column called last_updated in the User table so I'm not really sure how that's working.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manasa2850 they are fetching it in line 137 as an alias for the most recently updated node for that user 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I missed that. Thanks @Tlazypanda! 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need some input or more problem solving please reach out in chat! Thanks everyone for working together on this one!

@codeclimate
Copy link

codeclimate bot commented Jun 27, 2021

Code Climate has analyzed commit 3cabaf8 and detected 0 issues on this pull request.

View more on Code Climate.

@Manasa2850 Manasa2850 closed this Jun 27, 2021
@Manasa2850 Manasa2850 reopened this Jun 27, 2021
@Manasa2850 Manasa2850 closed this Jun 27, 2021
@Manasa2850 Manasa2850 reopened this Jun 27, 2021
@Manasa2850 Manasa2850 requested a review from cesswairimu June 27, 2021 19:07
get :list, params: { sort: 'last_activity' }

assert_response :success
assert assigns(:users).each_cons(2).all?{|i,j| i.updated_at >= j.updated_at }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test looks amiss though, because we want to order by node_revisions last updated right?
but this looks like its looking at users table last updated_at ..I will pull locally and try to find a work around and revert

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cesswairimu @Manasa2850 any more activity here? please let me know how I can help 😅 I see the tests are now passing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, the test was a bit off, might need to rewrite... this skipped my mind...will check it out soon...thanks @Tlazypanda ❤️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @Manasa2850 is overloaded a bit but will be back online very soon, so this can hold for a bit! Thanks!

@stale
Copy link

stale bot commented Sep 8, 2022

Hi 😄, this issue has been automatically marked as stale because it has not had recent activity. Don't worry you can continue to work on this and ask @publiclab/reviewers to add in-progress label 🎉 . Otherwise, it will be closed if no further activity occurs in 10 days -- but you can always re-open it if you like! 💯 Thank you for your contributions! 🙌 🎈.

@stale stale bot added the stale label Sep 8, 2022
@stale stale bot closed this Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorting by last activity does not work on the 'people' page
5 participants