Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
how to force an associated object when seeding data
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
kadoudal  
View profile  
 More options May 8 2012, 12:01 pm
From: kadoudal <kadou...@gmail.com>
Date: Tue, 8 May 2012 09:01:58 -0700 (PDT)
Local: Tues, May 8 2012 12:01 pm
Subject: how to force an associated object when seeding data
I am trying to seed data in my test DB using factory_girls

I have some static data created like :
puts "CREATE AREAS"
west = Area.create(name: "West)
north = Area.create(name: "North)
east = Area.create(name: "East)
south = Area.create(name: "South)
..
and I wrote
FactoryGirl.define do
  factory :partner do
    area
   ......
    phone {....}
    address { ...}

I want to seed partners for these areas, forcing the associated area
( west, north, east , south )
FactoryGirl.create(:partner)   ??
how should I wrote it ?

thanks for feedback


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Bloom  
View profile  
 More options May 9 2012, 12:12 am
From: Chris Bloom <chrisblo...@gmail.com>
Date: Tue, 8 May 2012 21:12:56 -0700 (PDT)
Local: Wed, May 9 2012 12:12 am
Subject: Re: how to force an associated object when seeding data

FactoryGirl.create(:partner, area: west)
FactoryGirl.create(:partner, area: north)
FactoryGirl.create(:partner, area: east)
FactoryGirl.create(:partner, area: south)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kadoudal  
View profile  
 More options May 9 2012, 2:03 am
From: kadoudal <kadou...@gmail.com>
Date: Tue, 8 May 2012 23:03:37 -0700 (PDT)
Local: Wed, May 9 2012 2:03 am
Subject: Re: how to force an associated object when seeding data
Thanks Chris

That's what I tested first, but I get an error :

FactoryGirl.build(:private_partner, area: ouest)

$ rake RAILS_ENV=test db:seed
rake aborted!
Trait not registered: area

as I have in my factories
  factory :partner do
    area
...
    trait :private do
      legal_framework {...}
      ...
    end
...
    trait :company
      legal_framework {...}
      ..
    end
    factory :private_partner,    traits: [:private]
    factory :company_partner,    traits: [:company]
end

I may have to indicate area inside each trait ?

On May 9, 6:12 am, Chris Bloom <chrisblo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kadoudal  
View profile  
 More options May 9 2012, 2:40 am
From: kadoudal <kadou...@gmail.com>
Date: Tue, 8 May 2012 23:40:03 -0700 (PDT)
Local: Wed, May 9 2012 2:40 am
Subject: Re: how to force an associated object when seeding data
after re-tseting , it seems that the association SHOULD be written
inside the factory redefinitions ... is that right  ? ( not specified
in the doc ..)

  factory :partner do
...
    trait :private do
      area
      legal_framework {...}
      ...
    end
...
    trait :company
      area
      legal_framework {...}
      ..
    end
    factory :private_partner,    traits: [:private]
    factory :company_partner,    traits: [:company]
end


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Ferris  
View profile  
 More options May 9 2012, 9:29 am
From: Joe Ferris <jfer...@thoughtbot.com>
Date: Wed, 9 May 2012 09:29:36 -0400
Local: Wed, May 9 2012 9:29 am
Subject: Re: [factory_girl] Re: how to force an associated object when seeding data

Hey,

Do you have an area factory? If you define an attribute without a value, factory_girl expects a factory, sequence, or trait to be defined by that name. Otherwise, it doesn't know how to supply a value for that attribute.

-Joe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kadoudal  
View profile  
 More options May 9 2012, 12:51 pm
From: kadoudal <kadou...@gmail.com>
Date: Wed, 9 May 2012 09:51:35 -0700 (PDT)
Local: Wed, May 9 2012 12:51 pm
Subject: Re: how to force an associated object when seeding data
Thanks a lot ! Got it...

On May 9, 3:29 pm, Joe Ferris <jfer...@thoughtbot.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »