Search code examples
ruby-on-railstestingcapybaraminitestsystem-testing

Sign up user and then visit account page with system tests?


If I've understood it correctly, creating a user in a form like below doesn't create a record in the database.

I want to create a system test to follow these steps:
1. Sign up in a form
2. Visit account pages
3. Update account information

What technique would allow to accomplish the above scenario?

within 'form#t-signup-form' do
    fill_in 'first_name', with: 'Eve'
    fill_in 'last_name', with: 'Farmer'
    fill_in 'email', with: '[email protected]'
    fill_in 'password', with: 'Something'
    find('button').click
end

Solution

  • Whether or not a User record is actually committed to the database is dependent on whether or not you are using transactional testing. If you are using transactional testing then a record doesn't actually ever get committed, but it shouldn't matter because (if configured correctly) everything in your test and app should be accessing the same pre commit transaction and therefore see the record. To do what you're asking you would just do

    visit signup_path #whatever is the correct route to the page with the signup form
    within '#t-signup-form' do
      fill_in 'first_name', with: 'Eve'
      fill_in 'last_name', with: 'Farmer'
      fill_in 'email', with: '[email protected]'
      fill_in 'password', with: 'Something'
      find('button').click
    end
    assert_content('You are signed up!') # assert for visible change in page that indicates signup has succeeded
    visit account_path # route to whatever page you want to go to
    ... # do whatever actions are required to update the account