Skip to content

Commit

Permalink
sqlite and mysql don't yet support reading records from transactions
Browse files Browse the repository at this point in the history
this disables the tx read specs for mysql and sqlite
  • Loading branch information
repomaa committed Nov 6, 2019
1 parent 1d88a0f commit ad5a6ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: crystal
script:
- crystal spec
- crystal spec -D $DB_TYPE
- crystal tool format --check
services:
- mysql
Expand All @@ -18,11 +18,9 @@ before_script:
- psql -c 'create database crecto_test;' -U postgres
- psql $PG_URL < spec/migrations/pg_migrations.sql
- sqlite3 ./crecto_test.db < spec/migrations/sqlite3_migrations.sql
- if [ ! -z "$PG_URL" ]; then cp ./spec/travis_pg_repo.cr ./spec/repo.cr; fi
- if [ ! -z "$MYSQL_URL" ]; then cp ./spec/travis_mysql_repo.cr ./spec/repo.cr; fi
- if [ ! -z "$SQLITE3_PATH" ]; then cp ./spec/travis_sqlite_repo.cr ./spec/repo.cr; fi
- cp ./spec/travis_${DB_TYPE}_repo.cr ./spec/repo.cr
env:
matrix:
- PG_URL=postgres://postgres@localhost:5432/crecto_test
- MYSQL_URL=mysql://root@localhost/crecto_test
- SQLITE3_PATH=sqlite3://./crecto_test.db
- PG_URL=postgres://postgres@localhost:5432/crecto_test DB_TYPE=pg
- MYSQL_URL=mysql://root@localhost/crecto_test DB_TYPE=mysql
- SQLITE3_PATH=sqlite3://./crecto_test.db DB_TYPE=sqlite
39 changes: 21 additions & 18 deletions spec/transactions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,29 @@ describe Crecto do
Repo.all(User, Query.where(name: "perform_all_io2oj999")).size.should eq 0
end

it "allows reading records inserted inside the transaction" do
insert_user = User.new
insert_user.name = "insert_user"
# This only works for postgres for now
{% begin %}
{{ flag?(:pg) ? :it.id : :pending.id }} "allows reading records inserted inside the transaction" do
insert_user = User.new
insert_user.name = "insert_user"

Repo.transaction! do |tx|
id = tx.insert!(insert_user).instance.id
tx.get(User, id).should_not eq(nil)
tx.get!(User, id).should_not eq(nil)
tx.get(User, id, Query.new).should_not eq(nil)
tx.get!(User, id, Query.new).should_not eq(nil)
tx.get_by(User, id: id).should_not eq(nil)
tx.get_by!(User, id: id).should_not eq(nil)
tx.get_by(User, id: id).should_not eq(nil)
tx.get_by!(User, id: id).should_not eq(nil)
tx.get_by(User, Query.where(id: id)).should_not eq(nil)
tx.get_by!(User, Query.where(id: id)).should_not eq(nil)
tx.all(User, Query.where(id: id)).first.should_not eq(nil)
tx.all(User, Query.where(id: id), preload: [] of Symbol).first.should_not eq(nil)
Repo.transaction! do |tx|
id = tx.insert!(insert_user).instance.id
tx.get(User, id).should_not eq(nil)
tx.get!(User, id).should_not eq(nil)
tx.get(User, id, Query.new).should_not eq(nil)
tx.get!(User, id, Query.new).should_not eq(nil)
tx.get_by(User, id: id).should_not eq(nil)
tx.get_by!(User, id: id).should_not eq(nil)
tx.get_by(User, id: id).should_not eq(nil)
tx.get_by!(User, id: id).should_not eq(nil)
tx.get_by(User, Query.where(id: id)).should_not eq(nil)
tx.get_by!(User, Query.where(id: id)).should_not eq(nil)
tx.all(User, Query.where(id: id)).first.should_not eq(nil)
tx.all(User, Query.where(id: id), preload: [] of Symbol).first.should_not eq(nil)
end
end
end
{% end %}

it "allows nesting transactions" do
Repo.delete_all(Post)
Expand Down

0 comments on commit ad5a6ff

Please sign in to comment.