Skip to content
This repository
Browse code

allow factories to use all ancestors' traits

  • Loading branch information...
commit f14a8cf2152776c5c6c307d15bde107ed299db83 1 parent 2bef7b1
Barun Singh authored March 04, 2012
2  lib/factory_girl/factory.rb
@@ -87,8 +87,8 @@ def names
87 87
 
88 88
     def compile
89 89
       unless @compiled
90  
-        parent.defined_traits.each {|trait| define_trait(trait) }
91 90
         parent.compile
  91
+        parent.defined_traits.each {|trait| define_trait(trait) }
92 92
         @definition.compile
93 93
         @compiled = true
94 94
       end
9  spec/acceptance/traits_spec.rb
@@ -60,6 +60,10 @@
60 60
             name "Judy"
61 61
           end
62 62
 
  63
+          factory :female_great_user do
  64
+            great
  65
+          end
  66
+
63 67
           factory :female_admin_judy, :traits => [:admin]
64 68
         end
65 69
 
@@ -167,6 +171,11 @@
167 171
     subject     { FactoryGirl.create(:user_without_admin_scoping) }
168 172
     it { expect { subject }.to raise_error(ArgumentError, "Trait not registered: admin_trait") }
169 173
   end
  174
+
  175
+  context "child factory using grandparents' trait" do
  176
+    subject     { FactoryGirl.create(:female_great_user) }
  177
+    its(:great) { should == "GREAT!!!" }
  178
+  end
170 179
 end
171 180
 
172 181
 describe "traits with callbacks" do

0 notes on commit f14a8cf

Please sign in to comment.
Something went wrong with that request. Please try again.