Sequences without blocks return sequential numbers

This commit is contained in:
Nate Smith 2011-01-27 16:25:31 -05:00
parent a7f7e85187
commit 0946f6d4bb
3 changed files with 54 additions and 2 deletions

View File

@ -14,7 +14,7 @@ module FactoryGirl
# Returns the next value for this sequence
def next
@proc.call(@value)
@proc ? @proc.call(@value) : @value
ensure
@value = @value.next
end

View File

@ -16,5 +16,17 @@ describe "sequences" do
another_value.should =~ /^somebody\d+@example\.com$/
first_value.should_not == another_value
end
end
it "generates sequential numbers if no block is given" do
FactoryGirl.define do
sequence :order
end
first_value = Factory.next(:order)
another_value = Factory.next(:order)
first_value.should == 1
another_value.should == 2
first_value.should_not == another_value
end
end

View File

@ -40,4 +40,44 @@ describe FactoryGirl::Sequence do
end
end
end
describe "a basic sequence without a block" do
before do
@sequence = FactoryGirl::Sequence.new
end
it "should start with a value of 1" do
@sequence.next.should == 1
end
describe "after being called" do
before do
@sequence.next
end
it "should use the next value" do
@sequence.next.should == 2
end
end
end
describe "a custom sequence without a block" do
before do
@sequence = FactoryGirl::Sequence.new("A")
end
it "should start with a value of A" do
@sequence.next.should == "A"
end
describe "after being called" do
before do
@sequence.next
end
it "should use the next value" do
@sequence.next.should == "B"
end
end
end
end