Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FactoryGirl attributes_for with associations

There is the following factory:

factory :car do
    name 'Some car'
    engine_value 1.6
    color '#ff0000'
    car_type
    engine_type
    transmission
    drive_type
    material
end

As you see there are a lot of associated objects. But code

attributes_for(:car)

generates only :name=>"Some car", :engine_value=>1.6, :color=>"#ff0000"} hash. I need to get a hash with all attributes. How can I do it? Thanks.

like image 904
malcoauri Avatar asked Mar 04 '14 11:03

malcoauri


1 Answers

I've run into this same issue and I've used something like

build(:car).attributes

Not sure if this is the best way to do it but it worked for me

Hope this helps

like image 151
strivedi183 Avatar answered Oct 16 '22 00:10

strivedi183