Skip to content
This repository
Browse code

Don't set overridden attributes multiple times

  • Loading branch information...
commit 0ddc78bd4ee9d744027cb293e018fdf33623e0c3 1 parent 58ec702
Joshua Clayton authored August 20, 2011
2  lib/factory_girl/factory.rb
@@ -86,7 +86,7 @@ def run(proxy_class, overrides) #:nodoc:
86 86
         if factory_overrides.empty?
87 87
           attribute.add_to(proxy)
88 88
         else
89  
-          factory_overrides.each { |attr, val| proxy.set(attr, val) }
  89
+          factory_overrides.each { |attr, val| proxy.set(attr, val); overrides.delete(attr) }
90 90
         end
91 91
       end
92 92
       overrides.each { |attr, val| proxy.set(attr, val) }
9  spec/factory_girl/factory_spec.rb
@@ -309,11 +309,11 @@
309 309
 
310 310
 describe FactoryGirl::Factory, "running a factory" do
311 311
   subject             { FactoryGirl::Factory.new(:user) }
312  
-  let(:attribute)     { stub("attribute", :name => :name, :add_to => nil) }
  312
+  let(:attribute)     { stub("attribute", :name => :name, :add_to => nil, :aliases_for? => true) }
313 313
   let(:proxy)         { stub("proxy", :result => "result", :set => nil) }
314 314
 
315 315
   before do
316  
-    define_class("User")
  316
+    define_model("User", :name => :string)
317 317
     FactoryGirl::Attribute::Static.stubs(:new => attribute)
318 318
     FactoryGirl::Proxy::Build.stubs(:new => proxy)
319 319
     FactoryGirl::AttributeList.stubs(:new => [attribute])
@@ -333,4 +333,9 @@
333 333
     subject.run(FactoryGirl::Proxy::Build, {}).should == "result"
334 334
     proxy.should have_received(:result).with(nil)
335 335
   end
  336
+
  337
+  it "sets overrides once on the factory" do
  338
+    subject.run(FactoryGirl::Proxy::Build, { :name => "John Doe" })
  339
+    proxy.should have_received(:set).once
  340
+  end
336 341
 end

0 notes on commit 0ddc78b

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