Productive or wasted week?
At the beginning of the week I was exercising the web app I'm developing and came across what appears to be a bug with file uploads.
After clicking around the app a bit in my browser, I verified the problem. So I wrote an rspec story (integration test) to create a repeatable failing case. Then using rdebug, traced through the code and discovered it was not just a bug but a structural design flaw.
How could I have missed that? The feature appeared to work one case at a time, but multiple file uploads were clobbering each other. I knew this was one of the few features that didn't have much testing coverage; it was just one of those things that you implement, it seems to work, and the effort to go in and write tests after the fact seemed more than it's worth. Part of the resistance was I wasn't sure how to test file uploads.
As if you really cared, the feature is not simply a file upload field in a form. My app allows project owners to create custom forms, where one or more fields can be a file attachment. Multiple users can submit multiple forms containing multiple attachments. The user submissions have multiple views, as input forms, as a table of records, and to show a single record at a time, where each file upload needs to be rendered, for example, as a thumbnail image and/or a download link. Non-trivial anyway.
Roughly the week went like this
Monday: Discovered the problem, but didn't really get to work on it.
Tuesday: Began attacking the problem in earnest, traced the code with rdebug, determined the issue was a design flaw, not just a 'bug'. Wrote some story scenarios to illustrate it. And began fleshing out the corresponding model specs, taking a top-down + bottom-up approach.
Wednesday: Completed the model specs and coding, so the tests pass. The fixes involved some refactoring (general clean up the code) caused some other tests to fail; fixed that too.
Thursday: Fleshed out the corresponding controller specs, and discovered a few additional problems with the models that didn't show up with the unit tests. Entire test suite passes (2159 examples).
Friday: Finally returned to the story scenarios I'd written in the beginning of the week. With some fiddling mostly in the story steps, but also several views and helpers, got the stories to pass. Committed the code changes and took the evening off.
It took some research to determine how to implement testing file upload fields, they're not a normal input field. I adopted Rails' TestUploadedFile to simulate the upload, and File.exists? to verify the upload occurred (and FileUtils.rm_rf to clean out the uploads directory before each test example runs). In stories, I used the webrat attaches_file method.
So, my plans for the week on Monday were befuddled by discovering the problem, which was fixed (I sincerely hope) once and for all by Friday. Is that progress? Or did I fall behind a week?
This debugging was getting me down all week, felt like I was wasting time, but now I can move forward again.
Actually it probably would have gone faster if I hadn't kept distracting myself doing emails, chatting on irc (including offering some support on #rubyonrails), and doing stuff around the house. And the design problem required some clear headed concentration, which has become a rare commodity for me lately. And this was the first week of school for my kids so things got hectic at certain times of the day. Ok, ok, excuses, excuses.
On the other hand, the bugs were real and would have to be fixed eventually. Perhaps they occurred in the first place because the feature was not really implemented using test-first, behavior driven process. I admit, I got lazy (or rather, very distracted) a few months ago when I first implemented that code, and I paid for that now.
I need to write a few more story scenarios to complete the testing but otherwise I'm ready to move forward next week with what I was planning to work on this week...
Comments
New Comment