Skip to content
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

Prevent upvoting or downvoting multiple times on the same restroom #520

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

translatorzepp
Copy link

Context

Summary of Changes

  • After up- or downvoting a restroom, store that restroom ID in session and prevent tallying further votes for that restroom
  • Add a flash message in English and Spanish

Concerns

  • I left off Javascript changes to disable the buttons, but I'd be happy to add it in if folks think it would be nice!
  • I think we're safe to put database IDs into session since it's encrypted, but if anyone has concerns about leaking information, let me know.

Checklist

  • Tested Mobile Responsiveness
  • Added Unit Tests
  • CI Passes
  • Deploys to Heroku on test Correctly (Maintainers will handle)
  • Added Documentation (Service and Code when required)

Screenshots

After

already-voted

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Oct 27, 2018

Thank you for this!

Hopefully @mi-wood or @tkwidmer can take a look at this, since they have dealt with this part of the code more than me. But on first look, this appears pretty good!

I'm not familiar with the Rails session concept, so I'll perhaps take a look into that before merging.

In any case... Happy Hacktoberfest! 🎃 💻 ✨ 🍂

@DeeDeeG DeeDeeG added bug enhancement Ready for Review Hacktoberfest These are issues or pull requests related to Hacktoberfest (https://hacktoberfest.digitalocean.com/) labels Oct 27, 2018
Copy link
Member

@mi-wood mi-wood left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request! I've left a few comments about reducing the complexity of the _vote_for_restroom method. Other than that, this look good!

@@ -76,6 +76,15 @@ def find_restroom
@restroom = Restroom.find(params[:id])
end

def _vote_for_restroom(up_or_downvote)
if session[:voted_for] and session[:voted_for].include? @restroom.id
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of the if session[:voted_for] and just automatically create that at the beginning? It would be premature, but also reduce the complexity of these conditionals.

@@ -76,6 +76,15 @@ def find_restroom
@restroom = Restroom.find(params[:id])
end

def _vote_for_restroom(up_or_downvote)
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to break this into a service and reduce the complexity of the controller/tests. There's an example here: https://github.com/RefugeRestrooms/refugerestrooms/tree/develop/app/services

flash[:notice] = I18n.t('restroom.flash.alreadyvoted')
else
Restroom.increment_counter(up_or_downvote, @restroom.id)
session[:voted_for] = session[:voted_for] ? session[:voted_for].push(@restroom.id) : [@restroom.id]
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, this would become a lot easier to read and would probably fix the code climate error.

@DeeDeeG DeeDeeG mentioned this pull request Mar 19, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement Hacktoberfest These are issues or pull requests related to Hacktoberfest (https://hacktoberfest.digitalocean.com/) Ready for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants