mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Sequences without blocks return sequential numbers
This commit is contained in:
parent
a7f7e85187
commit
0946f6d4bb
3 changed files with 54 additions and 2 deletions
|
@ -14,7 +14,7 @@ module FactoryGirl
|
||||||
|
|
||||||
# Returns the next value for this sequence
|
# Returns the next value for this sequence
|
||||||
def next
|
def next
|
||||||
@proc.call(@value)
|
@proc ? @proc.call(@value) : @value
|
||||||
ensure
|
ensure
|
||||||
@value = @value.next
|
@value = @value.next
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,5 +16,17 @@ describe "sequences" do
|
||||||
another_value.should =~ /^somebody\d+@example\.com$/
|
another_value.should =~ /^somebody\d+@example\.com$/
|
||||||
first_value.should_not == another_value
|
first_value.should_not == another_value
|
||||||
end
|
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
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue