Just got bitten by a bug. In a model, I was doing:

1 self.unit_price = self.product.current_price(Date.today) \
2   if self.unit_price.cents.blank?

After upgrading to Rails 0.14.3, I found some failures in my tests. About 30 minutes of sleuthing around, and I found my bug to be with the new object.blank? behavior.

Some console code to “prove” it:

 1 $ ruby script\console
 2 Loading development environment.
 3 >> 0.blank?
 4 => true
 5 >> exit
 6 
 7 $ svn up vendor\rails
 8 ...
 9  U   vendor\rails
10 Updated external to revision 2932.
11 
12 $ ruby script\console
13 Loading development environment.
14 >> 0.blank?
15 => false

So, I rewrote my code to now do:

1 self.unit_price = self.product.current_price(Date.today) \
2   if 0 == self.unit_price.cents

Again, this shows how a good set of unit and functional tests can help prevent problems before they hit you.

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on