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

Fixing #4822 daily vs weekly subject #4955

Merged
merged 5 commits into from
Mar 11, 2019

Conversation

IshaGupta18
Copy link
Collaborator

@IshaGupta18 IshaGupta18 commented Mar 8, 2019

Fixes #4822

So it works locally now on changing the value of k(parameter for daily v/s weekly):

weekly:
image

daily:

image

@plotsbot
Copy link
Collaborator

plotsbot commented Mar 8, 2019

1 Message
📖 @IshaGupta18 Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

@IshaGupta18
Copy link
Collaborator Author

Hey @jywarren, I think the code climate issues are very trivial and can be ignored. However, I fail to understand the travis build fail. Could you please explain what happened and what can be done to fix it?

@@ -54,10 +54,14 @@ def notify_tag_added(node, tag, tagging_user)
)
end

def send_digest(user_id, top_picks)
subject = "Your weekly digest"
def send_digest(user_id, top_picks, k)
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 give this parameter a more informative name, so people understand when reading the code? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Also, maybe top picks could just become "nodes", you know?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes absolutely, and I am gonna rename top_picks parameter to nodes then?

top_picks = content_followed_in_period(1.week.ago, Time.now)
if top_picks.count.positive?
SubscriptionMailer.send_digest(id, top_picks).deliver_now
if self.has_tag('digest:daily')
Copy link
Member

Choose a reason for hiding this comment

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

nice!

if top_picks.count.positive?
SubscriptionMailer.send_digest(id, top_picks).deliver_now
if self.has_tag('digest:daily')
top_picks = content_followed_in_period(Time.now - 1.day, Time.now)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure, but I think @siaw23 was able to use 1.day.ago instead of subtracting... maybe worth a try cause it's short?

top_picks = content_followed_in_period(Time.now - 1.week, Time.now)
k = 1
end
if top_picks.count > 0
Copy link
Member

Choose a reason for hiding this comment

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

This is where the error points to.


ERROR["test_send_digest_email", #<Minitest::Reporters::Suite:0x00005572aa9d18a0 @name="UserTest">, 24.959422129000018]
 test_send_digest_email#UserTest (24.96s)
NoMethodError:         NoMethodError: undefined method `count' for nil:NilClass
        Did you mean?  concat
            app/models/user.rb:326:in `send_digest_email'
            test/unit/user_test.rb:225:in `block in <class:UserTest>'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yes, so probably because the daily top_picks were empty, that's why it couldn't trigger the condition, should I put a nil check there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I tried to a check like !top_picks.nil? && top_picks.count > 0 , however another error showed up in travis.

Copy link
Member

Choose a reason for hiding this comment

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

Sure or as i said above, you can start by defining it as []. Great!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have tried both, but still, the new error prevails, could you please tell me why?

if self.has_tag('digest:daily')
top_picks = content_followed_in_period(Time.now - 1.day, Time.now)
k = 0
elsif self.has_tag('digest:weekly')
Copy link
Member

Choose a reason for hiding this comment

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

Aha - so if a user has /neither/ tag set, we are still trying to call top_picks. We should set it to [] by default? We could define it above as top_picks = [] before these IFs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I thought of doing the same, but I didn't. So sorry!

Copy link
Member

Choose a reason for hiding this comment

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

no worries!

@jywarren
Copy link
Member

jywarren commented Mar 8, 2019

Hmm, i see in Travis:

 FAIL["test_send_digest_email", #<Minitest::Reporters::Suite:0x00005629dcddcc30 @name="UserTest">, 41.071117536999964]
 test_send_digest_email#UserTest (41.07s)
        Expected nil to be truthy.
        test/unit/user_test.rb:225:in `block in <class:UserTest>'

So do you see how to look up that line where the error occurred? See how it points here: https://github.com/publiclab/plots2/blob/master/test/unit/user_test.rb#L225

Are we sure that send_digest_email still returns something that's not nil?

freq = 1
end
if !top_picks.nil? && top_picks.count > 0
SubscriptionMailer.send_digest(id, top_picks, freq).deliver_now
Copy link
Member

Choose a reason for hiding this comment

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

aha, so could it be that the test was set up such that the test user doesn't actually have these tags, and so is now not getting the digest email?

Also, if you wouldn't mind changing top_picks to nodes or subscribed_content perhaps, that'd be nice, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh it could be that! Yeah sure, I will change it here as well, as I did in the mailer!

@jywarren
Copy link
Member

jywarren commented Mar 8, 2019

Isha this is going really well. You're getting better and better at tracing errors through the logs, figuring out what they mean and what caused them, and identifying the spot in the code where you need to make a change. Travis tests can really help guide your debugging, so it's great to build that skill set!

@IshaGupta18
Copy link
Collaborator Author

Thanks a lot! Yes, I think that's very important too. I do know how to look up for the errors and find the files that caused them. Let me try another hand at debugging this one!

@IshaGupta18
Copy link
Collaborator Author

@jywarren so the checks have passed, I think I caught the error somewhere in user.rb 🎉 . Kindly review and let me know if its ready to be merged! Thanks a lot!

@jywarren jywarren merged commit 59dbc83 into publiclab:master Mar 11, 2019
@jywarren
Copy link
Member

Fantastic work, @IshaGupta18 !!!

icarito pushed a commit to icarito/plots2 that referenced this pull request Apr 9, 2019
* Fixing publiclab#4822 daily vs weekly subject

* fixing small changes

* fixing changes

* spaces

* trying to fix bugs
SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* Fixing publiclab#4822 daily vs weekly subject

* fixing small changes

* fixing changes

* spaces

* trying to fix bugs
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.

3 participants