diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index 66cbf9d6c..82353ce26 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -205,7 +205,7 @@ def run(overrides = {}) apply_callbacks apply_attributes - apply_remaining_attributes + apply_remaining_overrides proxy.result(@to_create) end @@ -221,18 +221,22 @@ def apply_callbacks def apply_attributes @attributes.each do |attribute| if overrides_for_attribute(attribute).any? - handle_overrides(attribute) + handle_attribute_with_overrides(attribute) else handle_attribute_without_overrides(attribute) end end end + def apply_remaining_overrides + @overrides.each { |attr, val| proxy.set(attr, val) } + end + def overrides_for_attribute(attribute) @overrides.select { |attr, val| attribute.aliases_for?(attr) } end - def handle_overrides(attribute) + def handle_attribute_with_overrides(attribute) overrides_for_attribute(attribute).each do |attr, val| if attribute.ignored proxy.set_ignored(attr, val) @@ -248,10 +252,6 @@ def handle_attribute_without_overrides(attribute) attribute.add_to(proxy) end - def apply_remaining_attributes - @overrides.each { |attr, val| proxy.set(attr, val) } - end - def proxy @proxy ||= @proxy_class.new(@build_class) end