Tags:

data mining   fail save   gentoo   html2pdf   lazykid   mod_fcgid   nothing to hide   onetime password   open office   otp   privacy   ruby   ruby on rails   security   test driven development  

Last update
(Nov 25 2007)

Test driven development is your friend

Friday 02 November 2007 - 01:45 by sven

tree in front of sea

Since I started programming in ruby, I tried to force myself to do test driven development. The pain of writing the test first and the actual code later prevents me from over engineering and makes me focus better on the actual problem I want to solve.

Knowing about the great benefits of test driven development, I completely ignored them when I needed a file upload functionality in my new bewiso interface based on ruby on rails. The first test I wrote did not work and after I found out that there was an unpatched bug related to testing file uploads, I removed my test and forgot about the issue.

This turned out to be a big mistake. One month later, I manually tested my file upload to check if my layout would look nice with an embedded picture. The upload failed and ruby complained with this error message:

 undefined method `original_filename' for "#<File:0xb71f0cb8>":String

After a bit of reading I found out that the uploaded file is supposed to be available as 'File' object or as 'StringIO' object if the file is bigger than xy.
The string object was not expected. As I did a rails update some days ago and had a new version of actionpack in use, I started looking into lib/action_controller/cgi_ext/cgi_methods.rb and lib/action_controller/cgi_process.rb but could not find any obvious problems. After reading the changelog of actionpack and getting more and more frustrated I found the line that caused all my trouble by accident.

before_filter :validate_utf_params , inside my application controller. This calls a method that goes through my params and makes sure that there are no wired utf8 characters inside the data. It crashed my params object as I did not expect to find something different than a string.

Lesson learned; write tests even for obvious stuff. If I had followed my own procedures with care I would have found this problem immediately after I checked in the utf8 stuff.


ruby on rails test driven development ruby

Make a Comment!