form_test_helper and AJAX (update)

Jason Garber has updated his excellent form_test_helper plug in to support XmlHttpRequests.

Rather than the clumsy code I showed before you can now test your Ajax form with a simple and elegant:

# test in non AJAX modethingy = Thingy.find 1get :edit, :id => thingy.idassert_response :success

submit_form do | form |  form['thingy[field]'] = 'wotsit'endassert_redirected_to thingy_path(thingy)thingy.reloadassert_equal 'wotsit', thingy.field

# test in AJAX modexhr :get, :edit, :id => thingy.idassert_response :successassert_rjs :replace_html, "thingy_panel"

submit_form :xhr => true do | form | form['thingy[field]'] = 'doodah'endassert_response :successassert_rjs :replace_html, "thingy_panel"assert_rjs :visual_effect, :highlight, "thingy_panel"thingy.reloadassert_equal 'doodah', thingy.field

Note: the fantastic example above also uses Kevin Clark’s ARTS plug in for testing the RJS responses.

So what are you waiting for? Fire up that subversion client and get downloading.

Thanks Jason.

This entry was posted on Tuesday, April 24th, 2007 at 8:55 pm and is filed under Ruby on Rails and Software Development, Writing Reliable, Bug-Free Code. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply