Ruby on Rails ActiveRecord Manually Testing Your Models


Testing your Active Record models through your command line interface is simple. Navigate to the app directory in your terminal and type in rails console to start the Rails console. From here, you can run active record methods on your database.

For example, if you had a database schema with a Users table having a name:string column and email:string, you could run:

User.create name: "John", email: ""

Then, to show that record, you could run:

User.find_by email: ""

Or if this is your first or only record, you could simply get the first record by running: