Ruby on Rails Confession
Posted by Doug Tue, 21 Jun 2005 15:51:00 GMT
I have a confession to make. I coded a bunch of stuff last night without writing any tests. I feel horrible. MarkWindholtz says the feeling won’t go away until I write the tests.
I typically code and test at the same time. Only occasionally do I write tests first. But I rarely test in the browser before I’ve written both unit and functional tests. Ruby on Rails encourages you to write tests. It’s usually not that hard.
I’ve been struggling with some image handling code in my commercial Rails project (more on that later). It’s been several weeks with no progress. I’ve had to redo this code several times.
I had copied some code I wrote for RailsDay image manipulation. Unfortunately, that code was dependent on Image Magick. The Ruby bindings for Image Magick depended on a newer version of IM than what my server, running Debian Woody, had. The level of effort of upgrading that box to the newly released Debian Sarge was too much.
So, I did some hunting and found I could install Imlib2 and its Ruby bindings without too much headache. I started hacking on my old RailsDay Image Magick based code trying to get it working like I needed. The problem is the code for RailsDay has different requirements than what I have for my project. It was more complicated than what it needed to be. There was a lot of indirection that was driving me nuts.
So, I did something Mark has encouraged me to do before: I threw out all my code. My partner, Dave, was a little stressed by this. I didn’t totally throw it away. I just did a fresh checkout from CVS and put my old working directory aside. That’s when I quit testing.
Dave was concerned about me starting over (again) and I wanted to get this stuff done faster. So, I started doing what some call “Interface Driven Development”. I started adding code to my HTML views and then started filling in the backend to make that code work.
In about four hours I managed to get all my image handling working except the part for which I actually need Imlib2. Both Administrators and Users can upload images to their profile. Both admins and users can delete images from profiles. Images upload by admins are automatically approved. Images uploaded by users are automatically not approved. Administrators can view the list of not approved and can either delete them or approve them.
I think there’s still a few odd cases that need working out though. The main thing is I’m not scaling the images as thumbnails or a standard image size. Also, there are some issues with informing the user their image was disapproved and allowing users to delete their own not approved images before the admin gets around to it.
I don’t think I’m going to do much of that until I get tests though. Maybe my partner, Dave, will pair up with me to work on that together. Writing test code for handling file uploads is tedious. It always helps to have company when doing tedious work.
