Permalink
Browse files

Dynamic attributes referencing dynamic attributes of child factories …

…work correctly


Fixes #173
  • Loading branch information...
1 parent 2ccbf45 commit 8012d3d81b2557f4256dc40a9de72298a566e946 @joshuaclayton joshuaclayton committed Aug 9, 2011
Showing with 8 additions and 2 deletions.
  1. +5 −1 lib/factory_girl/factory.rb
  2. +3 −1 spec/acceptance/parent_spec.rb
@@ -45,7 +45,11 @@ def inherit_from(parent) #:nodoc:
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
@@ -3,12 +3,13 @@
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 @@
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

0 comments on commit 8012d3d

Please sign in to comment.