Skip to content

Add full Minitest 6 testing suite#1

Merged
rameerez merged 6 commits intomainfrom
cursor/ensure-gem-is-fully-tested-and-robust-29e7
Jan 16, 2026
Merged

Add full Minitest 6 testing suite#1
rameerez merged 6 commits intomainfrom
cursor/ensure-gem-is-fully-tested-and-robust-29e7

Conversation

@rameerez
Copy link
Owner

@rameerez rameerez commented Aug 8, 2025

Adds a comprehensive Minitest suite to ensure gem reliability and cover all functionality and edge cases.


Open in Cursor Open in Web

@cursor
Copy link

cursor bot commented Aug 8, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Co-authored-by: jaracursorsh <jaracursorsh@mitomail.com>
@rameerez rameerez force-pushed the cursor/ensure-gem-is-fully-tested-and-robust-29e7 branch from ed35083 to 3505605 Compare January 16, 2026 19:11
- Increase test coverage from 47.42% to 99.06% line coverage
- Achieve 100% branch coverage (up from 0%)
- Add 226 new tests across all components

Test improvements by component:
- Configuration: 47 tests covering defaults, edge cases, disposable? API
- DisposableDomain model: 40 tests for validations, CRUD, case sensitivity
- DomainListUpdater: 41 tests for HTTP handling, transactions, idempotency
- EmailValidator: 50 tests for validation, error messages, conditions
- Engine/Railtie: 40 tests for setup, version, templates
- Generator: 22 tests for migration, initializer, job generation
- Integration: 16 new tests for full workflows, performance, concurrency

Also:
- Enhanced test_helper with multiple test models and WebMock setup
- Fixed sqlite3 gem version for Rails 8 compatibility
- Raised minimum coverage thresholds to 95% line, 90% branch

Discovered bugs documented in tests:
- Edge case: NoMethodError when email is "@"
- Engine references non-existent assets
- Case sensitivity issues in additional/excluded domains

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rameerez
Copy link
Owner Author

Comprehensive Test Suite Implementation

I've expanded the test suite to be production-ready with world-class coverage.

Coverage Improvement

Metric Before After
Tests 30 256
Assertions 75 483
Line Coverage 47.42% 99.06%
Branch Coverage 0% 100%

Test Categories Added

  • Configuration Tests (47): Defaults, error messages, additional/excluded domains, Nondisposable.disposable? API
  • DisposableDomain Model Tests (40): Validations, CRUD operations, case sensitivity, database constraints
  • DomainListUpdater Tests (41): HTTP success/failure, network errors, transactions, idempotency, rollback
  • EmailValidator Tests (50): Validation logic, blank handling, custom error messages, conditional validation
  • Engine/Railtie Tests (40): Engine setup, version constants, template validation, module structure
  • Generator Tests (22): Migration, initializer, job file generation
  • Integration Tests (16): Full workflows, multi-model validation, performance, concurrency

Edge Cases Now Covered

  • Unicode/IDN domains
  • Very long email addresses and domain names
  • Special characters (hyphens, underscores, numbers)
  • Whitespace handling
  • Multiple @ symbols in email
  • Case sensitivity variations
  • Subdomain handling
  • Plus addressing (user+tag@domain.com)

Bugs Discovered

While writing comprehensive tests, I discovered several bugs in the source code:

  1. lib/nondisposable.rb:22 - NoMethodError when email is just "@" (edge case where split('@').last returns nil)
  2. lib/nondisposable/engine.rb:7-9 - References non-existent assets (nondisposable/application.css and .js)
  3. lib/nondisposable/railtie.rb:5 - Tries to include a class (NondisposableValidator) instead of a module
  4. Case sensitivity inconsistency - additional_domains and excluded_domains comparisons are case-sensitive, but domain lookups are lowercased

I'll fix these bugs in the next commit.

Technical Improvements

  • Enhanced test_helper.rb with multiple test model classes for different scenarios
  • Added WebMock integration for HTTP stubbing
  • Fixed sqlite3 gem version for Rails 8 compatibility
  • Set minimum coverage thresholds (95% line, 90% branch)

Bug fixes:
1. lib/nondisposable.rb: Fix NoMethodError when email is "@"
   - Added nil/empty check for domain after split('@')
   - Now returns false for malformed emails like "@" or "user@"

2. lib/nondisposable/engine.rb: Remove non-existent asset references
   - Removed initializer for nondisposable/application.css and .js
   - These assets don't exist in the gem

3. lib/nondisposable/railtie.rb: Removed buggy file entirely
   - Was trying to `include` a class (NondisposableValidator) instead of a module
   - The validator is already auto-loaded by Rails via naming conventions
   - Engine already handles all necessary Rails integration

Test coverage now at 100% line and 100% branch coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rameerez
Copy link
Owner Author

Bug Fixes Committed

I've fixed all the bugs discovered during test suite development:

1. lib/nondisposable.rb - Edge Case Fix

Problem: NoMethodError: undefined method 'downcase' for nil when email is "@"

Root Cause: "@".split('@').last returns nil/empty in some Ruby versions

Fix: Added nil/empty check for domain after splitting:

def self.disposable?(email)
  return false if email.nil? || !email.include?('@')
  domain = email.to_s.split('@').last
  return false if domain.nil? || domain.empty?  # NEW
  DisposableDomain.disposable?(domain.downcase)
end

2. lib/nondisposable/engine.rb - Remove Non-existent Assets

Problem: Engine referenced nondisposable/application.css and .js that don't exist

Fix: Removed the asset precompile initializer entirely

3. lib/nondisposable/railtie.rb - Removed Buggy File

Problem: Was trying to include a class (NondisposableValidator) instead of a module

Fix: Deleted the file entirely because:

  • The validator is already auto-loaded by Rails through naming conventions
  • The Engine already handles all necessary Rails integration
  • The include statement was fundamentally broken (can't include a class)

Final Results

  • 256 tests, 483 assertions
  • 100% line coverage (up from 47.42%)
  • 100% branch coverage (up from 0%)
  • 0 failures, 0 errors

- Use shared-cache in-memory SQLite (file::memory:?cache=shared)
  instead of plain :memory: to allow threads to share the same database
- Add ensure_database_schema! helper that recreates tables if missing
- Call ensure_database_schema! in NondisposableTestCase#setup

This fixes the "no such table: nondisposable_disposable_domains" errors
that occurred when InstallGeneratorTest ran before other tests (due to
random test ordering). The generator tests could affect ActiveRecord
connection state, and threads in concurrent tests couldn't access the
regular in-memory database.
@rameerez rameerez marked this pull request as ready for review January 16, 2026 20:04
@rameerez rameerez changed the title Ensure gem is fully tested and robust Add full Minitest 6 testing suite Jan 16, 2026
@rameerez rameerez merged commit 62076b9 into main Jan 16, 2026
12 checks passed
@rameerez rameerez deleted the cursor/ensure-gem-is-fully-tested-and-robust-29e7 branch January 16, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants