Last Updated: February 25, 2016
· fs

Check the last inserted record with Cucumber

When testing complex forms interactions it may be useful checking that fields are written correctly into the db.

With ActiveRecord, create a database.yml as usual and map the classes:

require 'active_record'
require 'mysql2'

dbconfig = YAML::load('database.yml'))

class Domain < ActiveRecord::Base

Now you can access data and test if the field registrar has been written in the last insertion:

Then /^the last inserted domain must be valid$/ do
  registrar = Domain.last.registrar
  registrar.should_not eq(nil)