Skip to content

Conversation

@seuros
Copy link
Member

@seuros seuros commented May 31, 2025

Summary

This PR migrates closure_tree to match the new API patterns from the with_advisory_lock gem, removing global monkey patching and implementing proper multi-database support.

Major Changes

1. Remove Global Monkey Patching

  • Removed global injection into ActiveRecord connections
  • Now uses ActiveSupport.on_load for specific adapters only
  • Advisory lock support is added only to PostgreSQL and MySQL adapters

2. Multi-Database Support

  • Added support for running tests with PostgreSQL, MySQL, and SQLite simultaneously
  • Created database-specific model base classes (ApplicationRecord, MysqlRecord, SqliteRecord)
  • Configured DatabaseCleaner for all three database connections
  • Tests can now run against all databases in parallel

3. Advisory Lock Implementation

  • Changed from connection-level to model-level advisory locks
  • Uses model_class.with_advisory_lock instead of connection.with_advisory_lock
  • SQLite models return false for advisory lock support (as expected)
  • Advisory lock names use CRC32 hashing to fit MySQL's 64-character limit

4. Test Infrastructure Updates

  • Copied Docker Compose configuration from with_advisory_lock
  • Moved test models into dummy app structure
  • Fixed MySQL connection to use 127.0.0.1 instead of localhost (socket vs TCP)
  • Renamed SqliteTag to MemoryTag (SQLite reserves "sqlite_" prefix)
  • Updated test helper with proper DatabaseCleaner configuration

5. Code Quality

  • Added RuboCop to development dependencies
  • Applied RuboCop auto-corrections across the codebase
  • Added frozen string literal comments to all Ruby files

Testing

All tests pass with the new multi-database setup:

  • PostgreSQL tests use advisory locks
  • MySQL tests use advisory locks
  • SQLite tests work without advisory locks (as designed)

Breaking Changes

This removes the global monkey patching behavior. Applications relying on connection.with_advisory_lock will need to update to use model.with_advisory_lock instead.

@seuros seuros requested a review from Copilot May 31, 2025 15:37

This comment was marked as outdated.

@seuros seuros force-pushed the dummy branch 5 times, most recently from 1f818da to 398d9d8 Compare May 31, 2025 16:52
@seuros seuros marked this pull request as draft July 20, 2025 19:44
seuros added 4 commits July 20, 2025 20:48
Major changes: - Remove global monkey patching from ActiveRecord connections - Use model-level with_advisory_lock instead of connection-level - Add multi-database support (PostgreSQL, MySQL, SQLite) - SQLite models don't support advisory locks (returns false) - Add DatabaseCleaner configuration for multi-database tests - Rename SqliteTag to MemoryTag to avoid SQLite reserved prefix - Fix MySQL connection to use 127.0.0.1 instead of localhost - Use CRC32 for advisory lock names to fit MySQL 64-char limit - Add RuboCop and apply auto-corrections
@seuros seuros requested a review from Copilot July 20, 2025 21:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates closure_tree to use a dummy Rails app structure for testing and implements proper multi-database support, removing global monkey patching in favor of the new API patterns from the with_advisory_lock gem. The main changes include creating a standard Rails test environment with database-specific model classes and updating test infrastructure to support concurrent testing across PostgreSQL, MySQL, and SQLite.

Key changes:

  • Migrated from standalone test setup to Rails dummy app structure with proper database configuration
  • Implemented multi-database support with separate base classes for PostgreSQL, MySQL, and SQLite
  • Converted Minitest describe/it syntax to Rails test methods using dynamic method definitions

Reviewed Changes

Copilot reviewed 95 out of 100 changed files in this pull request and generated no comments.

File Description
test/test_helper.rb Complete rewrite to use Rails dummy app and configure multi-database testing
test/support/tag_examples.rb Converted from describe/it to Rails test methods with dynamic definitions
test/dummy/ New Rails dummy application structure with multi-database models and configuration
test/closure_tree/ Updated test files to use new dummy app structure and converted syntax
Comments suppressed due to low confidence (5)

test/support/tag_examples.rb:70

  • The test method name has inconsistent spacing. It should be 'test_should_find_tag_by_valid_path' to match the naming pattern of other test methods.
 define_method 'test_should find tag by valid path' do 

test/support/tag_examples.rb:76

  • The test method name has inconsistent spacing. It should be 'test_adds_children_through_add_child' to match the naming pattern of other test methods.
 define_method 'test_adds children through add_child' do 

test/support/tag_examples.rb:89

  • The test method name has inconsistent spacing. It should be 'test_adds_children_through_collection' to match the naming pattern of other test methods.
 define_method 'test_adds children through collection' do 

test/support/tag_examples.rb:112

  • The test method name contains spaces and special characters. It should be 'test_3_tag_collection_create_hierarchy' to follow standard Ruby method naming conventions.
 define_method 'test_3 tag collection.create hierarchy' do 

test/support/tag_examples.rb:192

  • The test method name contains spaces. It should be 'test_3_tag_explicit_create_hierarchy' to follow standard Ruby method naming conventions.
 define_method 'test_3 tag explicit_create hierarchy' do 
@seuros seuros marked this pull request as ready for review July 20, 2025 21:44
@seuros seuros changed the title test: test inside a dummy app. feat: rewrite with clean api Jul 20, 2025
@seuros seuros merged commit f56f2e1 into master Jul 20, 2025
1 check passed
@seuros seuros deleted the dummy branch July 20, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant