再会。我得到这个错误
1) Subscription
Failure/Error: @subscription = FactoryGirl.create(:subscription)
ActiveRecord::RecordInvalid:
Encountered errors: Email already exists, Login already exists
虽然在 FactoryGirl 我指定了这些字段的唯一性^
召唤工厂女孩
@subscription = FactoryGirl.create(:subscription)
build 无法实现,因为
应该 validate_uniqueness_of(:category_id).scoped_to(:user_id)
工厂:
factory :subscription do
association :category, factory: :advt_category
user
end
factory :user do
sequence(:login) { |n| "user__#{n}" }
password "password"
sequence(:email) { |n| "example__#{n}@example.com"}
end
如何解决这个错误?为什么会出现?
更新
我最终销毁了该规范中用户模型的所有记录
before do
User.destroy_all
end