Back to Repositories

Testing Password Reset Controller Integration in maybe-finance/maybe

This test suite validates the password reset functionality in a Ruby on Rails application using Minitest. It covers the complete password reset flow including request initiation, email delivery, and password update verification.

Test Coverage Overview

The test suite provides comprehensive coverage of the password reset workflow:

  • New password reset request handling
  • Email delivery verification
  • Token validation and reset form access
  • Password update completion
Integration points include user authentication, email delivery system, and session management.

Implementation Analysis

The testing approach utilizes ActionDispatch::IntegrationTest for end-to-end validation of the password reset flow. It employs fixtures for user data setup and leverages Rails’ built-in assert_enqueued_emails for email delivery verification.

The implementation follows RESTful conventions with distinct test methods for new, create, edit, and update actions.

Technical Details

  • Testing Framework: Minitest
  • Integration Tools: ActionDispatch
  • Fixtures: User model fixtures
  • Authentication: Token-based verification
  • Email Testing: ActiveJob assertion helpers

Best Practices Demonstrated

The test suite exemplifies several testing best practices including isolated setup using fixtures, explicit assertion checks, and comprehensive workflow coverage. Each action is tested independently with clear success criteria and proper HTTP response validation.

The code organization follows the standard controller test structure with setup and individual test methods for each action.

maybe-finance/maybe

test/controllers/password_resets_controller_test.rb

            
require "test_helper"

class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @user = users(:family_admin)
  end

  test "new" do
    get new_password_reset_path
    assert_response :ok
  end

  test "create" do
    assert_enqueued_emails 1 do
      post password_reset_path, params: { email: @user.email }
      assert_redirected_to new_password_reset_url(step: "pending")
    end
  end

  test "edit" do
    get edit_password_reset_path(token: @user.generate_token_for(:password_reset))
    assert_response :ok
  end

  test "update" do
    patch password_reset_path(token: @user.generate_token_for(:password_reset)),
      params: { user: { password: "password", password_confirmation: "password" } }
    assert_redirected_to new_session_url
  end
end