Forum: Ruby on Rails Factory Girl Associations Issue with Uniqueness Validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tyler A. (Guest)
on 2009-03-15 05:41
(Received via mailing list)
Greetings,

Does anybody have a workaround/solution for Factory Girl's insistence on
creating a new record for each association it creates?  As far as I can
tell, this makes using Factory Girl unusable when you have uniqueness
validations on the model referenced by the FK when testing interrelated
has_many/belongs_to associations.

What am I missing here?  Google shows many people with same issue
without a clear resolution.  I may just need some sleep. :-)

Thanks

TMA
mirts (Guest)
on 2009-03-19 22:30
(Received via mailing list)
I have exactly the same problem... but no solution. Would also greatly
appreciate suggestions as to a workaround.
Andrew T. (Guest)
on 2009-03-20 09:25
(Received via mailing list)
On Thu, Mar 19, 2009 at 8:01 PM, mirts <removed_email_address@domain.invalid> 
wrote:
>
> I have exactly the same problem... but no solution. Would also greatly
> appreciate suggestions as to a workaround.
>
> >
>

When I encounter this type of issue, I tend to create the high level
objects and then explicitly include them

@author = Factory(:author)

book1 = Factory(:book, :author => @author)
book2 = Factory(:book, :author => @author)
etc.

Andrew T.
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
This topic is locked and can not be replied to.