Back to Repositories

Testing Devise Authentication Model Configurations in heartcombo/devise

This test suite validates Devise authentication configurations and custom model behaviors in Ruby. It covers various authentication scenarios, model validations, and customization options for the Devise authentication framework.

Test Coverage Overview

The test suite provides comprehensive coverage of Devise model configurations and authentication features.

  • Database authentication with configurable settings
  • Custom password validation rules
  • User confirmation workflows
  • Account lockout mechanisms
  • Remember me functionality
  • Timeout configurations

Implementation Analysis

The testing approach focuses on validating different Devise modules and custom model behaviors. It implements various authentication scenarios using class inheritance and module inclusion patterns specific to Ruby and Devise framework features.

  • Custom password hashing implementations
  • Virtual attribute handling
  • Case-insensitive key configurations
  • Multiple devise module combinations

Technical Details

Testing Framework Components:

  • Ruby class inheritance structure
  • Devise authentication modules
  • Custom model validations
  • Password encryption overrides
  • Configurable authentication parameters

Best Practices Demonstrated

The test models demonstrate excellent separation of concerns and modular authentication configuration. Each test case isolates specific Devise functionality while maintaining clear inheritance hierarchies and configuration patterns.

  • Isolated authentication scenarios
  • Clear module configuration
  • Custom validation implementation
  • Flexible authentication options

heartcombo/devise

test/test_models.rb

            
# frozen_string_literal: true

class Configurable < User
  devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
         stretches: 15, pepper: 'abcdef', allow_unconfirmed_access_for: 5.days,
         remember_for: 7.days, timeout_in: 15.minutes, unlock_in: 10.days
end

class WithValidation < Admin
  devise :database_authenticatable, :validatable, password_length: 2..6
end

class UserWithValidation < User
  validates_presence_of :username
end

class UserWithCustomHashing < User
  protected
  def password_digest(password)
    password.reverse
  end
end

class UserWithVirtualAttributes < User
  devise case_insensitive_keys: [:email, :email_confirmation]
  validates :email, presence: true, confirmation: { on: :create }
end

class Several < Admin
  devise :validatable
  devise :lockable
end

class Inheritable < Admin
end