31 January 2007

RMagic and Fedora Core 6

So it turns out that installing the rmagic gem requires you to install the Microsoft True Type fonts. This seems like a very odd requirement to me. Maybe there is a flag that says install the gem without the fonts, but I could not find it. Fedora Core 6 does not come with an rpm to install the corefonts. You need to visit corefonts.sourceforge.net. Daniel Resare has put together all of the resources that you need to build your own rpm. You may want to visit Mauriat Miranda’s site for lots of good fc6 information including corefont stuff.

The rpm I built installed the fonts in the wrong place. I had to move them from the /usr/share/fonts/msttcorefonts directory to the /usr/share/fonts/default/TrueType directory. After this, ‘gem install rmagick’ worked like a charm.

11 January 2007

Integration Testing Rails

After reading Jamis’s excellent blog about integration testing a ruby on rails app, I decided to take the plunge and write my first integration test. I have never cared much for testing, but with the wonderful testing architecture set up in rails, I have started to actually enjoy it. I now write many tests before I finish coding anything else. I have found it to be very useful and I suspect it has saved me a lot of debugging time. I was kind of forced into this recently because there was no way to test my most recent code with a browser for our iMemoryBook product. The only way I could actually see if what I was writing worked at all was to write a series of functional tests. Today, though, I found I needed to test how two controllers worked together. Hence my need for learning about integration tests.

Duane had written one integration test already so I had a good example to go by, but there was one thing that I did not know how to do. This is why I am writing now, to share what I learned.

05 January 2007

Setting the Accept header

Our site is running on edge rails and we are using the new REST interface. The site also uses a lot of Ajax to make requests that only accept XML as a response. Setting the accept header turned out to be very easy…Just add the header information to the third parameter of the request, which is a hash of HTTP headers.

put "/bookshelf/1/sections/5",
{ :lp => 0,
:pvW => 300,
"section[title]" => "New title",
"section[body]" => "new very short body" },
{ "Accept" => "text/xml" }

In this example I invoke the sections_controller’s update method because of the put call and I will receive my response in XML because I set the Accept header to “text/xml”. Now that I understand this, I can write integration tests for the rest of the application.