Permalink
Browse files

Don't set overridden attributes multiple times

  • Loading branch information...
1 parent 58ec702 commit 0ddc78bd4ee9d744027cb293e018fdf33623e0c3 @joshuaclayton joshuaclayton committed Aug 20, 2011
Showing with 8 additions and 3 deletions.
  1. +1 −1 lib/factory_girl/factory.rb
  2. +7 −2 spec/factory_girl/factory_spec.rb
@@ -86,7 +86,7 @@ def run(proxy_class, overrides) #:nodoc:
if factory_overrides.empty?
attribute.add_to(proxy)
else
- factory_overrides.each { |attr, val| proxy.set(attr, val) }
+ factory_overrides.each { |attr, val| proxy.set(attr, val); overrides.delete(attr) }
end
end
overrides.each { |attr, val| proxy.set(attr, val) }
@@ -309,11 +309,11 @@
describe FactoryGirl::Factory, "running a factory" do
subject { FactoryGirl::Factory.new(:user) }
- let(:attribute) { stub("attribute", :name => :name, :add_to => nil) }
+ let(:attribute) { stub("attribute", :name => :name, :add_to => nil, :aliases_for? => true) }
let(:proxy) { stub("proxy", :result => "result", :set => nil) }
before do
- define_class("User")
+ define_model("User", :name => :string)
FactoryGirl::Attribute::Static.stubs(:new => attribute)
FactoryGirl::Proxy::Build.stubs(:new => proxy)
FactoryGirl::AttributeList.stubs(:new => [attribute])
@@ -333,4 +333,9 @@
subject.run(FactoryGirl::Proxy::Build, {}).should == "result"
proxy.should have_received(:result).with(nil)
end
+
+ it "sets overrides once on the factory" do
+ subject.run(FactoryGirl::Proxy::Build, { :name => "John Doe" })
+ proxy.should have_received(:set).once
+ end
end

0 comments on commit 0ddc78b

Please sign in to comment.