mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Returns block's value on #transaction method (#159)
* Returns block's value on #transaction method * Update src/db/begin_transaction.cr Co-authored-by: Johannes Müller <straightshoota@gmail.com> Co-authored-by: Johannes Müller <straightshoota@gmail.com>
This commit is contained in:
parent
5a7d27e0c5
commit
d829b07b01
2 changed files with 40 additions and 2 deletions
|
@ -175,4 +175,39 @@ describe DB::Transaction do
|
|||
db.pool.is_available?(cnn).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "returns block value when sucess" do
|
||||
with_dummy_connection do |cnn|
|
||||
res = cnn.transaction do |tx|
|
||||
42
|
||||
end
|
||||
|
||||
res.should eq(42)
|
||||
typeof(res).should eq(Int32 | Nil)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns value on rollback via method" do
|
||||
with_dummy_connection do |cnn|
|
||||
res = cnn.transaction do |tx|
|
||||
tx.rollback
|
||||
42
|
||||
end
|
||||
|
||||
res.should eq(42)
|
||||
typeof(res).should eq(Int32 | Nil)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns nil on rollback via exception" do
|
||||
with_dummy_connection do |cnn|
|
||||
res = cnn.transaction do |tx|
|
||||
raise DB::Rollback.new
|
||||
42
|
||||
end
|
||||
|
||||
res.should be_nil
|
||||
typeof(res).should eq(Int32 | Nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue