rod mclaughlin


FactoryGirl and has_and_belongs_to_many (20 feb 13)

 

If you have a table roles_users, and

user has_and_belongs_to_many :roles

and

role has_and_belongs_to_many :users

you cannot say

  factory :administrator, :parent => :user do
    ...
    roles { [ create( :admin ) ] }
  end

but you can do this

  factory :admin, :parent => :role do
    ...
    users { [ create( :administrator ) ] }
  end

providing you have defined user, administrator and role.


Another thing - in factories.rb it's no good doing this

retrieval_date   '01/17/2011' 

you have to do this

retrieval_date   Date.new(2011, 1, 17) 

 



Back
Portland London