Thursday, 31 January 2008

A colleague caught this bug when we were running rake test today (Jan 31st). Suddenly the quota-calculation tests were acting weird. All our tests ran fine yesterday, so we were both pretty perplexed by why they'd suddenly stopped working today.

Quota is calculated based on a calendar month... so he delved into the fixtures looking for dates. What he came up with was a short script/console session showing the results below:

Clearly "months ago" really isn't - it's actually "30 days ago". This means that our tests will be working again fine tomorrow, just as they have been all month... and only failed because (like so *few* other months in the year), we have 31 days in January, and this is it.

The fixtures in question had something similar to "save these quota-eating things as happening one month ago and check they don't eat into this month's quota too". And yet today, "one month ago" was being evaluated as Jan 1st... :P

With experimentation, the following does work correctly, even across funky boundaries: