If you’re using Postgresql with Rails 2.2, your testing database user needs to be a “superuser” for your tests to run. This is not a good thing. It’s the equivalent of running as root. But, if you’ve got a completely separate development/testing server it’s better than not being able to test at all.
If your postgres testing user isn’t a superuser, you’ll get errors like:
ActiveRecord::StatementInvalid: PGError: ERROR: permission \ denied: "RI_ConstraintTrigger_17866" is a system trigger
You can create a postgres superuser thusly:
> su - postgres > psql template1 > template1=# create user your username superuser;
Update the testing stanza of your config/database.yml and you should be good to go.
You could otherwise change the configuration of your test environment in database.yml to:
test:
adapter: postgresql
database: myapp_test
username: postgres
Sure. The real problem isn’t getting it to work, it’s that Rails 2.2 testing seems to need a superuser connection – meaning bad SQL could destroy your entire postgres install. Not good.
I was doing alright with tests in Rails 2.2.2 and a non-superuser in my Postgres DB, until I added the migration_helpers plugin and created some foreign key constraints. Thanks for the post; it got me up and running again quickly!