Plots2: Create a @user.questions method to return a user's questions

Created on 31 Oct 2016  Â·  4Comments  Â·  Source: publiclab/plots2

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

The problem

We need to fetch and display the questions for a given user (like on their profile!) in a few different places, but don't have an easy way to do it -- we write a chained ActiveRecord method like here:

https://github.com/publiclab/plots2/blob/master/app/controllers/users_controller.rb#L119

It looks like:

DrupalNode.questions.where(status: 1, uid: @user.id)

Solution

We should make a method in the User model to make this easier, and reduce repetition. The user model is in: https://github.com/publiclab/plots2/tree/master/app/models/user.rb

We can add a new method (at the bottom of the file is fine) like:

def questions
  DrupalNode.questions.where(status: 1, uid: @user.id)
end

Then we could replace these two lines: https://github.com/publiclab/plots2/blob/master/app/controllers/users_controller.rb#L119-L120

with this (the double "user" is unfortunate, but has to do with some legacy issues in our database setup):

  @questions = @user.user.questions

We should also write a unit test for this new function, in: https://github.com/publiclab/plots2/blob/master/test/unit/user_test.rb

Right after line 26, we could add:

    assert user.questions.count > 0

This would confirm that, in our tests, our new method correctly returns that the user "jeff" has more than 0 questions.

Steps to Fix

  • [ ] claim this issue with a comment here, below, and ask any clarifying questions you need
  • [ ] set up a repository locally following the README instructions, and make sure that all tests pass
  • [ ] try to fix the issue following the steps above, but even before you're done, you can:
  • [ ] commit your changes and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
  • [ ] alert someone via the developers list (see below) to have your pull request merged. This may take a few extra steps depending on when you do it, but we'll help you out!

Please email the developers list (see https://publiclab.org/developers) if you have questions!

Ruby enhancement first-timers-only help wanted

All 4 comments

Hello! I wanna do this!

I'll clone the project and start working on this. I'll post any questions I have here on this thread, ok?

That would be absolutely super, Ruan! A bunch of us are here and can help
discuss, etc.

+1 336-269-1539
@lizbarry http://twitter.com/lizbarry

On Mon, Oct 31, 2016 at 3:23 PM, Ruan Brandão [email protected]
wrote:

Hello! I wanna do this!

I'll clone the project and start working on this. I'll post any questions
I have here on this thread, ok?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/935#issuecomment-257393869,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJ2nwHp2MkZdaMqnOZJg2xXUpNQu2bcks5q5kBGgaJpZM4KkpxJ
.

Hi @ruan-brandao! Thank you for reaching out to Public Lab! I would like to invite you to join us in a video conference to say a few words about what you found engaging about the Public Lab community and/or this particular github issue. The event is https://publiclab.org/openhour, and it’s coming right up on November 7th, at 1pm EDT which is UTC/GMT -4.

Please feel free to respond here, or else email [email protected], [email protected], [email protected].

Hi @ebarry. Unfortunately, I won't be able to attend to the Open Hour :disappointed:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

first-timers[bot] picture first-timers[bot]  Â·  3Comments

grvsachdeva picture grvsachdeva  Â·  3Comments

milaaraujo picture milaaraujo  Â·  3Comments

divyabaid16 picture divyabaid16  Â·  3Comments

bronwen9 picture bronwen9  Â·  3Comments