I modelli sono: Post e Utente (Idea). Sto testando il controller Post.Test del controller con RSpec, Idea, 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
Ma la seconda prova fallisce:
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
Come posso risolvere questo problema?
Quando includo il codice in spec_helper. Ho ricevuto un errore Errore/Errore: impossibile trovare la linea corrispondente da backtrace ActiveRecord :: Istruzione non valida: SQLite3 :: SQLException: impossibile avviare una transazione all'interno di una transazione: iniziare la transazione – Mike
non è necessario un altro gioiello per questo. – coneybeare
Ho trovato che la soluzione di eccezione di SQLite consisteva nel rimuovere il 'clean_with (: truncation)' e cambiare completamente la strategia in 'DatabaseCleaner.strategy =: truncation' – Dan