Skip to content

thoughtbot-upcase-exercises/testing-fundamentals-testing-activerecord

Repository files navigation

Rails Testing Exercises / Testing Fundamentals Testing Activerecord

Hey there! We're thoughtbot, a design and development consultancy that brings your digital product ideas to life. We also love to share what we learn.

This coding exercise comes from Upcase, the online learning platform we run. It's part of the Rails Testing Exercises course and is just one small sample of all the great material available on Upcase, so be sure to visit and check out the rest.

Exercise Intro

Testing an ActiveRecord model is similar to testing a simple Ruby object, but you'll need to go through the public ActiveRecord API to test your functionality. For example, you'll need to run save or valid? to generate error messages from your validations.

In this exercise, you'll write an RSpec model test to verify a simple validation.

Instructions

To start, you'll want to clone and run the setup script for the repo

git clone [email protected]:thoughtbot-upcase-exercises/testing-fundamentals-testing-activerecord.git
cd testing-fundamentals-testing-activerecord
bin/setup
  1. Edit spec/models/person_spec.rb.
  2. Write a spec to ensure that the model is invalid without a first_name.
  3. Make sure your specs are passing by running rake.

Featured Solution

Check out the featured solution branch to see the approach we recommend for this exercise.

Forum Discussion

If you find yourself stuck, be sure to check out the associated Upcase Forum discussion for this exercise to see what other folks have said.

Next Steps

When you've finished the exercise, head on back to the Rails Testing Exercises course to find the next exercise, or explore any of the other great content on Upcase.

License

testing-fundamentals-testing-activerecord is Copyright © 2015-2022 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

Credits

thoughtbot

This exercise is maintained and funded by thoughtbot, inc.

The names and logos for Upcase and thoughtbot are registered trademarks of thoughtbot, inc.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •