File tree Expand file tree Collapse file tree 3 files changed +24
-12
lines changed
Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,16 @@ concurrent access to **any instance of a model**. Their coarseness means they
147147aren'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
Original file line number Diff line number Diff line change 33
44require 'bundler/setup'
55require 'active_record'
6+ require 'dotenv'
7+ Dotenv . load
68
79# Setup PostgreSQL database
810puts 'Setting up PostgreSQL test database...'
911ActiveRecord ::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
1820ActiveRecord ::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
4446ActiveRecord ::Schema . define ( version : 1 ) do
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments