mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
add spec for transactions and nested transactions (#12)
This commit is contained in:
parent
c39220e3f0
commit
46709eab00
2 changed files with 83 additions and 0 deletions
|
@ -242,4 +242,57 @@ describe Driver do
|
|||
File.delete(DB_FILENAME)
|
||||
end
|
||||
end
|
||||
|
||||
describe "transactions" do
|
||||
it "can read inside transaction and rollback after" do
|
||||
with_db do |db|
|
||||
db.exec "create table person (name varchar(25))"
|
||||
db.transaction do |tx|
|
||||
tx.connection.scalar("select count(*) from person").should eq(0)
|
||||
tx.connection.exec "insert into person (name) values (?)", "John Doe"
|
||||
tx.connection.scalar("select count(*) from person").should eq(1)
|
||||
tx.rollback
|
||||
end
|
||||
db.scalar("select count(*) from person").should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "can read inside transaction or after commit" do
|
||||
with_db do |db|
|
||||
db.exec "create table person (name varchar(25))"
|
||||
db.transaction do |tx|
|
||||
tx.connection.scalar("select count(*) from person").should eq(0)
|
||||
tx.connection.exec "insert into person (name) values (?)", "John Doe"
|
||||
tx.connection.scalar("select count(*) from person").should eq(1)
|
||||
# using other connection
|
||||
db.scalar("select count(*) from person").should eq(0)
|
||||
end
|
||||
db.scalar("select count(*) from person").should eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "nested transactions" do
|
||||
it "can read inside transaction and rollback after" do
|
||||
with_db do |db|
|
||||
db.exec "create table person (name varchar(25))"
|
||||
db.transaction do |tx_0|
|
||||
tx_0.connection.scalar("select count(*) from person").should eq(0)
|
||||
tx_0.connection.exec "insert into person (name) values (?)", "John Doe"
|
||||
tx_0.transaction do |tx_1|
|
||||
tx_1.connection.exec "insert into person (name) values (?)", "Sarah"
|
||||
tx_1.connection.scalar("select count(*) from person").should eq(2)
|
||||
tx_1.transaction do |tx_2|
|
||||
tx_2.connection.exec "insert into person (name) values (?)", "Jimmy"
|
||||
tx_2.connection.scalar("select count(*) from person").should eq(3)
|
||||
tx_2.rollback
|
||||
end
|
||||
end
|
||||
tx_0.connection.scalar("select count(*) from person").should eq(2)
|
||||
tx_0.rollback
|
||||
end
|
||||
db.scalar("select count(*) from person").should eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue