2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2008-06-01 13:46:50 -04:00
|
|
|
|
2009-04-13 21:39:19 -04:00
|
|
|
# Raised when calling Factory.sequence from a dynamic attribute block
|
|
|
|
class SequenceAbuseError < StandardError; end
|
|
|
|
|
2011-01-26 20:55:06 -05:00
|
|
|
# Sequences are defined using sequence within a FactoryGirl.define block.
|
|
|
|
# Sequence values are generated using next.
|
2008-06-01 13:46:50 -04:00
|
|
|
class Sequence
|
2011-01-25 17:55:40 -05:00
|
|
|
def initialize(name, value = 1, &proc) #:nodoc:
|
|
|
|
@name = name
|
2008-06-01 13:46:50 -04:00
|
|
|
@proc = proc
|
2010-07-06 20:54:55 -04:00
|
|
|
@value = value || 1
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
2008-07-30 15:47:12 -04:00
|
|
|
# Returns the next value for this sequence
|
2011-01-25 17:55:40 -05:00
|
|
|
def run(proxy_class = nil, overrides = {})
|
2011-01-27 16:25:31 -05:00
|
|
|
@proc ? @proc.call(@value) : @value
|
2010-08-12 22:42:18 -04:00
|
|
|
ensure
|
|
|
|
@value = @value.next
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
2011-01-25 17:55:40 -05:00
|
|
|
def next
|
|
|
|
puts "WARNING: FactoryGirl::Sequence#next is deprecated."
|
|
|
|
puts "Use #run instead."
|
|
|
|
run
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_strategy
|
|
|
|
:create
|
|
|
|
end
|
|
|
|
|
|
|
|
def names
|
|
|
|
[@name]
|
|
|
|
end
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
2011-01-25 17:55:40 -05:00
|
|
|
def self.sequences
|
|
|
|
puts "WARNING: FactoryGirl.sequences is deprecated."
|
|
|
|
puts "Use FactoryGirl.registry instead."
|
|
|
|
registry
|
2008-12-11 15:54:33 -05:00
|
|
|
end
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|