Whatâs the Problem?
Whatâs the big deal if I want to use normal, ordinary ActiveRecord#create in my tests? I use it in my code. What could go wrong?
Since you askedâ¦
Weâll start with a simple test involving two users:
â | it â"can tell which user is older"â âdoâ |
â | eldest = User.create(date_of_birth: â'1971-01-22'â) |
â | youngest = User.create(date_of_birth: â'1973-08-31'â) |
â | expect(User.find_eldest).to eq(eldest) |
â | expect(User.find_youngest).to eq(youngest) |
â | âendâ |
That test is deliberately simple, so as not to distract from the data-creation issue. The only weird thing here is that we are testing a hypothetical finder method, find_eldest, that actually goes into the database, so itâs necessary for the ...
Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.