Inverse_of doesn't work with rand parameter.

16 views
Skip to first unread message

Pedro Adame Vergara

unread,
May 3, 2017, 11:05:05 AM5/3/17
to fabrication

# spec/fabricators/a.rb

Fabricator(:a) do
 text
{ Faker::Lorem.sentence }
 bs
(count: 4, inverse_of: :a)
end

# spec/fabricators/b.rb

Fabricator(:b) do
 text
{ Faker::Lorem.sentence }
 b
(inverse_of: :a)
end

Given A has_many B, these fabricators works. But if I want a random count of B in A (change the parameter count: 4 to rand: 4), it goes to "No fabricator defined for bs". If I change, bs to b, it goes to "Stack level too deep" error.

How can I do that?

Paul Elliott

unread,
May 4, 2017, 8:37:03 AM5/4/17
to fabrica...@googlegroups.com
It may be because you have `b` instead of `a` as a field in the `b` Fabricator, although it may also just be a typo in this example.

If that's not the issue then I think you've stumbled on a bug. To get through the day I you may need to manually define the expansion in the fabricator like so:

```
Fabricator(:a) do
  bs(rand: 4) { Fabricate.build(:b, a: nil) }
end
```

-- Paul

--
You received this message because you are subscribed to the Google Groups "fabrication" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabricationgem+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pedro Adame Vergara

unread,
May 4, 2017, 8:52:13 AM5/4/17
to fabrication
Yes, it was a typo. Anyway, let me try it just to be sure. I will update.
```

-- Paul

To unsubscribe from this group and stop receiving emails from it, send an email to fabricationge...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages