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.

This article is obsolete. It does not have a replacement.

After updating my externals to Rails 0.14.1, I ran into a few snags. First one is a difference in the handling of boolean attributes between both versions. I had the following assertion:


1 class EstimateTest < Test::Unit::TestCase
2 def test_converts_base_information_to_quote
3 # …
4 assert_equal e.pst_active, q.pst_active, copied pst active
5 end
6 end

q is an instance of Quote, and e is an instance of Estimate. In both cases, pst_active determines if the provincial tax is active. It is a boolean attribute, but I had forgotten to use the attr_name? form. In 0.13.1, this worked, but with 0.14.1, it failed with the following:


1 1) Failure:
2 test_converts_base_information_to_quote(EstimateTest) [./test/unit/estimate_test.rb:493]:
3 copied pst active.
4 <1> expected but was
5 <true>.

When I switched both calls to pst_active to the boolean form, the assertion passed again.

Next, I had 44 failures in my functionnal tests:


1 44) Error:
2 test_destroyed_pictures_dont_appear_in_the_slideshow(WelcomeControllerTest):
3 TypeError: cannot convert Symbol into String
4 D:/rails-app/config/../lib/productize.rb:38:in `+’
5 D:/rails-app/config/../lib/productize.rb:38:in `full_template_path’

This application makes use of the Rails Product Generator. Notice the bug is in lib/productize.rb, and not my code per se. Line 38 of lib/productize.rb looks like this:


1 site_specific_path = File.join(SITE_ROOT, app, views, template_path + . + extension)

I corrected the error by simply calling to_s on both template_path and extension.

After that, my tests ran perfectly ! Shows how important it is to have even a minimal test suite.

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