Skip to content

Commit

Permalink
don't include nested tx spec for sqlite as it's not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
repomaa committed Nov 6, 2019
1 parent ad5a6ff commit 7f47b9c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions spec/transactions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -361,32 +361,35 @@ describe Crecto do
end
{% end %}

it "allows nesting transactions" do
Repo.delete_all(Post)
Repo.delete_all(User)
# Sqlite doesn't support nesting transactions
{% unless flag?(:sqlite) %}
it "allows nesting transactions" do
Repo.delete_all(Post)
Repo.delete_all(User)

insert_user = User.new
insert_user.name = "nested_transactions_insert_user"
invalid_user = User.new
delete_user = quick_create_user("nested_transactions_delete_user")
insert_user = User.new
insert_user.name = "nested_transactions_insert_user"
invalid_user = User.new
delete_user = quick_create_user("nested_transactions_delete_user")

Repo.transaction! do |tx|
tx.insert!(insert_user)
Repo.transaction! do |tx|
tx.insert!(insert_user)

expect_raises Crecto::InvalidChangeset do
Repo.transaction! do |inner_tx|
inner_tx.delete!(delete_user)
inner_tx.insert!(invalid_user)
expect_raises Crecto::InvalidChangeset do
Repo.transaction! do |inner_tx|
inner_tx.delete!(delete_user)
inner_tx.insert!(invalid_user)
end
end
end
end

# check insert happened
Repo.all(User, Query.where(name: "nested_transactions_insert_user")).size.should eq 1
# check insert happened
Repo.all(User, Query.where(name: "nested_transactions_insert_user")).size.should eq 1

# check delete didn't happen
Repo.all(User, Query.where(name: "nested_transactions_delete_user")).size.should eq 1
end
# check delete didn't happen
Repo.all(User, Query.where(name: "nested_transactions_delete_user")).size.should eq 1
end
{% end %}
end
end
end

0 comments on commit 7f47b9c

Please sign in to comment.