Skip to content

Commit ce1592d

Browse files
committed
Use older mysql to avoid trilogy error, fix docker compose and instructions, mount code for easier development
1 parent 8875fc7 commit ce1592d

5 files changed

Lines changed: 57 additions & 25 deletions

File tree

CONTRIBUTE.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,28 @@ upstream:
1212

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

15-
- 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)
16-
- Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it
15+
### Run tests without Docker (or using Docker only for the databases)
16+
17+
- 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)
18+
- Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it as needed
1719
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle install` (change `6.1` with any version from the `gemfiles` directory)
1820
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle exec rake`
1921

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

23-
> Note that you can check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
25+
> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
26+
27+
### Run tests with Docker
28+
29+
- Open `docker-compose.yml` and configure the Ruby version and Gemfile file to use
30+
- Copy `spec/support/sample.docker.config.yml` to `spec/support/config.yml` (not this config file is specific for the Docker setup)
31+
- Run `docker compose up` to start the container, run the tests, and exit
32+
- Run `docker compose run ruby bash` to open `bash` inside the container for more control, run `rake` to run the tests
33+
34+
> 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`
35+
36+
> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
2437
2538
## 3. Prepare your contribution
2639

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
FROM ruby:3.3
1+
ARG RUBY_VERSION=3.3
2+
FROM ruby:${RUBY_VERSION}
23

34
# Set the working directory in the container
45
WORKDIR /app
56

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

9-
# Copy the sample config to the actual config (performed at build time)
10-
RUN cp spec/support/sample.docker.config.yml spec/support/config.yml
12+
ARG BUNDLE_GEMFILE=Gemfile
13+
ENV BUNDLE_GEMFILE=${BUNDLE_GEMFILE}
1114

1215
# Install any needed packages specified in Gemfile
1316
RUN bundle install

docker-compose.db.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
postgres:
3+
image: postgres:16 # specify the version needed for a given app
4+
environment:
5+
- POSTGRES_PASSWORD=postgres # this is required
6+
ports:
7+
- "127.0.0.1:5432:5432" # so we can use `localhost` as the host
8+
mysql:
9+
image: mysql:5.7
10+
environment:
11+
- MYSQL_ROOT_PASSWORD=mysql
12+
ports:
13+
- "127.0.0.1:3306:3306"
14+
redis:
15+
image: redis:6.2-alpine
16+
restart: always
17+
ports:
18+
- "127.0.0.1:6379:6379"
19+
command: redis-server --save 20 1 --loglevel warning

docker-compose.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ services:
33
image: postgres:16 # specify the version needed for a given app
44
environment:
55
- POSTGRES_PASSWORD=postgres # this is required
6-
ports:
7-
- "127.0.0.1:5432:5432" # so we can use `localhost` as the host
86
mysql:
9-
image: mysql:9.3
7+
image: mysql:5.7
108
environment:
119
- MYSQL_ROOT_PASSWORD=mysql
12-
ports:
13-
- "127.0.0.1:3306:3306"
1410
redis:
1511
image: redis:6.2-alpine
1612
restart: always
17-
ports:
18-
- "127.0.0.1:6379:6379"
1913
command: redis-server --save 20 1 --loglevel warning
2014
ruby:
21-
image: ruby:3.3 # Manually change this based on the desired Ruby version
22-
working_dir: /app
23-
build: .
24-
environment:
25-
BUNDLE_GEMFILE: gemfiles/rails_7.2.gemfile # Manually change this based on the desired Rails version
15+
build:
16+
context: .
17+
args:
18+
BUNDLE_GEMFILE: gemfiles/rails_7.2.gemfile # Manually change this based on the desired Rails version
19+
RUBY_VERSION: 3.3 # Manually change this based on the desired Ruby version
20+
volumes:
21+
- ".:/app:delegated"
22+
command: rake
2623
depends_on:
2724
- mysql
2825
- postgres

lib/database_cleaner/active_record/truncation.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(opts={})
2121
def clean
2222
connection.disable_referential_integrity do
2323
if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
24-
connection.pre_count_truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
24+
connection.pre_count_truncate_tables(tables_to_clean(connection))
2525
else
2626
connection.truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
2727
end
@@ -109,8 +109,8 @@ def truncate_tables(tables, opts)
109109
end
110110

111111
module AbstractMysqlAdapter
112-
def pre_count_truncate_tables(tables, opts = {})
113-
truncate_tables(pre_count_tables(tables), opts)
112+
def pre_count_truncate_tables(tables)
113+
truncate_tables(pre_count_tables(tables))
114114
end
115115

116116
def pre_count_tables(tables)
@@ -157,8 +157,8 @@ def truncate_tables(tables, opts)
157157
tables.each { |t| truncate_table(t) }
158158
end
159159

160-
def pre_count_truncate_tables(tables, opts = {})
161-
truncate_tables(pre_count_tables(tables), opts)
160+
def pre_count_truncate_tables(tables)
161+
truncate_tables(pre_count_tables(tables))
162162
end
163163

164164
def pre_count_tables(tables)
@@ -200,8 +200,8 @@ def truncate_tables(table_names, opts)
200200
execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY #{opts[:truncate_option]};")
201201
end
202202

203-
def pre_count_truncate_tables(tables, opts = {})
204-
truncate_tables(pre_count_tables(tables), opts)
203+
def pre_count_truncate_tables(tables)
204+
truncate_tables(pre_count_tables(tables))
205205
end
206206

207207
def pre_count_tables(tables)

0 commit comments

Comments
 (0)