Future on Rails

Using Rails

Nested Forms & Webrat

leave a comment »

I love the new features of Rails 2.3 – one beeing the support for nested forms (forms which let you edit multiple models and associations). However, I ran into some problems with this new approach: 1) Making complex forms with AJAX work with the Rails 2.3 approach and 2) Testing those forms with Cucumber and Webrat.

1) Making complex forms with AJAX work with the Rails 2.3 approach

When I tried to use the approach from Ryan Bate’s railscast “Complex Forms Part 3”, ran into several issues with organizing my partials and getting the HTML and Javascript right. Fortunately, Ryan addressed this issue himself => see his github project.

2) Testing those forms with Cucumber and Webrat

Another problem I ran into was testing a complex AJAX form with the new nested forms. Imagine the default app for managing projects, where each project has multiple tasks. To add tasks to a project, I can simply click “Add Task” on the project’s edit page and add form fields dynamically via AJAX. However, how would you address those fields in a cucumber step using webrat?

Given I am on the project edit page
When I click “Add Task”
And I fill in ??? with “my new task”
And I click “Save”
Then I should see …

What to insert for the “???” ? Those fields all have the same label (“Task:”) and the name/id is very cryptic, containing a randomly generated id. I couldn’t find an elegant solution for this issue yet. Please tell me if you know of any solution!

Advertisements

Written by Matthias Orgler

September 30, 2009 at 1:21 pm

Posted in Uncategorized

Tagged with , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: