...

/

What's The Problem?

What's The Problem?

Learn about testing and validating problems.

We'll cover the following...

What’s the big deal if we want to use normal, ordinary ActiveRecord#create in the tests? We use it in the code. What could go wrong? Let’s see what happens.

You’ll start with a simple test involving two users:

it "can tell which user is older" do
  eldest_user = User.create(date_of_birth: '1971-01-22')
  youngest_user = User.create(date_of_birth: '1973-08-31')
  expect(User.eldest).to eq(eldest_user)
  expect(User.youngest).to eq(youngest_user)
end

That test is deliberately simple so as not to distract from the data-creation issue. The only weird thing here is testing a hypothetical finder method, eldest, that goes into the database, so it’s necessary that the objects we ...