diff --git a/lib/factory_girl/attribute_list.rb b/lib/factory_girl/attribute_list.rb index 901d7326a..cd6469f51 100644 --- a/lib/factory_girl/attribute_list.rb +++ b/lib/factory_girl/attribute_list.rb @@ -5,10 +5,10 @@ class AttributeList attr_reader :callbacks, :declarations def initialize - @attributes = {} + @attributes = {} @declarations = [] - @overridable = false - @callbacks = [] + @callbacks = [] + @overridable = false end def declare_attribute(declaration) @@ -17,10 +17,7 @@ def declare_attribute(declaration) end def define_attribute(attribute) - if !overridable? && attribute_defined?(attribute.name) - raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}" - end - + ensure_attribute_not_defined! attribute add_attribute attribute end @@ -90,6 +87,12 @@ def flattened_attributes end.flatten end + def ensure_attribute_not_defined!(attribute) + if !overridable? && attribute_defined?(attribute.name) + raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}" + end + end + def attribute_defined?(attribute_name) !!find_attribute(attribute_name) end