Skip to content

Commit 10a62a3

Browse files
Thelliordrujensen
authored andcommitted
Test multiple databases (#270)
* Everything is now scoped by one adapter at a time * Fixed granite spec * Changed default env to pg * Changed travis CI and ameba fixes * Restored granite spec location * Update .env * Removed log * Fixing timestamps_spec.cr * crystal tool format * Testing travis config * Travis env is not working for multiple versions * Testing matrix option * Added postgres to the matrix * Removed old version that are redundant. Added sqlite * Running with multiple docker-compose files * Seperate docker compose files so only the needed images are build * Changed docker folder * typo * Fixed the duplicate env("CURRENT_ADAPTER") * Added documentation about the env variables * Added more docs * Removed graniteexample because it's not used anymore * Setting default to sqlite * remove extra require spec * Only test the 2 latests versions
1 parent b6e96cd commit 10a62a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2197
-2238
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export PG_DATABASE_URL=postgres://granite:password@localhost:5432/granite_db
22
export MYSQL_DATABASE_URL=mysql://granite:password@localhost:3306/granite_db
33
export SQLITE_DATABASE_URL=sqlite3:./granite.db
4+
export CURRENT_ADAPTER=pg
5+
export PG_VERSION=10.4
6+
export MYSQL_VERSION=5.7

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/.deps/
44
/.crystal/
55
/doc/
6-
/config/*.db
6+
*.db
77

88
# Libraries don't need dependency lock
99
# Dependencies will be locked in application that uses them

.travis.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,35 @@ services:
44
- docker
55

66
before_install:
7-
- docker-compose build spec
7+
- docker-compose -f docker/docker-compose.$CURRENT_ADAPTER.yml build spec
88

99
script:
10-
- docker-compose run spec
10+
- docker-compose -f docker/docker-compose.$CURRENT_ADAPTER.yml run spec
11+
12+
matrix:
13+
include:
14+
- name: "Mysql 5.7"
15+
env:
16+
- CURRENT_ADAPTER=mysql
17+
- MYSQL_VERSION=5.7
18+
- PG_VERSION=10.4
19+
- name: "Mysql 5.6"
20+
env:
21+
- CURRENT_ADAPTER=mysql
22+
- MYSQL_VERSION=5.6
23+
- PG_VERSION=10.4
24+
- name: "Postgres 9.6"
25+
env:
26+
- CURRENT_ADAPTER=pg
27+
- MYSQL_VERSION=5.7
28+
- PG_VERSION=9.6
29+
- name: "Postgres 10.5"
30+
env:
31+
- CURRENT_ADAPTER=pg
32+
- MYSQL_VERSION=5.7
33+
- PG_VERSION=10.5
34+
- name: "Sqlite"
35+
env:
36+
- CURRENT_ADAPTER=sqlite
37+
- MYSQL_VERSION=5.7
38+
- PG_VERSION=10.4

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,38 @@ Start by checking out the [Getting Started](docs/getting_started.md) guide to ge
2828
### Docker setup
2929

3030
There is a self-contained testing environment provided via the `docker-compose.yml` file in this repository.
31+
We are testing against multiple databases so you have to specify which docker-compose file you would like to use.
32+
Replace "{database_type}" with "mysql" or "pg" or "sqlite". Before you can run the docker configuration you have to set the appropriate
33+
env variables. To do so you can either load them yourself or load the .env file
34+
35+
```
36+
$ source .env
37+
```
38+
39+
You can find postgres versions at https://hub.docker.com/_/postgres/
40+
You can find mysql versions at https://hub.docker.com/_/mysql/
3141

3242
After you have docker installed do the following to run tests:
3343

3444
#### First run
3545

3646
```
37-
$ docker-compose build spec
38-
$ docker-compose run spec
47+
$ docker-compose -f docker/docker-compose.{database_type}.yml build spec
48+
$ docker-compose -f docker/docker-compose.{database_type}.yml run spec
3949
```
4050

4151
#### Subsequent runs
4252

4353
```
44-
$ docker-compose run spec
54+
$ docker-compose -f docker/docker-compose.{database_type}.yml run spec
4555
```
4656

4757
#### Cleanup
4858

4959
If you're done testing and you'd like to shut down and clean up the docker dependences run the following:
5060

5161
```
52-
$ docker-compose down
62+
$ docker-compose -f docker/docker-compose.{database_type}.yml down
5363
```
5464

5565
### Local setup
@@ -64,19 +74,19 @@ Start by checking out the [Getting Started](docs/getting_started.md) guide to ge
6474

6575
```sql
6676
CREATE USER granite WITH PASSWORD 'password';
67-
77+
6878
CREATE DATABASE granite_db;
69-
79+
7080
GRANT ALL PRIVILEGES ON DATABASE granite_db TO granite;
7181
```
7282

7383
#### MySQL
7484

7585
```sql
7686
CREATE USER 'granite'@'localhost' IDENTIFIED BY 'password';
77-
87+
7888
CREATE DATABASE granite_db;
79-
89+
8090
GRANT ALL PRIVILEGES ON granite_db.* TO 'granite'@'localhost' WITH GRANT OPTION;
8191
```
8292

docker-compose.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,4 @@ services:
88
PG_DATABASE_URL: 'postgres://postgres:@pg:5432/postgres'
99
MYSQL_DATABASE_URL: 'mysql://user:pass@mysql:3306/test'
1010
SQLITE_DATABASE_URL: 'sqlite3:./test.db'
11-
depends_on:
12-
- pg
13-
- mysql
14-
pg:
15-
image: postgres:10.4
16-
mysql:
17-
image: mysql:5.7
18-
environment:
19-
MYSQL_ROOT_PASSWORD: pass
20-
MYSQL_DATABASE: test
21-
MYSQL_USER: user
22-
MYSQL_PASSWORD: pass
11+
CURRENT_ADAPTER: sqlite

docker/docker-compose.mysql.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '2'
2+
services:
3+
spec:
4+
extends:
5+
file: ../docker-compose.yml
6+
service: spec
7+
environment:
8+
CURRENT_ADAPTER: mysql
9+
depends_on:
10+
- mysql
11+
mysql:
12+
image: mysql:${MYSQL_VERSION}
13+
environment:
14+
MYSQL_ROOT_PASSWORD: pass
15+
MYSQL_DATABASE: test
16+
MYSQL_USER: user
17+
MYSQL_PASSWORD: pass

docker/docker-compose.pg.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '2'
2+
services:
3+
spec:
4+
extends:
5+
file: ../docker-compose.yml
6+
service: spec
7+
environment:
8+
CURRENT_ADAPTER: pg
9+
depends_on:
10+
- pg
11+
pg:
12+
image: postgres:${PG_VERSION}

docker/docker-compose.sqlite.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '2'
2+
services:
3+
spec:
4+
extends:
5+
file: ../docker-compose.yml
6+
service: spec
7+
environment:
8+
CURRENT_ADAPTER: sqlite
Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,68 @@
11
require "../../spec_helper"
22

3-
{% for adapter in GraniteExample::ADAPTERS %}
4-
module {{adapter.capitalize.id}}
5-
describe "{{ adapter.id }} belongs_to" do
6-
it "provides a getter for the foreign entity" do
7-
teacher = Teacher.new
8-
teacher.name = "Test teacher"
9-
teacher.save
3+
describe "belongs_to" do
4+
it "provides a getter for the foreign entity" do
5+
teacher = Teacher.new
6+
teacher.name = "Test teacher"
7+
teacher.save
108

11-
klass = Klass.new
12-
klass.name = "Test klass"
13-
klass.teacher_id = teacher.id
14-
klass.save
9+
klass = Klass.new
10+
klass.name = "Test klass"
11+
klass.teacher_id = teacher.id
12+
klass.save
1513

16-
klass.teacher.id.should eq teacher.id
17-
end
14+
klass.teacher.id.should eq teacher.id
15+
end
1816

19-
it "provides a setter for the foreign entity" do
20-
teacher = Teacher.new
21-
teacher.name = "Test teacher"
22-
teacher.save
17+
it "provides a setter for the foreign entity" do
18+
teacher = Teacher.new
19+
teacher.name = "Test teacher"
20+
teacher.save
2321

24-
klass = Klass.new
25-
klass.name = "Test klass"
26-
klass.teacher = teacher
27-
klass.save
22+
klass = Klass.new
23+
klass.name = "Test klass"
24+
klass.teacher = teacher
25+
klass.save
2826

29-
klass.teacher_id.should eq teacher.id
30-
end
27+
klass.teacher_id.should eq teacher.id
28+
end
3129

32-
it "supports custom types for the join" do
33-
book = Book.new
34-
book.name = "Screw driver"
35-
book.save
30+
it "supports custom types for the join" do
31+
book = Book.new
32+
book.name = "Screw driver"
33+
book.save
3634

37-
review = BookReview.new
38-
review.book = book
39-
review.body = "Best book ever!"
40-
review.save
35+
review = BookReview.new
36+
review.book = book
37+
review.body = "Best book ever!"
38+
review.save
4139

42-
review.book.name.should eq "Screw driver"
43-
end
40+
review.book.name.should eq "Screw driver"
41+
end
4442

45-
it "supports custom method name" do
46-
author = Person.new
47-
author.name = "John Titor"
48-
author.save
43+
it "supports custom method name" do
44+
author = Person.new
45+
author.name = "John Titor"
46+
author.save
4947

50-
book = Book.new
51-
book.name = "How to Time Traveling"
52-
book.author = author
53-
book.save
48+
book = Book.new
49+
book.name = "How to Time Traveling"
50+
book.author = author
51+
book.save
5452

55-
book.author.name.should eq "John Titor"
56-
end
53+
book.author.name.should eq "John Titor"
54+
end
5755

58-
it "supports both custom method name and custom types for the join" do
59-
publisher = Company.new
60-
publisher.name = "Amber Framework"
61-
publisher.save
56+
it "supports both custom method name and custom types for the join" do
57+
publisher = Company.new
58+
publisher.name = "Amber Framework"
59+
publisher.save
6260

63-
book = Book.new
64-
book.name = "Introduction to Granite"
65-
book.publisher = publisher
66-
book.save
61+
book = Book.new
62+
book.name = "Introduction to Granite"
63+
book.publisher = publisher
64+
book.save
6765

68-
book.publisher.name.should eq "Amber Framework"
69-
end
66+
book.publisher.name.should eq "Amber Framework"
7067
end
7168
end
72-
{% end %}

0 commit comments

Comments
 (0)