Skip to content
Snippets Groups Projects
Select Git revision
  • 16b5777ed84f35eb1c3885b0577b54543edf7f80
  • eip-develop default
  • develop
  • 0valt/assorted
  • master
  • 0valt/flag-sort
  • 0valt/rlyeh
  • art/versioned-error-logs
  • 0valt/csrf
  • dependabot/bundler/bundler-6d4d941ed1
  • dependabot/npm_and_yarn/npm_and_yarn-a48ea45f8c
  • 0valt/caching
  • art/mod-spam-tools
  • 0valt/keyboard
  • 0valt/1808/unnecessary-ajax
  • 0valt/general-fixes
  • 0valt/tour-fixes
  • 0valt/1815/tags-ordering
  • 0valt/voting-improvements
  • 0valt/1459/draft-discard
  • 0valt/1790/preferences
  • 0valt/query-optimizations
  • v0.12.3
  • v0.12.2
  • v0.12.1
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.1
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v1.0
37 results

login_test.rb

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    login_test.rb 1.74 KiB
    require 'application_system_test_case'
    
    class LoginTest < ApplicationSystemTestCase
      test 'User can register a new account and sign-in to it after confirming their email' do
        email = 'test@test.com'
        username = 'Test User'
        password = 'login_test_1'
    
        # Sign up for an account
        visit root_url
        click_on 'Sign Up'
        fill_in 'Email', with: email
        fill_in 'Username', with: username
        fill_in 'Password', with: password
        fill_in 'Password confirmation', with: password
    
        assert_difference 'User.count' do
          click_on 'Sign up'
        end
    
        user = User.last
    
        # Try logging in directly, this should fail because not confirmed yet
        log_in user, password
        assert_selector '.notice', text: 'You have to confirm your email address before continuing.'
    
        # Confirm email and sign in again, should succeed this time
        confirm_email user
        log_in user, password
        assert_selector '.notice', text: 'Signed in successfully.'
      end
    
      test 'User can sign in and is redirected back to the page they were on' do
        # Start on the users page
        visit users_url
    
        # Click the sign in button (top right)
        # Don't go through log_in helper, since we want to test the sign-in fully here
        click_on 'Sign In'
        fill_in 'Email', with: users(:standard_user).email
        fill_in 'Password', with: 'test123'
        click_button 'Sign in'
    
        # We should see a message that we have signed in, and we should be on the users page again.
        assert_selector '.notice', text: 'Signed in successfully.'
        assert_current_path users_url
      end
    
      test 'User can sign out' do
        log_in :standard_user
        assert_selector '.notice', text: 'Signed in successfully.'
    
        log_out
        assert_selector '.notice', text: 'Signed out successfully.'
      end
    end