Rails Test Application Integration
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The myapp directory contains a functional Rails test application used to validate the integration and behavior of the sidekiq-unique-jobs gem within a real-world framework environment. This application serves as a testing ground for various lock strategies, middleware configurations, and Redis interactions under standard Rails conventions.
The integration focuses on ensuring that Sidekiq client and server middlewares correctly intercept job lifecycle events while interacting with a PostgreSQL database and a Redis backend. It provides a suite of system and unit tests to verify that uniqueness constraints are respected during job enqueuing and execution.
Sources: myapp/README.md, CLAUDE.md:8-10
Middleware and Service Configuration
The integration requires specific configuration within the Sidekiq initializer to enable the uniqueness features. Both client-side and server-side middlewares must be added to the Sidekiq chain to ensure comprehensive job interception.
Sidekiq Configuration Flow
The following diagram illustrates how the middleware is injected into the Sidekiq lifecycle during application startup:
The client middleware intercepts push operations to Redis, while the server middleware manages the lock and unlock phases during execution.
Sources: spec/spec_helper.rb:48-73, README.md:32-52
Testing Infrastructure
The Rails test application utilizes RSpec along with specific system test helpers to simulate browser-based interactions and background job processing.
System Test Support
System tests are configured to use a JavaScript driver (Capybara) and include helpers for managing Turbo frames and asset precompilation. The precompile_assets.rb script ensures that CSS (via Tailwind) is built before the suite runs if system tests are selected.
Sources: myapp/spec/system/support/precompile_assets.rb:3-23, myapp/spec/system/support/better_rails_system_tests.rb:45-55
RSpec Configuration
The test environment is configured to maintain a consistent schema and handle transactional fixtures.
| Feature | Description | File |
|---|---|---|
transactional_fixtures | Set to true to ensure database cleanliness between tests. | myapp/spec/rails_helper.rb |
Sidekiq::Testing | Supports inline! and fake! modes for job behavior validation. | README.md |
SidekiqUniqueJobs::Testing | Provides matchers for verifying lock acquisition in specs. | spec/spec_helper.rb |
Sources: myapp/spec/rails_helper.rb:17-21, spec/spec_helper.rb:133-145
Data Persistence Layer
The application integrates with a PostgreSQL database to store standard Rails entities like User and Post. This allows for testing unique jobs that depend on database record states (e.g., jobs that ensure only one cleanup process runs per user_id).
Database Schema
The User table includes standard Devise-style fields for authentication and locking, which can be used to trigger background jobs requiring uniqueness.
Sources: myapp/db/schema.rb:16-56
Integration Execution Flow
When a job is enqueued within the Rails application, the integration follows a strict sequence to determine if the job should proceed based on existing Redis locks.
Sources: CLAUDE.md:37-45, spec/spec_helper.rb:63-71
Conclusion
The Rails Test Application Integration provides the necessary environment to verify that sidekiq-unique-jobs functions correctly within the Rails ecosystem. By combining standardized database schemas, asset management, and specialized RSpec helpers, the project ensures that uniqueness constraints behave predictably across different Sidekiq versions and Redis configurations.