In this sixth part of a multi-part series on the scaffolding feature of Ruby on Rails, we'll clone the database of our book inventory management system and begin performing tests on it to verify that it works as expected. This article is excerpted from chapter three of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Cloning the Database
There’s one important step left to do before we start writing unit tests: we need to clone the development database to the test environment. Your unit tests will use the test database, emporium_test, but it hasn’t been updated to the latest version. The easiest way of cloning the database structure from the development to the test database is by executing the following command:
rake db:test:clone_structure
Note An alternative way of updating the test database is to recreate the database from scratch using migrations, by executing therakecommand without specifying any parameters. This first runs all the migrations, and then executes the tests in the test directory.
This is a built-in task that copies the database schema from theemporium_developmentto theemporium_testdatabase. If you skip this step, you’ll get the following error when running the unit test: