<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net: Ruby on Rails Confession</title>
    <link>http://blog.lathi.net/articles/2005/06/21/ruby-on-rails-confession</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Ruby on Rails Confession</title>
      <description>I have a confession to make.  I coded a bunch of stuff last night without writing any tests.  I feel horrible.  &lt;a href="http://lathi.net/twiki-bin/view/Main/MarkWindholtz"&gt;MarkWindholtz&lt;/a&gt; says the feeling won&amp;#8217;t go away until I write the tests. &lt;img alt="frown" src="http://www.lathi.net/twiki/TWiki/SmiliesPlugin/frown.gif" /&gt;
&lt;p /&gt;
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&amp;#8217;ve written both unit and functional tests. &lt;a href="http://rubyonrails.com" target="_top"&gt;Ruby on Rails&lt;/a&gt; encourages you to write tests.  It&amp;#8217;s usually not that hard.
&lt;p /&gt;
I&amp;#8217;ve been struggling with some image handling code in my commercial Rails project (more on that later).  It&amp;#8217;s been several weeks with no progress.  I&amp;#8217;ve had to redo this code several times.
&lt;p /&gt;
I had copied some code I wrote for &lt;a href="http://lathi.net/twiki-bin/view/Main/RailsDay"&gt;RailsDay&lt;/a&gt; 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.
&lt;p /&gt;
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 &lt;a href="http://lathi.net/twiki-bin/view/Main/RailsDay"&gt;RailsDay&lt;/a&gt; Image Magick based code trying to get it working like I needed.  The problem is the code for &lt;a href="http://lathi.net/twiki-bin/view/Main/RailsDay"&gt;RailsDay&lt;/a&gt; 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.
&lt;p /&gt;
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&amp;#8217;t totally throw it away.  I just did a fresh checkout from &lt;span class="caps"&gt;CVS&lt;/span&gt; and put my old working directory aside.  That&amp;#8217;s when I quit testing.
&lt;p /&gt;
Dave was concerned about me starting over (again) and I wanted to get this stuff done faster.  So, I started doing what some call &amp;#8220;Interface Driven Development&amp;#8221;.  I started adding code to my &lt;span class="caps"&gt;HTML&lt;/span&gt; views and then started filling in the backend to make that code work.  
&lt;p /&gt;
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.  
&lt;p /&gt;
I think there&amp;#8217;s still a few odd cases that need working out though.  The main thing is I&amp;#8217;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.
&lt;p /&gt;
I don&amp;#8217;t think I&amp;#8217;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.</description>
      <pubDate>Tue, 21 Jun 2005 10:51:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:654ab2dbe46f4531ab991709e325ef4f</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2005/06/21/ruby-on-rails-confession</link>
      <category>Ruby on Rails</category>
    </item>
  </channel>
</rss>

