FactoryGirl似乎没有正确执行email
上的序列,因为当我尝试创建用户6.times
时,我遇到了失败。 (另请注意:我在email
字段上有唯一性约束。)
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/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)>'