Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Provide a 'Changelog' link on Rubygems: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/114
* Fix bundling and CONTRIBUTE.md instructions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/123
* Fix order of arguments in `truncate_tables` expectation https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/124
* Add Docker to make it easier to run tests locally for maintainers and contributors https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/109

## v2.2.1 2025-05-13

Expand Down
19 changes: 16 additions & 3 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ upstream:

The gem uses Appraisal to configure different Gemfiles to test different Rails versions.

- You can run all the databases through docker if needed with `docker compose up` (you can also have them running on your system, just comment out the ones you don't need from the `docker-compose.yml` file)
- Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it
### Run tests without Docker (or using Docker only for the databases)

- You can run all the databases through docker if needed with `docker compose -f docker-compose.db.yml up` (you can also have them running on your system, just comment out the ones you don't need from the `docker-compose.db.yml` file)
- Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it as needed
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle install` (change `6.1` with any version from the `gemfiles` directory)
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle exec rake`

Note that if you don't have all the supported databases installed and running,
some tests will fail.

> Note that you can check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work

### Run tests with Docker

- Open `docker-compose.yml` and configure the Ruby version and Gemfile file to use
- Copy `spec/support/sample.docker.config.yml` to `spec/support/config.yml` (not this config file is specific for the Docker setup)
- Run `docker compose up` to start the container, run the tests, and exit
- Run `docker compose run ruby bash` to open `bash` inside the container for more control, run `rake` to run the tests

> Note that the code is mounted inside the docker container, so changes in the container will reflect in the code. There's no need to re-build the container for code changes, but changing the Ruby version or Gemfile in the docker-compose.yml will require a container re-build with `docker compose build --no-cache`

> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work

## 3. Prepare your contribution

Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG RUBY_VERSION=3.3
FROM ruby:${RUBY_VERSION}

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
# This is copied so we can bundle the application, but it's replaced
# by a mounted volume with the current code when executed with docker compose
COPY . /app

ARG BUNDLE_GEMFILE=Gemfile
ENV BUNDLE_GEMFILE=${BUNDLE_GEMFILE}

# Install any needed packages specified in Gemfile
RUN ./bin/setup

# Command to run the application
CMD ["bash"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ test:
min_messages: WARNING
</pre>

## Development

Check the CONTRIBUTE.md file for instructions running tests with and withour Docker.

## COPYRIGHT

See [LICENSE](LICENSE) for details.
2 changes: 1 addition & 1 deletion database_cleaner-active_record.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = []
spec.require_paths = ["lib"]

spec.add_dependency "database_cleaner-core", "~>2.1.0"
spec.add_dependency "database_cleaner-core", "~>2.0"
spec.add_dependency "activerecord", ">= 5.a"

spec.add_development_dependency "bundler"
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
postgres:
image: postgres:16 # specify the version needed for a given app
environment:
- POSTGRES_PASSWORD=postgres # this is required
ports:
- "127.0.0.1:5432:5432" # so we can use `localhost` as the host
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=mysql
ports:
- "127.0.0.1:3306:3306"
redis:
image: redis:6.2-alpine
restart: always
ports:
- "127.0.0.1:6379:6379"
command: redis-server --save 20 1 --loglevel warning
21 changes: 14 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ services:
image: postgres:16 # specify the version needed for a given app
environment:
- POSTGRES_PASSWORD=postgres # this is required
ports:
- "127.0.0.1:5432:5432" # so we can use `localhost` as the host
mysql:
image: mysql:9.3
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=mysql
ports:
- "127.0.0.1:3306:3306"
redis:
image: redis:6.2-alpine
restart: always
ports:
- "127.0.0.1:6379:6379"
command: redis-server --save 20 1 --loglevel warning
ruby:
build:
context: .
args:
BUNDLE_GEMFILE: gemfiles/rails_7.2.gemfile # Manually change this based on the desired Rails version
RUBY_VERSION: 3.3 # Manually change this based on the desired Ruby version
volumes:
- ".:/app:delegated"
command: rake
depends_on:
- mysql
- postgres
- redis
33 changes: 33 additions & 0 deletions spec/support/sample.docker.config.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an feature request in the core repo DatabaseCleaner/database_cleaner#722

with that we could replace the sample file to support ENV variables and then define password/host with the docker-compose file to not need a second sample file here just for docker

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
mysql2:
adapter: mysql2
database: database_cleaner_test
username: root
password: mysql
host: mysql
port: 3306
encoding: utf8

trilogy:
adapter: trilogy
database: database_cleaner_test
username: root
password: mysql
host: mysql
port: 3306
encoding: utf8

postgres:
adapter: postgresql
database: database_cleaner_test
username: postgres
password: postgres
host: postgres
encoding: unicode
template: template0

sqlite3:
adapter: sqlite3
database: tmp/database_cleaner_test.sqlite3
pool: 5
timeout: 5000
encoding: utf8
Loading