On Dec 20, 4:38 pm, daze <dmonopol...@gmail.com> wrote: > > Wait.... what if you wanted to do this? > > t.title {|x| "#{x.section.name}Article#{Factory.next(:count)}" } > > So would this be a scenario in which it's better to have a separate > sequence for "something that is more complex" - so like a sequence > called :article_title?
The tricky part there is that you want both the sequence and the handle to the object that you're creating. I think that means you can't use the shortcut syntax I had (or at least I don't see how), but it also means you can't use a Factory.sequence :foobar do ... end, because that won't know your x object and it doesn't look like you can pass in a context like you can with the other Factory objects. It seems like you have three options which are: 1) Do something like what you're doing, although if you need to share part of it you could make a sequence :article_title for "article_#{n}" and then do t.title {|x| "#{x.section.name}_#{Factory.next(:article_title)}"} 2) You could not put the x.section.name in the title; that'd be my first inclination as it'd seem odd if the name you have is required to be that, since its just for testing purposes. 3) You could patch factory_girl's sequence to take a context like the object factories. Look at https://github.com/thoughtbot/factory_girl/blob/master/lib/factory_girl/sequence.rb; basically you want to override the next method to take options and pass them into the call in there. I'm not sure exactly how the object part does it, but in theory one should be able to look at that and emulate the appropriate stuff. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.