Tôi có các kiểu: Post and User (Devise). Tôi đang kiểm tra bộ điều khiển Post.Kiểm tra bộ điều khiển với RSpec, Devise, Factory Girl
describe "If user sign_in" do
before(:all){
@user = Factory(:user)
}
it "should get new" do
sign_in @user
get 'new'
response.should be_success
response.should render_template('posts/new')
end
it "should create post" do
sign_in @user
post 'create', :post => Factory(:post)
response.should redirect_to(post_path(:post))
end
end
Nhưng cuộc thử nghiệm thứ hai thất bại:
Failure/Error: post 'create', :post => Factory(:post) ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, Email has already been taken, Username has already been taken
Làm thế nào để sửa lỗi này?
Khi tôi bao gồm mã của bạn trong spec_helper. Tôi gặp lỗi Lỗi/Lỗi: Không thể tìm thấy dòng khớp từ backtrace ActiveRecord :: StatementInvalid: SQLite3 :: SQLException: không thể bắt đầu giao dịch trong một giao dịch: bắt đầu giao dịch – Mike
bạn không cần một gem khác. – coneybeare
Tôi tìm thấy giải pháp ngoại lệ SQLite là xóa 'clean_with (: truncation)' và thay đổi chiến lược hoàn toàn thành 'DatabaseCleaner.strategy =: truncation' – Dan