2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2008-07-30 13:46:06 -04:00
|
|
|
|
2009-02-17 16:38:15 -05:00
|
|
|
# Raised when defining an invalid attribute:
|
|
|
|
# * Defining an attribute which has a name ending in "="
|
|
|
|
# * Defining an attribute with both a static and lazy value
|
|
|
|
# * Defining an attribute twice in the same factory
|
2008-07-30 13:59:58 -04:00
|
|
|
class AttributeDefinitionError < RuntimeError
|
|
|
|
end
|
2010-06-07 15:51:18 -04:00
|
|
|
|
2008-07-30 13:46:06 -04:00
|
|
|
class Attribute #:nodoc:
|
2011-07-19 10:49:00 -04:00
|
|
|
include Comparable
|
2008-07-30 13:46:06 -04:00
|
|
|
|
|
|
|
attr_reader :name
|
|
|
|
|
2009-01-02 17:33:00 -05:00
|
|
|
def initialize(name)
|
|
|
|
@name = name.to_sym
|
2008-07-30 13:59:58 -04:00
|
|
|
|
2009-01-02 17:33:00 -05:00
|
|
|
if @name.to_s =~ /=$/
|
2009-04-17 04:58:35 -04:00
|
|
|
attribute_name = $`
|
2010-06-07 15:51:18 -04:00
|
|
|
raise AttributeDefinitionError,
|
2009-04-17 04:58:35 -04:00
|
|
|
"factory_girl uses 'f.#{attribute_name} value' syntax " +
|
|
|
|
"rather than 'f.#{attribute_name} = value'"
|
2008-07-30 13:59:58 -04:00
|
|
|
end
|
2008-07-30 13:46:06 -04:00
|
|
|
end
|
|
|
|
|
2009-01-02 17:33:00 -05:00
|
|
|
def add_to(proxy)
|
2008-07-30 13:46:06 -04:00
|
|
|
end
|
2011-05-19 10:56:45 -04:00
|
|
|
|
|
|
|
def association?
|
|
|
|
false
|
|
|
|
end
|
2011-07-19 10:49:00 -04:00
|
|
|
|
|
|
|
def priority
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
2011-08-08 10:03:13 -04:00
|
|
|
def aliases_for?(attr)
|
|
|
|
FactoryGirl.aliases_for(attr).include?(name)
|
|
|
|
end
|
|
|
|
|
2011-07-19 10:49:00 -04:00
|
|
|
def <=>(another)
|
|
|
|
return nil unless another.is_a? Attribute
|
|
|
|
self.priority <=> another.priority
|
|
|
|
end
|
|
|
|
|
2008-07-30 13:46:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|