Monday, June 16, 2008

Rails Asserting Image Encoding

This is a little thing, but it took me a bit to figure out today. Basically, in this project we had an issue where people uploaded photos and they "rendered funny". Turns out the problem was that no matter what was uploaded we set the MIME type to "image/gif". Hence, jpgs (and anything not gif) "rendered funny".

So I wanted to write a test to show the problem. Here's what we wound up with... easy, once you know what on earth that is called:

def test_image_display
   get :image, {:id => "28"}, {:session_id => "3"}
   assert_equal "image/jpg", @response.content_type

This should work for non-image MIME types as well - XML, etc. - although I've only tried images so far.

No comments:

Post a Comment