I have a User model that belongs to a group. The group must have a unique name attribute. The factory user and factory group are defined as:
Factory.define :user do |f| f.association :group, :factory => :group
When you create the first user, a new group is also created. When I try to create a second user, it fails because he wants to create the same group again.
Can I specify a factory_girl association method to search for the first existing record?
Note. I tried to define a method for handling this, but then I cannot use f.association. I would like to be able to use it in Cucumber scripts as follows:
Given the following user exists: | Email | Group | | test@email.com | Name: mygroup |
and this can only work if the association is used in the factory definition.
ruby ruby-on-rails-3 cucumber factory-bot
Slobodan Kovacevic Aug 22 '11 at 9:10 2011-08-22 09:10
source share