Skip to content

Commit

Permalink
Sequences without blocks return sequential numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nwjsmith committed Jan 27, 2011
1 parent a7f7e85 commit 0946f6d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/factory_girl/sequence.rb
Expand Up @@ -14,7 +14,7 @@ def initialize(value = 1, &proc) #:nodoc:

# Returns the next value for this sequence
def next
@proc.call(@value)
@proc ? @proc.call(@value) : @value
ensure
@value = @value.next
end
Expand Down
14 changes: 13 additions & 1 deletion spec/acceptance/sequence_spec.rb
Expand Up @@ -16,5 +16,17 @@
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 changes: 40 additions & 0 deletions spec/factory_girl/sequence_spec.rb
Expand Up @@ -40,4 +40,44 @@
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

0 comments on commit 0946f6d

Please sign in to comment.