Assert_select tag in Rails 1.2.2

Rails 1.2.2 names the form elements like contact[subject],
contact[body] and so on. The following code does not work in latest
version.

def test_login_form_has_all_fields
get :login
assert_select “form[action=http://myapp/login] input” do |inputs|
assert_equal 3, inputs.size
assert_select inputs[0], “input[type=name][name=username]”
assert_select inputs[1], “input[type=password][name=password]”
assert_select inputs[2], “input[type=submit][value=Login]”
end
end

When the name is changed to contact[subject] format, it bombs out
saying square brackets are not right selector.

Does anyone know how to check the form elements using assert_select
tag? TIA.

bcparanj wrote:

Does anyone know how to check the form elements using assert_select
tag? TIA.

You could query by id, typically “user_username”.

I just do this. Much more powerful:

form = select_form ‘my_form_id’
assert_equal ‘foo’, form[‘user[username]’]
form.submit


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!