2010-06-10 13:37:51 -04:00
|
|
|
require 'spec_helper'
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Sequence do
|
2010-08-12 22:42:18 -04:00
|
|
|
describe "a basic sequence" do
|
2009-04-11 11:27:23 -04:00
|
|
|
before do
|
2011-01-25 17:55:40 -05:00
|
|
|
@name = :test
|
|
|
|
@sequence = FactoryGirl::Sequence.new(@name) {|n| "=#{n}" }
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:56:45 -04:00
|
|
|
it "has a name" do
|
|
|
|
@sequence.name.should == @name
|
|
|
|
end
|
|
|
|
|
2011-01-25 17:55:40 -05:00
|
|
|
it "has names" do
|
|
|
|
@sequence.names.should == [@name]
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should start with a value of 1" do
|
|
|
|
@sequence.next.should == "=1"
|
|
|
|
end
|
|
|
|
|
2011-01-25 17:55:40 -05:00
|
|
|
it "responds to default_strategy" do
|
|
|
|
@sequence.default_strategy.should == :create
|
|
|
|
end
|
|
|
|
|
2009-04-11 11:27:23 -04:00
|
|
|
describe "after being called" do
|
|
|
|
before do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use the next value" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == "=2"
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-01-25 17:55:40 -05:00
|
|
|
|
2010-08-12 22:42:18 -04:00
|
|
|
describe "a custom sequence" do
|
|
|
|
before do
|
2011-01-25 17:55:40 -05:00
|
|
|
@sequence = FactoryGirl::Sequence.new(:name, "A") {|n| "=#{n}" }
|
2010-08-12 22:42:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should start with a value of A" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == "=A"
|
2010-08-12 22:42:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "after being called" do
|
|
|
|
before do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next
|
2010-08-12 22:42:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use the next value" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == "=B"
|
2010-08-12 22:42:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-01-27 16:25:31 -05:00
|
|
|
|
|
|
|
describe "a basic sequence without a block" do
|
|
|
|
before do
|
2011-01-25 17:55:40 -05:00
|
|
|
@sequence = FactoryGirl::Sequence.new(:name)
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
2011-01-25 17:55:40 -05:00
|
|
|
|
2011-01-27 16:25:31 -05:00
|
|
|
it "should start with a value of 1" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == 1
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
2011-01-25 17:55:40 -05:00
|
|
|
|
2011-01-27 16:25:31 -05:00
|
|
|
describe "after being called" do
|
|
|
|
before do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use the next value" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == 2
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "a custom sequence without a block" do
|
|
|
|
before do
|
2011-01-25 17:55:40 -05:00
|
|
|
@sequence = FactoryGirl::Sequence.new(:name, "A")
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should start with a value of A" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == "A"
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "after being called" do
|
|
|
|
before do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use the next value" do
|
2011-05-19 10:56:45 -04:00
|
|
|
@sequence.next.should == "B"
|
2011-01-27 16:25:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|