how to assign values to an array in a block with Fabricate gem

231 Views Asked by At

I have the following and the hosts (second to last) line isn't working. Is this possible? How would I assign to it for the save?

venues = Venue.all
users = User.all
Fabricate.times(16, :event ) do
  venue { venues.sample }
  created_by { users.sample }
  sales_rep { users.sample }
  casting_rep { users.sample }
  hosts << { users.sample(2) }
end
1

There are 1 best solutions below

1
SteveTurczyn On BEST ANSWER

Unless hosts is already an array with default value of [] the << won't work.

Better might be...

hosts { [users.sample, users.sample] }