Nonos
Nonos

Reputation: 2518

Rails test with triggers

I noticed that Rails creates triggers in the development db but not the test db since it creates the test db from schema.rb instead of running migrations. I have a trigger (as a migration) and need to test that it does the right thing, how can I do that? I tried adding the trigger manually to the test db but that didn't work.

Upvotes: 5

Views: 1713

Answers (2)

Alexander Presber
Alexander Presber

Reputation: 6635

If you do prefer Ruby dumps to SQL dumps you might give this gem a try:

https://github.com/jovoto-team/trackless_triggers

It supports dumping triggers and functions for mysql.

Upvotes: 0

Frederick Cheung
Frederick Cheung

Reputation: 84162

By default rails sets up the test database using the database independant schema.rb, which doesn't understand stuff like triggers.

If you change config.active_record_schema_format to :sql then rails will instead dump the raw SQL that represents the development database's structure and use that to recreate the test database. This dump is placed in development.sql, which is then used instead of schema.rb

This dump is done using the command line tools that your db provides and so will respect features like triggers that active record isn't aware of

Upvotes: 5

Related Questions