Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails functional test assert_select form input value?

I'm writing a simple test to check that a form is loading the correct values.

I've looked through the docs and can't seem to find an example that shows how to verify the value of a form input.

I have a form that renders the first_name of a user.

I just want to use assert_select on the text input and verify that the first_name field matches what's in the database exactly (e.g users(:one).first_name)

How does one do this in Rails?

like image 906
Leonard Teo Avatar asked Aug 20 '12 14:08

Leonard Teo


2 Answers

Actually the assert_tag is deprecated.

There's a good example of how to do this with assert_select in the documentation, so you could do this:

    assert_select '#user_first_name' do
      assert_select "[value=?]", Users.first.first_name
    end
like image 82
nashape Avatar answered Nov 14 '22 20:11

nashape


Checkbox: If you want to assert_select a checked checkbox (in this case 1 checked checkbox), try this:

assert_select 'input[type=checkbox][checked]', 1

Not 100% related to the question, but more for documentation purpose for others.

like image 2
fydelio Avatar answered Nov 14 '22 22:11

fydelio