David Kahn wrote in post #968158: > I am still trying to wrap my head around FG...
What's to wrap your head around? All it does is create an object with some associations. If you're finding it confusing, you're most likely overthinking it. > can someone explain me > why I > am seemingly having to reload an object to have access to the correct > association value which I updated since creating the object with FG. > Here is > an example (Factory below also): > > @person = Factory(:person) > @person.addresses.size.should == 0 > address = Factory(:address) > @person.add_address(address) Does add_address save @person ? Personally, I would do @person.addresses << address , which always seems to do the right thing. > @person = Person.find(@person.id) # if I dont do this I get the old > value, > 0, but if I reload I get the right value, 1. > @person.addresses.size.should == 1 > @person.addresses[0].person_id.should == @person.id You do know that, while this test is useful for getting to know Factory Girl, it is of no use for an actual application, right? All it's doing is testing FG and AR functionality that's already well tested. > > > Factory.define :person do |f| > f.first_name {"MyString"} > f.middle_name {"MyString"} > f.last_name {"MyString"} > end > > Factory.define :address do |f| > f.person_id {1} > f.address {"MyString"} > f.zip {"94587"} > f.city {"MyString"} > f.state {"MyString"} > end I don't think you need to use blocks for constant values. However, once you get FG working, I highly recommend using Faker to generate the data. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- Posted via http://www.ruby-forum.com/. -- 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.