O'Reilly logo

Rails, Angular, Postgres, and Bootstrap by David B. Copeland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Database Constraints

When treating your SQL database as a “dumb store” (or when using an RDBMS that lacks the sophisticated features of Postgres), you’d typically use various features of Active Record to ensure database integrity and you’d naturally want to test that code. Although we’re using constraints to enforce database integrity (like the check constraint from Exposing the Vulnerability Devise and Rails Leave Open), we’d still like to have test coverage that the constraint is doing what we want.

We can easily test this constraint in RSpec, but it requires a somewhat cumbersome assertion mechanism using exceptions. First, we’ll see how this works, and then we’ll create an RSpec matcher to abstract the awkward syntax away so ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required