mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Dynamic attributes referencing dynamic attributes of child factories work correctly
Fixes #173
This commit is contained in:
parent
2ccbf4561b
commit
8012d3d81b
2 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue