3hv

beautiful code for elegant web sites

  • You are here: 
  • Home
  • form_test_helper and AJAX (update)

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.


Posted on April 24th, 2007 | By: Rahoul Baruah | Filed under Ruby on Rails and Software Development, Writing Reliable, Bug-Free Code


Leave a Reply

You must be logged in to post a comment.