1
create_list(:post, 3)
導致唯一性驗證失敗。FactoryGirl belongs_to association的唯一性驗證失敗
我廠擁有郵政和作者之間的關聯belongs_to的:
factory :post do
author
end
factory :author do
sequence(:internal_ref) { |n| n }
end
的Author
模式對internal_ref
唯一性驗證。
UPDATE
後下面的評論暗示清理數據庫,我試圖從一個全新的測試數據庫是這樣開始:
rake db:drop
rake db:create
rake db:schema:load
rake # to create test db and run the tests
,並使用database_cleaner_gem
像這樣spec_helper:
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
我有同樣的問題。我會有興趣聽到其他人想出的內容,但我調整了Rspec.config數據庫清除設置後,我失蹤了。https://github.com/DatabaseCleaner/database_cleaner#how-to-use – steel
試試這篇文章。提出了一個解決方案,並且'爲什麼'在評論中:http://stackoverflow.com/questions/6091039/how-come-factory-girl-isnt-sequencing-unique-attributes – steel
@steel我嘗試使用品牌新的數據庫和使用數據庫清理寶石,但我沒有得到相同的結果 – mehulkar