Fix vintage syntax and add spec for creating child factories with vintage syntax

This commit is contained in:
Joshua Clayton 2011-09-23 15:49:32 -04:00
parent 450dbb2c5c
commit f8638b3085
2 changed files with 19 additions and 1 deletions

View File

@ -29,7 +29,7 @@ module FactoryGirl
proxy = FactoryGirl::DefinitionProxy.new(factory)
yield(proxy)
if parent = options.delete(:parent)
factory.inherit_from(FactoryGirl.factory_by_name(parent))
factory.inherit_factory(FactoryGirl.factory_by_name(parent))
end
FactoryGirl.register_factory(factory)
end

View File

@ -214,3 +214,21 @@ describe "an attribute generated by an in-line sequence" do
end
end
describe "a factory with a parent" do
before do
define_model("User", :username => :string)
Factory.define(:user) do |factory|
factory.username "awesome_username"
end
Factory.define(:boring_user, :parent => :user) do |factory|
factory.username "boring_username"
end
end
it "supports defining parents" do
Factory.build(:boring_user).username.should == "boring_username"
end
end