Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factory Girl: can one reopen factory definitions and complete them?

Hi have this special use case, in which I have to define a factory in one file without a certain parameter, and then insert it in the factory definition later. This is a case where I am importing factory definitions from an external dependency (gem, plugin, whtv) and I need to extend it in my project. Something like:

# external def
FactoryGirl.define do
  factory :user do
    email "[email protected]"
  end
end


# proj def
FactoryGirl.define do
  factory :user do
    password "qwerty"
  end
end

this code doesn't work, cuz factory girl thinks I'm redefining the factory. But what I'd really want would be extending it. Is this possible?

like image 441
ChuckE Avatar asked Oct 11 '12 09:10

ChuckE


1 Answers

Ups... seems I found the answer. Next time, have to check the documentation a bit furtherer... Here's the answer for anyone interested:

# external def
FactoryGirl.define do
 factory :user do
   email "[email protected]"
 end
end


# proj def
FactoryGirl.modify do
  factory :user do
    password "qwerty"
  end
end
like image 63
ChuckE Avatar answered Oct 15 '22 16:10

ChuckE