-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update spec tests and add ghaction #474
Changes from all commits
6888fa7
9be1974
b31bc4b
7dcd15b
3c4947c
6218129
ead889e
7937d22
011bb89
b6ecf3e
a65ed54
ac4e4a3
11cc067
56f030c
5adecec
c0fc782
d40b757
ed0bfed
7c0db8c
acde9ae
d7ef384
a57b086
4928ab2
46aa590
b024c8a
1ec0ea5
f55156b
4f641f3
f2cce73
f48a6df
101f7e8
d72bf01
aec78e3
06868c8
be261b7
9fad717
4a35e7f
ceb7285
b9bf437
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotenv_if_exists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
name: spec | ||
on: | ||
push: | ||
pull_request: | ||
branches: [main, master] | ||
# schedule: | ||
# - cron: "0 6 * * 6" # Every Saturday 6 AM | ||
jobs: | ||
formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: oprypin/[email protected] | ||
with: | ||
crystal: latest | ||
- name: Check formatting | ||
run: crystal tool format --check | ||
sqlite-spec: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 1 | ||
matrix: | ||
crystal: [1.6.2, 1.7.2, 1.8.1, latest] | ||
steps: | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: oprypin/[email protected] | ||
with: | ||
crystal: ${{ matrix.crystal }} | ||
- name: Install shards | ||
run: shards update --ignore-crystal-version | ||
- name: Run tests | ||
timeout-minutes: 2 | ||
run: crystal spec | ||
env: | ||
CURRENT_ADAPTER: sqlite | ||
SQLITE_DATABASE_URL: sqlite3:./granite.db | ||
MYSQL_DATABASE_URL: mysql://granite:password@localhost:3306/granite_db | ||
PG_DATABASE_URL: postgres://granite:password@localhost:5432/granite_db | ||
mysql-spec: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 1 | ||
matrix: | ||
crystal: [1.6.2, 1.7.2, 1.8.1, latest] | ||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
options: >- | ||
--health-cmd "mysqladmin ping" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
env: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: granite_db | ||
MYSQL_USER: granite | ||
MYSQL_PASSWORD: password | ||
ports: | ||
- 3306:3306 | ||
steps: | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: oprypin/[email protected] | ||
with: | ||
crystal: ${{ matrix.crystal }} | ||
- name: Install shards | ||
run: shards update --ignore-crystal-version | ||
- name: Run tests | ||
timeout-minutes: 2 | ||
run: crystal spec | ||
env: | ||
CURRENT_ADAPTER: mysql | ||
SQLITE_DATABASE_URL: sqlite3:./granite.db | ||
MYSQL_DATABASE_URL: mysql://granite:password@localhost:3306/granite_db | ||
PG_DATABASE_URL: postgres://granite:password@localhost:5432/granite_db | ||
psql-spec: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 1 | ||
matrix: | ||
crystal: [1.6.2, 1.7.2, 1.8.1, latest] | ||
services: | ||
postgres: | ||
image: postgres:15.2 | ||
env: | ||
POSTGRES_USER: granite | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: granite_db | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
# Maps tcp port 5432 on service container to the host | ||
- 5432:5432 | ||
steps: | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Install Crystal | ||
uses: oprypin/[email protected] | ||
with: | ||
crystal: ${{ matrix.crystal }} | ||
- name: Install shards | ||
run: shards update --ignore-crystal-version | ||
- name: Run tests | ||
timeout-minutes: 2 | ||
run: crystal spec | ||
env: | ||
CURRENT_ADAPTER: pg | ||
SQLITE_DATABASE_URL: sqlite3:./granite.db | ||
MYSQL_DATABASE_URL: mysql://granite:password@localhost:3306/granite_db | ||
PG_DATABASE_URL: postgres://granite:password@localhost:5432/granite_db |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
require "../../spec_helper" | ||
|
||
describe "has_one" do | ||
before_each do | ||
User.clear | ||
Profile.clear | ||
Courier.clear | ||
Character.clear | ||
end | ||
|
||
it "provides a setter to set childrens's foriegn_key from parent" do | ||
profile = Profile.new | ||
profile.name = "Test Profile" | ||
|
@@ -34,9 +41,8 @@ describe "has_one" do | |
it "provides a method to retrieve associated object that will raise if record is not found" do | ||
user = User.new | ||
user.email = "[email protected]" | ||
user.save | ||
|
||
expect_raises Granite::Querying::NotFound, "No Profile found where user_id = 3" { user.profile! } | ||
user.save! | ||
expect_raises Granite::Querying::NotFound, "No Profile found where user_id = #{user.id}" { user.profile! } | ||
end | ||
|
||
it "provides the ability to use a custom primary key" do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,13 +48,13 @@ require "../spec_helper" | |
end | ||
|
||
it "property defines IN query" do | ||
sql = "SELECT #{query_fields} FROM table WHERE date_completed IS NULL AND status IN ('outstanding','in_progress') ORDER BY id DESC" | ||
sql = "SELECT #{query_fields} FROM table WHERE date_completed IS NULL AND status IN (?,?) ORDER BY id DESC" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch there! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this was an change i made to the underlying lib. Previously granite was attempting to escape the string itself by wrapping it in single quotes, but it broke with strings that contained them such as "joe's burger". Now strings are passed down to the underlying adapter for variable substitution. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember why we were doing that at all, but maybe there's a reason. I think ideally we should avoid doing any substitution in queries ourselves, since the database is better equipped to do that for us safely. |
||
query = builder.where(date_completed: nil, status: ["outstanding", "in_progress"]) | ||
query.raw_sql.should match ignore_whitespace sql | ||
|
||
assembler = query.assembler | ||
assembler.where | ||
assembler.numbered_parameters.should eq [] of Granite::Columns::Type | ||
assembler.numbered_parameters.should eq ["outstanding", "in_progress"] | ||
end | ||
|
||
it "property defines IN query with numbers" do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#! /bin/bash | ||
|
||
source ../.env | ||
source .env | ||
|
||
echo "Testing PG" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
MYSQL_VERSION=${MYSQL_VERSION:-5.7} | ||
PG_VERSION=${PG_VERSION:-15.2} | ||
|
||
docker run --name mysql -d \ | ||
-e MYSQL_ROOT_PASSWORD=password \ | ||
-e MYSQL_DATABASE=granite_db \ | ||
-e MYSQL_USER=granite \ | ||
-e MYSQL_PASSWORD=password \ | ||
-p 3306:3306 \ | ||
mysql:%{MYSQL_VERSION} | ||
|
||
docker run --name psql -d \ | ||
-e POSTGRES_USER=granite \ | ||
-e POSTGRES_PASSWORD=password \ | ||
-e POSTGRES_DB=granite_db \ | ||
-p 5432:5432 \ | ||
postgres:${PG_VERSION} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should change this to use v8 instead of v5.7 since 5.7 is EOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, i did run it against 8, but there's a bug/issue with connecting to 8 with the adapter.
crystal-lang/crystal-mysql#62
I suggest we handle moving to 8 for testing in a separate issue, as it will take me a bit to work around it.