MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / transaction_begin_out_of_scope

Function transaction_begin_out_of_scope

tests/transaction_tests.rs:100–137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99#[sea_orm_macros::test]
100pub async fn transaction_begin_out_of_scope() -> Result<(), DbErr> {
101 let ctx = TestContext::new("transaction_begin_out_of_scope_test").await;
102 create_tables(&ctx.db).await?;
103
104 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0);
105
106 {
107 // Transaction begin in this scope
108 let txn = ctx.db.begin().await?;
109
110 bakery::ActiveModel {
111 name: Set("SeaSide Bakery".to_owned()),
112 profit_margin: Set(10.4),
113 ..Default::default()
114 }
115 .save(&txn)
116 .await?;
117
118 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 1);
119
120 bakery::ActiveModel {
121 name: Set("Top Bakery".to_owned()),
122 profit_margin: Set(15.0),
123 ..Default::default()
124 }
125 .save(&txn)
126 .await?;
127
128 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 2);
129
130 // The scope ended and transaction is dropped without commit
131 }
132
133 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0);
134
135 ctx.delete().await;
136 Ok(())
137}
138
139#[sea_orm_macros::test]
140pub async fn transaction_begin_commit() -> Result<(), DbErr> {

Callers

nothing calls this directly

Calls 5

saveMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
beginMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected