diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index 8fda985..14307a8 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -45,7 +45,11 @@ module FactoryGirl new_attributes = [] parent.attributes.each do |attribute| - unless attribute_defined?(attribute.name) + if attribute_defined?(attribute.name) + @attributes.delete_if do |attrib| + new_attributes << attrib.clone if attrib.name == attribute.name + end + else new_attributes << attribute.clone end end diff --git a/spec/acceptance/parent_spec.rb b/spec/acceptance/parent_spec.rb index a803c9a..5706e4f 100644 --- a/spec/acceptance/parent_spec.rb +++ b/spec/acceptance/parent_spec.rb @@ -3,12 +3,13 @@ require 'acceptance/acceptance_helper' describe "an instance generated by a factory that inherits from another factory" do before do - define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string) + define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string) FactoryGirl.define do factory :user do name "John" email { "#{name.downcase}@example.com" } + login { email } factory :admin do name "admin" @@ -43,6 +44,7 @@ describe "an instance generated by a factory that inherits from another factory" it { should_not be_admin } its(:name) { should == "John" } its(:email) { should eql "John-guest@example.com" } + its(:login) { should == "John-guest@example.com" } end end