Sequences without blocks return sequential numbers
This commit is contained in:
parent
a7f7e85187
commit
0946f6d4bb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue