non-overriden parent dynamic methods should be assigned before dynamic child attributes #173

Closed
wants to merge 2 commits into
from

Projects

None yet

2 participants

@twalpole

commit 28f541e changed to appending parent attributes to the end of the @attributes array. This has the effect of causing child dynamic attributes to be evaluated before non-overridden parent dynamic attributes, breaking a bunch of my factories. This commit changes it back to inserting parent attributes at the front of the @attributes array so that non-overridden dynamic parent attributes are evaluated before child dynamic attributes. spec added and all other specs pass

@twalpole

One step further to make sure dynamic parent attributes are evaluated in defined order even when overridden by child attributes

@joshuaclayton
thoughtbot, inc. member

I squashed and cleaned this up, since there was some extra work being done in the factory code itself - all that was necessary was the unshift, based on the tests. I also removed the login addition since it was passing already, without any changes to the factory.rb code.

@twalpole

Actually the second test that was in this fails without the extra changes. Without the other changes the code below would assign attributes in the order a,c,b when creating a :child- with the changes it will assign a,b,c in the order they are defined in the parent

factory :parent do
  a { ...  }
  b { ...  }
  c { ...  }
  factory :child do
    b { ...  }
  end
end
@joshuaclayton
thoughtbot, inc. member

Ah, whoops - I missed the second part; sorry about that. I've just pushed the second part of the commit.

@twalpole

Thanks - that makes it a lot more usable for me

@joshuaclayton
thoughtbot, inc. member

Awesome! Dynamic attributes and processing order have been getting progressively better thanks to developers like you who've found these bugs and put together patches; I (as well as other users of FG I'm sure) am grateful for these sorts of contributions.

@twalpole twalpole pushed a commit to twalpole/factory_girl that referenced this pull request Aug 9, 2011
@joshuaclayton joshuaclayton Dynamic attributes referencing dynamic attributes of child factories …
…work correctly

Fixes #173
8012d3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment