mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
allow factories to use all ancestors' traits
This commit is contained in:
parent
2bef7b142a
commit
f14a8cf215
2 changed files with 10 additions and 1 deletions
|
@ -87,8 +87,8 @@ module FactoryGirl
|
|||
|
||||
def compile
|
||||
unless @compiled
|
||||
parent.defined_traits.each {|trait| define_trait(trait) }
|
||||
parent.compile
|
||||
parent.defined_traits.each {|trait| define_trait(trait) }
|
||||
@definition.compile
|
||||
@compiled = true
|
||||
end
|
||||
|
|
|
@ -60,6 +60,10 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
name "Judy"
|
||||
end
|
||||
|
||||
factory :female_great_user do
|
||||
great
|
||||
end
|
||||
|
||||
factory :female_admin_judy, :traits => [:admin]
|
||||
end
|
||||
|
||||
|
@ -167,6 +171,11 @@ describe "an instance generated by a factory with multiple traits" do
|
|||
subject { FactoryGirl.create(:user_without_admin_scoping) }
|
||||
it { expect { subject }.to raise_error(ArgumentError, "Trait not registered: admin_trait") }
|
||||
end
|
||||
|
||||
context "child factory using grandparents' trait" do
|
||||
subject { FactoryGirl.create(:female_great_user) }
|
||||
its(:great) { should == "GREAT!!!" }
|
||||
end
|
||||
end
|
||||
|
||||
describe "traits with callbacks" do
|
||||
|
|
Loading…
Reference in a new issue