Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 493
Nonos Avatar asked Apr 05 '12 17:04

Nonos


People also ask

How do I run a test in rails?

2.7 The Rails Test Runner Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.

How do I test a controller in Ruby on rails?

The currently accepted way to test rails controllers is by sending http requests to your application and writing assertions about the response. Rails has ActionDispatch::IntegrationTest which provides integration tests for Minitest which is the Ruby standard library testing framework.

What are integration tests rails?

While unit tests make sure that individual parts of your application work, integration tests are used to test that different parts of your application work together.

What is Minitest in Ruby on rails?

What is Minitest? Minitest is a testing suite for Ruby. It provides a complete suite of testing facilities supporting test-driven development (TDD), behavior-driven development (BDD), mocking, and benchmarking. It's small, fast, and it aims to make tests clean and readable.


1 Answers

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

like image 192
Frederick Cheung Avatar answered Sep 25 '22 04:09

Frederick Cheung