Skip to content
This repository
Browse code

Minor code cleanup

  • Loading branch information...
commit 852eea84fff19867ce16eadad464aed2f60b16be 1 parent 34c1bf9
Joshua Clayton authored
2  lib/factory_girl/factory.rb
@@ -53,7 +53,7 @@ def human_names
53 53
     end
54 54
 
55 55
     def associations
56  
-      attributes.associations + parent.associations
  56
+      parent.associations + attributes.associations
57 57
     end
58 58
 
59 59
     # Names for this factory, including aliases.
2  lib/factory_girl/null_factory.rb
@@ -7,11 +7,11 @@ def initialize
7 7
     end
8 8
 
9 9
     delegate :defined_traits, :callbacks, :attributes, :constructor, :to => :definition
  10
+    delegate :associations, :to => :attributes
10 11
 
11 12
     def compile; end
12 13
     def class_name; end
13 14
     def default_strategy; :create; end
14 15
     def evaluator_class; FactoryGirl::Evaluator; end
15  
-    def associations; attributes.map(&:association?); end
16 16
   end
17 17
 end
11  spec/factory_girl/factory_spec.rb
@@ -49,12 +49,17 @@
49 49
   end
50 50
 
51 51
   it "includes associations from the parent factory" do
  52
+    association_on_parent = FactoryGirl::Declaration::Association.new(:association_on_parent, {})
  53
+    association_on_child  = FactoryGirl::Declaration::Association.new(:association_on_child, {})
  54
+
52 55
     factory = FactoryGirl::Factory.new(:post)
53  
-    factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
  56
+    factory.declare_attribute(association_on_parent)
54 57
     FactoryGirl.register_factory(factory)
  58
+
55 59
     child_factory = FactoryGirl::Factory.new(:child_post, :parent => :post)
56  
-    child_factory.declare_attribute(FactoryGirl::Declaration::Association.new(:editor, {}))
57  
-    child_factory.associations.size.should == 2
  60
+    child_factory.declare_attribute(association_on_child)
  61
+
  62
+    child_factory.associations.map(&:name).should == [:association_on_parent, :association_on_child]
58 63
   end
59 64
 
60 65
   describe "when overriding generated attributes with a hash" do
1  spec/factory_girl/null_factory_spec.rb
@@ -5,6 +5,7 @@
5 5
   it { should delegate(:callbacks).to(:definition) }
6 6
   it { should delegate(:attributes).to(:definition) }
7 7
   it { should delegate(:constructor).to(:definition) }
  8
+  it { should delegate(:associations).to(:attributes) }
8 9
 
9 10
   its(:compile)          { should be_nil }
10 11
   its(:class_name)       { should be_nil }

0 notes on commit 852eea8

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