FactoryGirl: attributes_for not giving me associated attributes

前端 未结 7 657
再見小時候
再見小時候 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:45

    This one doesn't return timestamps etc., only attributes that are accessible for mass assignment:

    (FactoryGirl.build :position).attributes.symbolize_keys.reject { |key, value| !Position.attr_accessible[:default].collect { |attribute| attribute.to_sym }.include?(key) }
    

    Still, it's quite ugly. I think FactoryGirl should provide something like this out of the box.

    I opened a request for this here.

提交回复
热议问题