From 854204dd12831a320f3226a875d9175ec68d1544 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 12 Aug 2011 15:07:40 -0700 Subject: [PATCH] Ensure factories prioritize static attributes in all cases --- spec/acceptance/attributes_ordered_spec.rb | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/spec/acceptance/attributes_ordered_spec.rb b/spec/acceptance/attributes_ordered_spec.rb index 23cd03c..676ee7e 100644 --- a/spec/acceptance/attributes_ordered_spec.rb +++ b/spec/acceptance/attributes_ordered_spec.rb @@ -19,14 +19,33 @@ describe "a generated attributes hash where order matters" do static 1 end end + + factory :without_parent, :class => ParentModel do + evaluates_first { static } + evaluates_second { evaluates_first } + evaluates_third { evaluates_second } + static 1 + end end end - subject { FactoryGirl.build(:child_model) } + context "factory with a parent" do + subject { FactoryGirl.build(:child_model) } - it "assigns attributes in the order they're defined with preference to static attributes" do - subject[:evaluates_first].should == 1 - subject[:evaluates_second].should == 1 - subject[:evaluates_third].should == 1 + it "assigns attributes in the order they're defined with preference to static attributes" do + subject[:evaluates_first].should == 1 + subject[:evaluates_second].should == 1 + subject[:evaluates_third].should == 1 + end + end + + context "factory without a parent" do + subject { FactoryGirl.build(:without_parent) } + + it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do + subject[:evaluates_first].should == 1 + subject[:evaluates_second].should == 1 + subject[:evaluates_third].should == 1 + end end end