-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update spec tests and add ghaction (#474)
* Add a check to ensure created_at and updated_at are Time If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs: ```There was a problem expanding macro 'macro_4801706624' Code in lib/granite/src/granite/transactions.cr:82:5 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %} ^ Called macro defined in lib/granite/src/granite/transactions.cr:82:5 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %} Which expanded to: > 1 | > 2 | if mode == :create > 3 | @created_at = time.at_beginning_of_second ^--------------------- ``` this simply adds a type check. * fix allowing enum columns * ameba fixes * fix build_find_by_clause for bool values * minor update * Fix issue where primary key can be pushed twice on create * fix infinate recusion when searching with enum * add retry to adapter base * add retry to adapters * minor update * add support for querying with Array(UUID) * format docs * FIX: add converter to read_attribute * Fix for type declaration in has_one * Fix callback runs on #import * more has_one fixes; fixes for through associations * small formatting fixes * fix passing primary_key to has_one * Add to docs (#446) * Quote fields in PG query assembler * Created converter for PG Enums that are returned as bytes * Quote table names in adapter methods only if not already quoted * Check if table/column string has already been quoted * Quote foreign key * Quote fields in query assemblers * added some docs * Created converter for Postgres enum arrays * Incorrect variable name * Added target key to association collection for many relations type * Added truncate function for postgres adapter * Removed unrequired parameter * Rogue value in log for truncate * Added truncate method for models * Add JsonString converter * Must use chars to check string index equality * add note for custom select macro * removed some other commits * removed changes from other pr * removed work from other pr * removed work from other pr * removed commits from other pr --------- Co-authored-by: ionica21 <[email protected]> * add support for foreign key converters (#438) Co-authored-by: Joakim Repomaa <[email protected]> * fix build_find_by_clause for bool values (#455) * Add context to RecordNotSaved/RecordNotDestroyed error messages (#452) * Add a check to ensure created_at and updated_at are Time (#454) If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs: ```There was a problem expanding macro 'macro_4801706624' Code in lib/granite/src/granite/transactions.cr:82:5 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %} ^ Called macro defined in lib/granite/src/granite/transactions.cr:82:5 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %} Which expanded to: > 1 | > 2 | if mode == :create > 3 | @created_at = time.at_beginning_of_second ^--------------------- ``` this simply adds a type check. * small formatting fixes * fix passing primary_key to has_one * fix spec: Granite no longer escapes strings, but passes them to the underlying adapter * Fix yaml spec to ignore whitespaces * working mysql spec tests * spec updates * add github workflows (#1) * update docker to use crystal 1.8 and added github action * fix workflow if statements * split workflow into separate jobs for each database * workflow: fix missing envs * workflow: add psql db var * attempt to use workflow services * split tests by database to speed things up * fix sql test * comment out workflow schedule * re-enable ameba --------- Co-authored-by: Seth T <[email protected]> Co-authored-by: Richard Howell-Peak <[email protected]> Co-authored-by: ionica21 <[email protected]> Co-authored-by: Joakim Repomaa <[email protected]> Co-authored-by: Joakim Repomaa <[email protected]> Co-authored-by: Aurélien Delogu <[email protected]>
- Loading branch information
1 parent
5c37572
commit 5afa787
Showing
22 changed files
with
213 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotenv_if_exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#! /bin/bash | ||
|
||
source ../.env | ||
source .env | ||
|
||
echo "Testing PG" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
Oops, something went wrong.