avoinministerio/avoinministerio — pull request #218 by jyrkive (2012-08-06 09:52:02+00:00)
Title: Fix invalid vote counts

It turned out that Pull Request #153 didn't completely fix invalid vote counts. As Aleksi guessed, the problem was caused by the fact that the option (either 0 [vote against] or 1 [vote for]) that the controller passed to Idea#vote was a string rather than an integer. When Idea#update_vote_counts compared the option to zero (integer), it never matched. Therefore every single vote incremented the votes_for count, even if the vote was against the idea. In addition, if the previous vote from the same citizen was against the idea, the votes_against_count was decremented. As a result, changing the vote continuously between "yes" and "no" kept incrementing votes_for_count and decrementing votes_against_count.

Aleksi's fix in Pull Request #217 was correct, but it also assumed that the old option (which the citizen previously chose) was a string as well. However, it's an integer. Therefore Aleksi's fix caused another, and a more severe, bug.

This is the proper fix that works according to my manual testing and unit tests. I also fixed the tests so that they pass a string rather than an integer to Idea#vote.

Finally, regarding existing vote counts I'd be on the safe side and re-run the script in Pull Request #153.