Skip to content

Commit

Permalink
Ensure static and dynamic attributes can be "rearranged" in child
Browse files Browse the repository at this point in the history
factories

Closes #186
  • Loading branch information
twalpole authored and joshuaclayton committed Aug 22, 2011
1 parent 4960cb3 commit a50c703
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/factory_girl/attribute_list.rb
Expand Up @@ -38,8 +38,10 @@ def apply_attributes(attributes_to_apply)

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
Expand Down
18 changes: 18 additions & 0 deletions spec/acceptance/parent_spec.rb
Expand Up @@ -19,6 +19,14 @@
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
Expand All @@ -45,5 +53,15 @@
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

0 comments on commit a50c703

Please sign in to comment.