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.
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.
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.
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? 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With