.vbw-planning/milestones/07-rails-audit-and-refactoring/06-test-infrastructure/01-PLAN.md
Each helper follows the create_source! pattern: set defaults, merge overrides, save! (with validate: false where appropriate for test speed). Use SecureRandom.hex for uniqueness in guid/url fields.
</action>
<verify>
ruby -c test/support/model_factories.rb (syntax check passes)
</verify>
<done>
test/support/model_factories.rb exists with all 6 factory methods defined in a module
</done>
</task>
<task type="auto">
<name>Wire factories into test_helper</name>
<files>
test/test_helper.rb
</files>
<action>
Add require_relative "support/model_factories" near top of test/test_helper.rb (after existing requires).
Add include ModelFactories inside the ActiveSupport::TestCase class reopening (alongside existing create_source!).
Move create_source! INTO the ModelFactories module as well (keep backward compat -- it will still be available via include). Update test_helper.rb to no longer define create_source! directly -- the module now provides it.
</action>
<verify>
PARALLEL_WORKERS=1 bin/rails test test/models/source_monitor/source_test.rb -- passes (create_source! still works)
</verify>
<done>
test_helper.rb requires and includes ModelFactories module; create_source! is defined in the module
</done>
</task>
<task type="auto">
<name>Migrate test files to shared factories</name>
<files>
test/lib/source_monitor/items/retention_pruner_test.rb
test/lib/source_monitor/scraping/enqueuer_test.rb
test/lib/source_monitor/scraping/state_test.rb
test/lib/source_monitor/scraping/scheduler_test.rb
test/lib/source_monitor/scraping/bulk_source_scraper_test.rb
test/lib/source_monitor/realtime/broadcaster_test.rb
test/lib/source_monitor/fetching/feed_fetcher/entry_processor_test.rb
test/lib/source_monitor/health/source_health_monitor_test.rb
test/lib/source_monitor/items/item_creator_test.rb
test/lib/source_monitor/events/event_system_test.rb
test/lib/source_monitor/scraping/item_scraper/adapter_resolver_test.rb
test/jobs/source_monitor/download_content_images_job_test.rb
test/jobs/source_monitor/scrape_item_job_test.rb
test/jobs/source_monitor/log_cleanup_job_test.rb
test/jobs/source_monitor/item_cleanup_job_test.rb
test/controllers/source_monitor/source_scrape_tests_controller_test.rb
</files>
<action>
For each test file that defines its own create_item, build_source, create_fetch_log, create_scrape_log, or create_health_check_log:
Note: Some test files may have unique factory variants (e.g., create_item with extra fields). Preserve those as local helpers only if they add genuinely unique test-specific logic. Otherwise migrate to the shared version with overrides. </action> <verify> bin/rails test -- full suite passes with zero failures </verify> <done> No test file outside test/support/ defines create_item, build_source, create_fetch_log, create_scrape_log, or create_health_check_log. grep -r "def create_item\b|def build_source\b|def create_fetch_log\b|def create_scrape_log\b|def create_health_check" test/ returns only test/support/model_factories.rb </done> </task> <task type="auto"> <name>Verify and document</name> <files> test/support/model_factories.rb </files> <action>