mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
parent
62827420ae
commit
4aecfff126
2 changed files with 25 additions and 1 deletions
|
@ -24,7 +24,8 @@ module FactoryGirl
|
|||
FactoryGirl.register_factory(factory)
|
||||
|
||||
proxy.child_factories.each do |(child_name, child_options, child_block)|
|
||||
factory(child_name, child_options.merge(:parent => name), &child_block)
|
||||
parent_factory = child_options.delete(:parent) || name
|
||||
factory(child_name, child_options.merge(:parent => parent_factory), &child_block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -65,3 +65,26 @@ describe "an instance generated by a factory that inherits from another factory"
|
|||
end
|
||||
end
|
||||
|
||||
describe "nested factories with different parents" do
|
||||
before do
|
||||
define_model("User", :name => :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
name "Basic User"
|
||||
|
||||
factory :male_user do
|
||||
name "John Doe"
|
||||
end
|
||||
|
||||
factory :uppercase_male_user, :parent => :male_user do
|
||||
after_build {|user| user.name = user.name.upcase }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "honors :parent over the factory block nesting" do
|
||||
FactoryGirl.build(:uppercase_male_user).name.should == "JOHN DOE"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue