Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

FactoryBot ActiveRecord::RecordInvalid: Validation failed: Year is required

Course Queries Syllabus Queries

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months ago )

 

When I run my rspec test I receive validation error year is required, but in my factory I set year value. I don't know why I receive this error.

FactoryBot.define do
  factory :syllabus do
    year  { 2019 } 
    cycle_academic { "1" }
    modality { "presencial" }
    syllabus_content { "{}" }
    association :doc_template 
    association :user 
    association :curriculum_course
    association :cycle 
    credits { 4 }
    weekly_hours { 5 }

    trait :syllabus_estrategia do
      course { :estrategia }
    end

    trait :syllabus_ingles1 do
      course { :ingles1 }
    end

    trait :syllabus_ingles2 do
      course { :ingles2 }
    end

    trait :syllabus_matematica do
      course { :matematica }
    end    
  end
end

In my rspec file I invoque this factory with this line

it "order to approver" do 
  syllabus_general =  FactoryBot.create(:syllabus) 
end

usr_profile.png

User

( 4 months ago )

There's nothing wrong with the year value in the factory you've displayed, so my guess would be that one of the associated models you have in this factory also requires a year and the default factory for that other model doesn't provide it.

With factories always be thinking what other things are happening.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif