Skip to content

Commit 7ec974a

Browse files
joao-estevesJoão Esteves
andauthored
doc: Add test instructions (#136)
* Add test instructions * Use env var in more places --------- Co-authored-by: João Esteves <joao.esteves@jumpseller.com>
1 parent 5a877cb commit 7ec974a

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ concurrent access to **any instance of a model**. Their coarseness means they
147147
aren't going to be commonly applicable, and they can be a source of
148148
[deadlocks](http://en.wikipedia.org/wiki/Deadlock).
149149

150+
## Running Tests
151+
152+
To setup the project and run the whole test suite:
153+
154+
1. Have Docker running
155+
2. `echo -e "DB_USER=with_advisory\nDB_PASSWORD=with_advisory_pass\nDB_NAME=with_advisory_lock_test\nDATABASE_URL_PG=postgres://\$DB_USER:\$DB_PASSWORD@localhost:5433/\$DB_NAME\nDATABASE_URL_MYSQL=mysql2://\$DB_USER:\$DB_PASSWORD@127.0.0.1:3366/\$DB_NAME" > .env`
156+
3. `make`
157+
158+
Alternatively to `make`, run `bin/rails test` to skip database and dependency setup.
159+
150160
## FAQ
151161

152162
### Transactions and Advisory Locks

bin/setup_test_db

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
require 'bundler/setup'
55
require 'active_record'
6+
require 'dotenv'
7+
Dotenv.load
68

79
# Setup PostgreSQL database
810
puts 'Setting up PostgreSQL test database...'
911
ActiveRecord::Base.establish_connection(
1012
adapter: 'postgresql',
1113
host: 'localhost',
1214
port: 5433,
13-
database: 'with_advisory_lock_test',
14-
username: 'with_advisory',
15-
password: 'with_advisory_pass'
15+
database: ENV['DB_NAME'],
16+
username: ENV['DB_USER'],
17+
password: ENV['DB_PASSWORD']
1618
)
1719

1820
ActiveRecord::Schema.define(version: 1) do
@@ -36,9 +38,9 @@ ActiveRecord::Base.establish_connection(
3638
adapter: 'mysql2',
3739
host: '127.0.0.1',
3840
port: 3366,
39-
database: 'with_advisory_lock_test',
40-
username: 'with_advisory',
41-
password: 'with_advisory_pass'
41+
database: ENV['DB_NAME'],
42+
username: ENV['DB_USER'],
43+
password: ENV['DB_PASSWORD']
4244
)
4345

4446
ActiveRecord::Schema.define(version: 1) do

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ services:
22
pg:
33
image: postgres:17-alpine
44
environment:
5-
POSTGRES_USER: with_advisory
6-
POSTGRES_PASSWORD: with_advisory_pass
7-
POSTGRES_DB: with_advisory_lock_test
5+
POSTGRES_USER: ${DB_USER}
6+
POSTGRES_PASSWORD: ${DB_PASSWORD}
7+
POSTGRES_DB: ${DB_NAME}
88
ports:
99
- "5433:5432"
1010
mysql:
1111
image: mysql:8
1212
environment:
13-
MYSQL_USER: with_advisory
14-
MYSQL_PASSWORD: with_advisory_pass
15-
MYSQL_DATABASE: with_advisory_lock_test
13+
MYSQL_USER: ${DB_USER}
14+
MYSQL_PASSWORD: ${DB_PASSWORD}
15+
MYSQL_DATABASE: ${DB_NAME}
1616
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
1717
MYSQL_ROOT_HOST: '%'
1818
ports:

0 commit comments

Comments
 (0)