When to use the create syntax

78 views
Skip to first unread message

IAmNaN

unread,
Apr 30, 2012, 8:06:01 PM4/30/12
to factor...@googlegroups.com
With FactoryGirl::Syntax::Methods included in my tests, this does not work:

FactoryGirl.define do

  factory
:article do
    after_create
{|a| a.comments << create(:comment) }
 
end

  factory
:comment do
 
end
end
...it produces this error: Comment(#nnn) expected, got FactoryGirl::Declaration::Static on the after_create line. However, this does work (notice FactoryGirl.create instead of create)...

FactoryGirl.define do

  factory
:article do
    after_create
{|a| a.comments << FactoryGirl.create(:comment) }
 
end

  factory
:comment do
 
end

end
'create' works in other places, but within a factory. So I am confused about whether I'm using create incorrectly or if this is a bug.

Joe Ferris

unread,
May 1, 2012, 9:40:17 AM5/1/12
to factor...@googlegroups.com
Hey,

Can you make sure you're on the latest version of factory_girl? Support for calling syntax methods in attribute blocks was added in 3.2.0.

Thanks,
-Joe
--
Individuals over processes. Interactions over tools. Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
You received this message because you are subscribed to the "factory_girl" mailing list.
To post to this group, send email to factor...@googlegroups.com
To unsubscribe from this group, send email to
factory_girl...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/factory_girl?hl=en

IAmNaN

unread,
May 2, 2012, 12:25:48 AM5/2/12
to factor...@googlegroups.com
Thanks for the reply. Yes, I'm on the latest gems.

factory_girl (3.2.0)
factory_girl_rails (3.2.0)
rails (3.2.3)
ruby (1.9.3)
rspec (2.9.0) if that matters

Josh Clayton

unread,
May 2, 2012, 12:55:39 AM5/2/12
to factory_girl
Hi,

This isn't currently supported - only dynamic attributes (*not*
callbacks) support calling the syntax methods (build, create,
generate, etc.) without explicitly calling them on FactoryGirl. It
shouldn't be too difficult to add.
> > factory_girl...@googlegroups.com

IAmNaN

unread,
May 2, 2012, 3:36:05 AM5/2/12
to factor...@googlegroups.com
Thank you for that answer, Josh.
> > factory_girl+unsubscribe@googlegroups.com
Reply all
Reply to author
Forward
0 new messages