FactoryGirl: attributes_for not giving me associated attributes

前端 未结 7 667
再見小時候
再見小時候 2020-12-08 14:08

I have a Code model factory like this:

Factory.define :code do |f|
    f.value \"code\"
    f.association :code_type
    f.association(:codeable, :factory =&         


        
7条回答
  •  难免孤独
    2020-12-08 14:50

    In my APP/spec/controllers/pages_controllers_spec.rb I set:

    let(:valid_attributes) { FactoryGirl.attributes_for(:page).merge(subject: FactoryGirl.create(:theme), user: FactoryGirl.create(:user)) } 
    

    Because I have two models associated. This works too:

     FactoryGirl.define do
        factory :page do
           title      { Faker::Lorem.characters 12 }
           body       { Faker::Lorem.characters 38 }
           discution  false
           published  true
           tags       "linux, education, elearning"
           section   { FactoryGirl.create(:section) }
           user      { FactoryGirl.create(:user)    }                                                                                                                            
         end
      end
    

提交回复
热议问题