Skip to content

Commit 3a77ccd

Browse files
committed
Add a section showing mysql+docker for test/dev
1 parent 931eb7e commit 3a77ccd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

RUNNING_TESTS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Rake tasks are loaded from **rakelib/02-test-rake**, most adapters have a
1616
corresponding test_[adapter] task e.g. `rake test_sqlite3` that run against DB.
1717
To check all available (test related) tasks simply `rake -T | grep test`.
1818

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

4951
rake test_derby PREPARED_STATEMENTS=false
5052

53+
#### MySQL with Docker
54+
55+
The standard Docker MySQL image can be used for testing and development. Depending on your environment these commands
56+
may need to be run as root.
57+
58+
Pull the image:
59+
60+
```
61+
sudo docker pull mysql
62+
```
63+
64+
Start up the database with a root password:
65+
66+
```
67+
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=testtest9 -d mysql
68+
```
69+
70+
The `mysql` client can be run through Docker as well:
71+
72+
```sh
73+
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"'
74+
```
75+
76+
Set up the database for the unit tests:
77+
78+
```sql
79+
GRANT ALL PRIVILEGES ON *.* TO 'rails'@'localhost' IDENTIFIED BY 'XXXXXXXXX';
80+
81+
CREATE USER 'rails'@'localhost' IDENTIFIED BY 'testtest9';
82+
create database activerecord_unittest2;
83+
GRANT Create,Drop,Select,Insert,Update,Delete,Lock Tables ON activerecord_unittest2.* TO 'rails'@'172.17.0.1';
84+
```
5185

5286
### ActiveRecord (Rails) Tests
5387

0 commit comments

Comments
 (0)