Skip to content

Commit

Permalink
Add a section showing mysql+docker for test/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 25, 2024
1 parent 931eb7e commit 3a77ccd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions RUNNING_TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Rake tasks are loaded from **rakelib/02-test-rake**, most adapters have a
corresponding test_[adapter] task e.g. `rake test_sqlite3` that run against DB.
To check all available (test related) tasks simply `rake -T | grep test`.

### Database Setup

If the adapter supports creating a database it will try to do so automatically
(most embed databases such as SQLite3) for some adapters (MySQL, PostgreSQL) we
do this auto-magically (see the `rake db:create` tasks), but otherwise you'll
Expand Down Expand Up @@ -48,6 +50,38 @@ but one can easily run tests with prepared statements disabled using env vars :

rake test_derby PREPARED_STATEMENTS=false

#### MySQL with Docker

The standard Docker MySQL image can be used for testing and development. Depending on your environment these commands
may need to be run as root.

Pull the image:

```
sudo docker pull mysql
```

Start up the database with a root password:

```
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=testtest9 -d mysql
```

The `mysql` client can be run through Docker as well:

```sh
docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
```

Set up the database for the unit tests:

```sql
GRANT ALL PRIVILEGES ON *.* TO 'rails'@'localhost' IDENTIFIED BY 'XXXXXXXXX';

CREATE USER 'rails'@'localhost' IDENTIFIED BY 'testtest9';
create database activerecord_unittest2;
GRANT Create,Drop,Select,Insert,Update,Delete,Lock Tables ON activerecord_unittest2.* TO 'rails'@'172.17.0.1';
```

### ActiveRecord (Rails) Tests

Expand Down

0 comments on commit 3a77ccd

Please sign in to comment.