If you use deferred Postgres checks or constraint triggers, you might have a bit of trouble testing them if you use RSpec, at least I did. I've only recently come accross deferred checks and I absolutely love them. They basically allow you to enforce constraints in a transactionally deferred manner. Put simply, if you have a NOT NULL constraint that you have flagged as DEFERRRED, then it won't be checked until a transaction is comitted.
Because of the transactional nature of these types of checks, you may find that your functions don't properly trigger in Rspec because Rspec likes to wrap each test in a transaction.
I needed to add this line to my spec which prevents Rspec from wrapping the test in a transaction, therefore triggering my deferred checks!
self.use_transactional_tests = false