mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Ensure static and dynamic attributes can be "rearranged" in child
factories Closes #186
This commit is contained in:
parent
4960cb3844
commit
a50c703b7e
2 changed files with 22 additions and 2 deletions
|
@ -38,8 +38,10 @@ module FactoryGirl
|
|||
|
||||
attributes_to_apply.each do |attribute|
|
||||
if attribute_defined?(attribute.name)
|
||||
@attributes[attribute.priority].delete_if do |attrib|
|
||||
new_attributes << attrib.clone if attrib.name == attribute.name
|
||||
@attributes.each_value do |attributes|
|
||||
attributes.delete_if do |attrib|
|
||||
new_attributes << attrib.clone if attrib.name == attribute.name
|
||||
end
|
||||
end
|
||||
else
|
||||
new_attributes << attribute.clone
|
||||
|
|
|
@ -19,6 +19,14 @@ describe "an instance generated by a factory that inherits from another factory"
|
|||
factory :guest do
|
||||
email { "#{name}-guest@example.com" }
|
||||
end
|
||||
|
||||
factory :no_email do
|
||||
email ""
|
||||
end
|
||||
|
||||
factory :bill do
|
||||
name { "Bill" } #block to make attribute dynamic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -45,5 +53,15 @@ describe "an instance generated by a factory that inherits from another factory"
|
|||
its(:email) { should eql "John-guest@example.com" }
|
||||
its(:login) { should == "John-guest@example.com" }
|
||||
end
|
||||
|
||||
describe "the child class redefining parent's dynamic attribute with static attribute" do
|
||||
subject { FactoryGirl.create(:no_email) }
|
||||
its(:email) { should == "" }
|
||||
end
|
||||
|
||||
describe "the child class redefining parent's static attribute with dynamic attribute" do
|
||||
subject { FactoryGirl.create(:bill) }
|
||||
its(:name) { should == "Bill" }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue