Scott's Recipes Logo

Ruby - FactoryBot - When Factories with Dependencies Toss Validation Errors

Pizza courtesy of Pizza for Ukraine!

Donate Now to Pizza for Ukraine

 

Last Updated On: 2025-09-01 04:31:52 -0400

Started

# factory :link do # url {‘https://fan-app-qa.azurewebsites.net/admin/’} # domain {‘fan-app-qa.azurewebsites.net’} # root_domain {‘azurewebsites.net’} #. environment # end

Then

❯ be rails test test/models/link_namer_test.rb Running 1 tests in a single process (parallelization threshold is 50) Run options: –seed 17236

Running:

E

Error: LinkNamerTest#test_a_link_with_a_link_type_of_issue_tracker_and_a_domain_of_github_should_NOT_have_a_name_of_GitHub_source_code_repo_and_tools: ActiveRecord::RecordInvalid: Validation failed: Project can’t be blank, User can’t be blank, User must exist, Project must exist test/models/link_namer_test.rb:9:in `block in '

then clean slate

/Users/sjohnson/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.4/lib/active_record/validations.rb:80:in `raise_validation_error’: Validation failed: Account can’t be blank, Account must exist, Environment must exist (ActiveRecord::RecordInvalid) 3.1.2 :002 > reload!

factory :link do account environment project user url {‘https://fan-app-qa.azurewebsites.net/admin/’} domain { ‘fan-app-qa.azurewebsites.net’ } root_domain { ‘azurewebsites.net’ } link_type { ‘execution_url’ } end

ALL dependencies must be satisfied