View Rahoul Baruah's profile on LinkedIn Basecamp project management and collaboration

The blog of Rahoul Baruah from 3hv Ltd

What's going on?

My name is Rahoul Baruah (aka Baz) and I'm a software developer in Leeds (England).

This is a log of things I've discovered while writing software in Ruby on Rails. In other words, geek stuff.

However, I've decided to put this blog on ice - I would ask you to check out my business blog here (or subscribe here).

24 April, 2007

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:

eXTReMe Tracker