1
可能重複:
Factory Girl sequences not incrementingFactoryGirl序列失敗
看來,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)>'
在這裏看到我的問題:http://stackoverflow.com/questions/11441505/factory-girl-sequences-not-incrementing/ – 2012-08-05 02:15:28