Skip to content

Conversation

@delusioninabox
Copy link
Contributor

@delusioninabox delusioninabox commented Jan 4, 2019

Requirements

  • Gets all active users
  • Search responses of active question for users who have NOT answered
  • Sends out reminder to those users before results sent

Tests

  • Gets only active users
  • Pings only users who haven't answered

@delusioninabox
Copy link
Contributor Author

Need to mock out the post_slack_msg method but I think that'll have to be a separate PR.

include Sidekiq::Worker
def perform

# First check there is an active question
Copy link

Choose a reason for hiding this comment

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

We should use guard clauses instead of nesting conditionals. If there are no open questions or no active users we can return from this method. Then the following code will be much more straightforward to read

if all_users
all_users.each do |user|
# Has this user answered?
if todays_question.responses.where(user: user).none?
Copy link

Choose a reason for hiding this comment

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

The above if can also be a guard clause

Copy link

Choose a reason for hiding this comment

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

It may be better to add a scope or class method to the user model to query only users who haven't answered today's question from the DB instead of loading all users from the DB and then checking if they've answered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to write this as a scope is making my head spin. 😭I can get where they haven't answered, but once I try to include the criteria of only where the question is open, it all breaks.

class User < ApplicationRecord
  has_many :responses

  scope :hasnt_answered, -> {
    where(active: true).left_outer_joins(:responses => :question).where(responses: {user_id: nil, question: {open: true}})
  }
end

message = ":bow: Sorry to disturb your work…I haven’t received an answer from you yet. :pray: I'm a good listener if you have a few minutes. :ear:"
attachments = []
# Get all active users and DM them the question
PostToSlack.post_slack_msg( user.ucode, message, attachments )
Copy link

Choose a reason for hiding this comment

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

Can you remove the padding spaces inside of parens? It's against our style guide

@johnkoht
Copy link
Member

This looks pretty good. I think Lawrence had some really good feedback for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants