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 ?
On Tuesday, May 8, 2012 12:01:58 PM UTC-4, kadoudal wrote:
> 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 { ...}
$ 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:
> On Tuesday, May 8, 2012 12:01:58 PM UTC-4, kadoudal wrote:
> > 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 { ...}
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
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.
On Wednesday, May 9, 2012 at 2:40 AM, kadoudal wrote:
> 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
> -- > 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 factory_girl@googlegroups.com (mailto:factory_girl@googlegroups.com)
> To unsubscribe from this group, send email to
> factory_girl+unsubscribe@googlegroups.com (mailto:factory_girl+unsubscribe@googlegroups.com)
> For more options, visit this group at
> http://groups.google.com/group/factory_girl?hl=en
> 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
> On Wednesday, May 9, 2012 at 2:40 AM, kadoudal wrote:
> > 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
> > --
> > 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 factory_girl@googlegroups.com (mailto:factory_girl@googlegroups.com)
> > To unsubscribe from this group, send email to
> > factory_girl+unsubscribe@googlegroups.com (mailto:factory_girl+unsubscribe@googlegroups.com)
> > For more options, visit this group at
> >http://groups.google.com/group/factory_girl?hl=en