From 6cddb37ecbfcedea275d690c51f42ff2d76bb715 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Wed, 8 Feb 2012 08:14:34 -0500 Subject: [PATCH] Move factory associations logic to evaluator_class evaluator_class contains the fully-inherited list of attributes; this includes parent classes, traits, etc. When calculating associations for an individual factory, the factory should use inheritance to build the list instead of merely accessing association attributes on itself. Closes #293 --- lib/factory_girl/factory.rb | 2 +- lib/factory_girl/null_factory.rb | 1 - spec/factory_girl/null_factory_spec.rb | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index d795a253f..42b476e00 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -53,7 +53,7 @@ def human_names end def associations - parent.associations + attributes.associations + evaluator_class.attribute_list.associations end # Names for this factory, including aliases. diff --git a/lib/factory_girl/null_factory.rb b/lib/factory_girl/null_factory.rb index cdaf9d577..5e812461c 100644 --- a/lib/factory_girl/null_factory.rb +++ b/lib/factory_girl/null_factory.rb @@ -7,7 +7,6 @@ def initialize end delegate :defined_traits, :callbacks, :attributes, :constructor, :to => :definition - delegate :associations, :to => :attributes def compile; end def class_name; end diff --git a/spec/factory_girl/null_factory_spec.rb b/spec/factory_girl/null_factory_spec.rb index 1362f7b78..f86ed6128 100644 --- a/spec/factory_girl/null_factory_spec.rb +++ b/spec/factory_girl/null_factory_spec.rb @@ -5,12 +5,10 @@ it { should delegate(:callbacks).to(:definition) } it { should delegate(:attributes).to(:definition) } it { should delegate(:constructor).to(:definition) } - it { should delegate(:associations).to(:attributes) } its(:compile) { should be_nil } its(:class_name) { should be_nil } its(:default_strategy) { should == :create } its(:attributes) { should be_an_instance_of(FactoryGirl::AttributeList) } - its(:associations) { should be_empty } its(:evaluator_class) { should == FactoryGirl::Evaluator } end