1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_girl/attribute.rb

49 lines
984 B
Ruby
Raw Normal View History

module FactoryGirl
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
class AttributeDefinitionError < RuntimeError
end
2010-06-07 15:51:18 -04:00
class Attribute #:nodoc:
include Comparable
attr_reader :name
def initialize(name)
@name = name.to_sym
if @name.to_s =~ /=$/
attribute_name = $`
2010-06-07 15:51:18 -04:00
raise AttributeDefinitionError,
"factory_girl uses 'f.#{attribute_name} value' syntax " +
"rather than 'f.#{attribute_name} = value'"
end
end
def add_to(proxy)
end
def association?
false
end
def priority
1
end
def aliases_for?(attr)
FactoryGirl.aliases_for(attr).include?(name)
end
def <=>(another)
return nil unless another.is_a? Attribute
self.priority <=> another.priority
end
end
end