diff --git a/lib/libsql.rb b/lib/libsql.rb index 1dfb681..9038cd0 100644 --- a/lib/libsql.rb +++ b/lib/libsql.rb @@ -504,7 +504,7 @@ def transaction abort = true raise ensure - abort and tx.rollback or tx.commit + abort ? tx.rollback : tx.commit end end diff --git a/spec/libsql_spec.rb b/spec/libsql_spec.rb index 42eecd1..8135fe1 100644 --- a/spec/libsql_spec.rb +++ b/spec/libsql_spec.rb @@ -73,4 +73,16 @@ expect(count).to eq(0) end end + + describe 'Connection#transaction' do + context 'when there is an exception' do + it 'aborts the transaction and raises the exception' do + exception_class = Class.new(StandardError) + + db.connect do |conn| + expect { conn.transaction { raise exception_class } }.to raise_error(exception_class) + end + end + end + end end