FactoryBot.define do factory :material_release do association :project name "Test Materials" trait :with_address do person_address_street1 "St1" person_address_street2 "St2" person_address_city "City" person_address_state "State" person_address_zip "123" person_address_country "US" end trait :native do person_first_name "Jane" person_last_name "Doe" person_phone "100-555-1001" person_email "owner@email.com" signature do path = Rails.root.join("spec", "fixtures", "files", "signature.png") Rack::Test::UploadedFile.new(path, "image/png") end end trait :minor do minor true guardian_first_name "Guardian1" guardian_last_name "First" guardian_2_first_name "Guardian2" guardian_2_last_name "Second" guardian_phone "1111" guardian_2_phone "2222" end trait :with_photo do photos do path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") [Rack::Test::UploadedFile.new(path, "image/png")] end end trait :with_file do files do path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") [Rack::Test::UploadedFile.new(path, "image/png")] end end trait :non_native do contract do path = Rails.root.join("spec", "fixtures", "files", "contract.pdf") Rack::Test::UploadedFile.new(path, "application/pdf") end end factory :material_release_with_contract_template do after(:build) do |material_release, _| material_release.contract_template = build(:material_release_contract_template) end end factory :material_release_with_contract_template_and_photo do after(:build) do |material_release, _| material_release.contract_template = build(:material_release_contract_template) path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") material_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png") end end factory :material_release_with_photo do after(:build) do |material_release, _| path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") material_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png") end end factory :material_release_with_photos do transient do photos_count { 2 } end after(:build) do |material_release, evaluator| material_release.photos = evaluator.photos_count.times.map do path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") Rack::Test::UploadedFile.new(path, "image/png") end end end end end