Ruby on Rails Testing with MySQL
I'm trying to test with Ruby on Rails with a MySQL database. When attempting to run the test each test fails with the same reason:
ActiveRecord::StatementInvalid: Mysql::Error: Table 'db_test.session_cleaners' doesn't exist: DELETE FROM `session_cleaners`
I created a session_cleaners table with a primary key and am now getting this error:
ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '0' for key 'PRIMARY': INSERT INTO `session_cleaners` () VALUES ()
I doubt I need the session_cleaners开发者_运维问答
table but I'm not sure what else to do. Any help would be appreciated.
Thanks
You should run the migrations and prepare the test database:
bundle exec rake db:migrate
bundle exec rake db:test:prepare
This will take care of everything provided you have valid migrations.
You'd better read the guides - there's plenty of information that people don't even realise.
There were two things that I did to fix this:
- Update the MySQL gem so that I was using 2.7. I'm on Ruby 1.8.6/Rails 2.3.10 so this gem was required
- Create a session_cleaner table with one field: id. The id is not a primary key and does allow null.
These two things made it so I could prepare the test environment
精彩评论