### Install dependencies and run tests without Docker Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/CONTRIBUTE.md Commands to install the bundle for a specific Rails version and run the test suite. Replace '6.1' with any version from the 'gemfiles' directory. ```bash BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle install ``` ```bash BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle exec rake ``` -------------------------------- ### Run tests with Docker Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/CONTRIBUTE.md Commands to start the Docker container, run the tests, and exit, or to open a bash shell inside the container for more control. ```bash docker compose up ``` ```bash docker compose run ruby bash ``` -------------------------------- ### Install database_cleaner-active_record in Gemfile Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/README.md Add the gem to the test group in your Gemfile to use Database Cleaner with ActiveRecord. ```ruby # Gemfile group :test do gem 'database_cleaner-active_record' end ``` -------------------------------- ### Configure ActiveRecord database adapter with #db Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/README.md Shows how to set the database for the ActiveRecord adapter, including using the default, switching back to default, and specifying multiple databases. ```ruby # ActiveRecord connection key DatabaseCleaner[:active_record].db = :logs # Back to default: DatabaseCleaner[:active_record].db = :default # Multiple databases can be specified: DatabaseCleaner[:active_record, db: :default] DatabaseCleaner[:active_record, db: :logs] ``` -------------------------------- ### Configure truncation and deletion strategies with :only and :except Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/README.md Shows how to set the truncation strategy to only affect the 'users' table and the deletion strategy to affect all tables except 'users'. ```ruby # Only truncate the "users" table. DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Truncation.new(only: ["users"]) # Delete all tables except the "users" table. DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Deletion.new(except: ["users"]) ``` -------------------------------- ### Add client_min_messages to database.yml for Postgres Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/README.md Alternative to postgresql.conf: add the client_min_messages parameter to the test environment in database.yml to silence truncate cascade notices. ```yaml test: adapter: postgresql ``` -------------------------------- ### Add upstream remote Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/CONTRIBUTE.md Adds the main repository as an upstream remote to your local clone, allowing you to fetch changes from the original project. ```bash git remote add upstream git@github.com:DatabaseCleaner/database_cleaner-active_record.git ``` -------------------------------- ### Silence Postgres truncate cascade notices in postgresql.conf Source: https://github.com/databasecleaner/database_cleaner-active_record/blob/main/README.md Set client_min_messages to warning in postgresql.conf to suppress 'NOTICE truncate cascades' messages on STDERR when using truncation with foreign key constraints. ```plaintext client_min_messages = warning ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.