Skip to content

Instantly share code, notes, and snippets.

@trendwithin
Created March 22, 2016 20:12
Show Gist options
  • Save trendwithin/1d2a6721c89d5bf91f51 to your computer and use it in GitHub Desktop.
Save trendwithin/1d2a6721c89d5bf91f51 to your computer and use it in GitHub Desktop.
Devise Confirmable Capybara Test
scenario 'HP: User Sign Up w/ Confirmable Email and Log in ' do
  visit new_user_registration_path
  fill_in 'Email', with: '[email protected]'
  fill_in 'Password', with: 'password'
  fill_in 'Password confirmation', with: 'password'
  assert_difference 'User.count', 1 do
    click_button 'Sign up'
    mail = ActionMailer::Base.deliveries[0]
    token = mail.body.decoded.match(/confirmation_token=([^"]+)/)[1]
    assert_equal User.find_by(email: "[email protected]").confirmation_token, token
    visit "users/confirmation?confirmation_token=#{token}"
    page.must_have_text "Your email address has been successfully confirmed."
    fill_in 'Email', with: '[email protected]'
    fill_in 'Password', with: 'password'
    click_button 'Log in'
    page.must_have_text "Signed in successfully."
  end
end
@melashu
Copy link

melashu commented Jan 10, 2023

Thank you very much! It helps me alot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment