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 mode
thingy = Thingy.find 1
get :edit, :id => thingy.id
assert_response :success
submit_form do | form |
form['thingy[field]'] = 'wotsit'
end
assert_redirected_to thingy_path(thingy)
thingy.reload
assert_equal 'wotsit', thingy.field
# test in AJAX mode
xhr :get, :edit, :id => thingy.id
assert_response :success
assert_rjs :replace_html, "thingy_panel"
submit_form :xhr => true do | form |
form['thingy[field]'] = 'doodah'
end
assert_response :success
assert_rjs :replace_html, "thingy_panel"
assert_rjs :visual_effect, :highlight, "thingy_panel"
thingy.reload
assert_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.
No comments:
Post a Comment