Writing Tests for Database Constraints
Learn how to write tests for database constraints in our Rails application.
We'll cover the following...
Test cases
Like all tests, tests for the correctness of the data model have a carrying cost. We don’t see a lot of value in testing null: false
or unique: true
because these tend to be easy to get right. Check constraints are more like real code and, thus, easier to mess up. We usually write tests for them. Let’s write a test for the constraint around the widget’s price. We’ll need two tests: ...