Possible Duplicate:
Factory Girl sequences not incrementing
It appears that FactoryGirl is not performing the sequence on email
correctly, since I'm getting a failure when I try to create a user 6.times
. (Also to note: I have a uniqueness constraint on the email
field.)
FactoryGirl.define do
factory :user do
username 'asddfsa'
sequence(:email) {|n| "asd01#{n}@gmail.com" }
...
end
end
RSpec:
describe User do
describe ".matches" do
before :each do
6.times { FactoryGirl.create(:user, :gender => 'Female', :seeking => 'Men') }
4.times { FactoryGirl.create(:user, :gender => 'Male', :seeking => 'Women') }
...
end
...
Failure:
Failure/Error: 6.times { FactoryGirl.create(:user, :gender => 'Female', :seeking => 'Men') }
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
# ./spec/models/user_spec.rb:6:in `block (4 levels) in <top (required)>'
# ./spec/models/user_spec.rb:6:in `times'
# ./spec/models/user_spec.rb:6:in `block (3 levels) in <top (required)>'