Sunday, May 11, 2014

That dang checkin button...again!

As I had written a few posts back, we had been having issues with the Checkin button; it was not disabling when it should and we had initially traced the problem back to the abandon challenge functionality, where certain records were not being removed and were being associated with the wrong challenge. So, I had fixed this issue...I thought. Then it starts appearing again without any apparent rhyme or reason. When it showed up in our presentation this morning, that was the last straw. As soon as I got home, I started combing through the code again to try to figure out what I had overlooked last time. I cleaned out my database and started taking challenges, abandoning challenges, completing challenges and....ah ha! I found where the bug was occurring. When you completed a 1 checkin challenge and then went to take another challenge within that same week, a date range search was being done in order to find the latest week record associated with the current challenge. Problem was, this was being called with ".first" to return on the first matching record. Thus, if two challenges were completed within the same week by the same user, the week record associated with the first challenge taken would be returned instead of the latest week record. Fixing this issue was a simple matter of replacing ".first" with ".last".

I did some testing after this fix to make sure that it was all working correctly and everything appears to be functioning as expected. I also made a small change to the abandon challenge functionality to make sure that all the Week and History records associated with the abandoned challenge are deleted so that they do not end up causing issues later on.

No comments:

Post a Comment