From 60ffe3d4ef9f14105ce777e9439c2ed5b2531a1a Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 23 Jan 2024 22:18:18 +0800 Subject: [PATCH] Drop the use of `rust_decimal_macros` --- Cargo.toml | 1 - tests/common/bakery_chain/cake.rs | 7 +++-- tests/common/setup/mod.rs | 5 ++++ tests/crud/create_cake.rs | 5 ++-- tests/crud/create_lineitem.rs | 9 +++---- tests/crud/create_order.rs | 11 ++++---- tests/crud/deletes.rs | 3 +-- tests/crud/error.rs | 3 +-- tests/crud/mod.rs | 1 + tests/crud/updates.rs | 5 ++-- tests/cursor_tests.rs | 2 +- tests/pi_tests.rs | 11 ++++---- tests/relational_tests.rs | 43 +++++++++++++++---------------- tests/sequential_op_tests.rs | 15 +++++------ tests/sql_err_tests.rs | 5 ++-- tests/transaction_tests.rs | 9 +++---- 16 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55487e5215..3407b61d13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,6 @@ futures = { version = "0.3" } tokio = { version = "1.6", features = ["full"] } actix-rt = { version = "2.2.0" } maplit = { version = "1" } -rust_decimal_macros = { version = "1" } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } sea-orm = { path = ".", features = ["mock", "debug-print", "tests-cfg", "postgres-array", "sea-orm-internal"] } pretty_assertions = { version = "0.7" } diff --git a/tests/common/bakery_chain/cake.rs b/tests/common/bakery_chain/cake.rs index 2fcd072f68..871035440f 100644 --- a/tests/common/bakery_chain/cake.rs +++ b/tests/common/bakery_chain/cake.rs @@ -1,3 +1,4 @@ +use crate::common::setup::rust_dec; use sea_orm::{entity::prelude::*, ConnectionTrait}; #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] @@ -63,8 +64,7 @@ impl ActiveModelBehavior for ActiveModel { where C: ConnectionTrait, { - use rust_decimal_macros::dec; - if self.price.as_ref() == &dec!(0) { + if self.price.as_ref() == &rust_dec(0) { Err(DbErr::Custom(format!( "[before_save] Invalid Price, insert: {insert}" ))) @@ -77,8 +77,7 @@ impl ActiveModelBehavior for ActiveModel { where C: ConnectionTrait, { - use rust_decimal_macros::dec; - if model.price < dec!(0) { + if model.price < rust_dec(0) { Err(DbErr::Custom(format!( "[after_save] Invalid Price, insert: {insert}" ))) diff --git a/tests/common/setup/mod.rs b/tests/common/setup/mod.rs index 2385cfb0c4..c0a91b9976 100644 --- a/tests/common/setup/mod.rs +++ b/tests/common/setup/mod.rs @@ -158,3 +158,8 @@ pub async fn create_table_without_asserts( } db.execute(builder.build(create)).await } + +pub fn rust_dec(v: T) -> rust_decimal::Decimal { + use std::str::FromStr; + rust_decimal::Decimal::from_str(&v.to_string()).unwrap() +} diff --git a/tests/crud/create_cake.rs b/tests/crud/create_cake.rs index b205e9c84c..2e5577f3d0 100644 --- a/tests/crud/create_cake.rs +++ b/tests/crud/create_cake.rs @@ -1,5 +1,4 @@ pub use super::*; -use rust_decimal_macros::dec; use uuid::Uuid; pub async fn test_create_cake(db: &DbConn) { @@ -31,7 +30,7 @@ pub async fn test_create_cake(db: &DbConn) { let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(-10.25)), + price: Set(rust_dec(-10.25)), gluten_free: Set(false), serial: Set(uuid), bakery_id: Set(Some(bakery_insert_res.last_insert_id)), @@ -64,7 +63,7 @@ pub async fn test_create_cake(db: &DbConn) { assert!(cake.is_some()); let cake_model = cake.unwrap(); assert_eq!(cake_model.name, "Mud Cake"); - assert_eq!(cake_model.price, dec!(-10.25)); + assert_eq!(cake_model.price, rust_dec(-10.25)); assert!(!cake_model.gluten_free); assert_eq!( cake_model diff --git a/tests/crud/create_lineitem.rs b/tests/crud/create_lineitem.rs index fa569a53fa..cb4c0f1fad 100644 --- a/tests/crud/create_lineitem.rs +++ b/tests/crud/create_lineitem.rs @@ -1,6 +1,5 @@ pub use super::*; use chrono::offset::Utc; -use rust_decimal_macros::dec; use uuid::Uuid; pub async fn test_create_lineitem(db: &DbConn) { @@ -34,7 +33,7 @@ pub async fn test_create_lineitem(db: &DbConn) { // Cake let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(bakery_insert_res.last_insert_id)), @@ -75,7 +74,7 @@ pub async fn test_create_lineitem(db: &DbConn) { let order_1 = order::ActiveModel { bakery_id: Set(bakery_insert_res.last_insert_id), customer_id: Set(customer_insert_res.last_insert_id), - total: Set(dec!(7.55)), + total: Set(rust_dec(7.55)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -88,7 +87,7 @@ pub async fn test_create_lineitem(db: &DbConn) { let lineitem_1 = lineitem::ActiveModel { cake_id: Set(cake_insert_res.last_insert_id), order_id: Set(order_insert_res.last_insert_id), - price: Set(dec!(7.55)), + price: Set(rust_dec(7.55)), quantity: Set(1), ..Default::default() }; @@ -106,7 +105,7 @@ pub async fn test_create_lineitem(db: &DbConn) { assert!(lineitem.is_some()); let lineitem_model = lineitem.unwrap(); - assert_eq!(lineitem_model.price, dec!(7.55)); + assert_eq!(lineitem_model.price, rust_dec(7.55)); let cake: Option = Cake::find_by_id(lineitem_model.cake_id) .one(db) diff --git a/tests/crud/create_order.rs b/tests/crud/create_order.rs index 950cba50c7..a80550ca79 100644 --- a/tests/crud/create_order.rs +++ b/tests/crud/create_order.rs @@ -1,6 +1,5 @@ pub use super::*; use chrono::offset::Utc; -use rust_decimal_macros::dec; use uuid::Uuid; pub async fn test_create_order(db: &DbConn) { @@ -34,7 +33,7 @@ pub async fn test_create_order(db: &DbConn) { // Cake let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(bakery_insert_res.last_insert_id)), @@ -75,7 +74,7 @@ pub async fn test_create_order(db: &DbConn) { let order_1 = order::ActiveModel { bakery_id: Set(bakery_insert_res.last_insert_id), customer_id: Set(customer_insert_res.last_insert_id), - total: Set(dec!(15.10)), + total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -88,7 +87,7 @@ pub async fn test_create_order(db: &DbConn) { let lineitem_1 = lineitem::ActiveModel { cake_id: Set(cake_insert_res.last_insert_id), order_id: Set(order_insert_res.last_insert_id), - price: Set(dec!(7.55)), + price: Set(rust_dec(7.55)), quantity: Set(2), ..Default::default() }; @@ -104,7 +103,7 @@ pub async fn test_create_order(db: &DbConn) { assert!(order.is_some()); let order_model = order.unwrap(); - assert_eq!(order_model.total, dec!(15.10)); + assert_eq!(order_model.total, rust_dec(15.10)); let customer: Option = Customer::find_by_id(order_model.customer_id) .one(db) @@ -128,6 +127,6 @@ pub async fn test_create_order(db: &DbConn) { .await .expect("could not find related lineitems"); assert_eq!(related_lineitems.len(), 1); - assert_eq!(related_lineitems[0].price, dec!(7.55)); + assert_eq!(related_lineitems[0].price, rust_dec(7.55)); assert_eq!(related_lineitems[0].quantity, 2); } diff --git a/tests/crud/deletes.rs b/tests/crud/deletes.rs index 70c18901f5..aa4722a6cc 100644 --- a/tests/crud/deletes.rs +++ b/tests/crud/deletes.rs @@ -1,5 +1,4 @@ pub use super::*; -use rust_decimal_macros::dec; use uuid::Uuid; pub async fn test_delete_cake(db: &DbConn) { @@ -17,7 +16,7 @@ pub async fn test_delete_cake(db: &DbConn) { let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(bakery_insert_res.last_insert_id)), diff --git a/tests/crud/error.rs b/tests/crud/error.rs index 07bb510093..9e05c7860c 100644 --- a/tests/crud/error.rs +++ b/tests/crud/error.rs @@ -1,5 +1,4 @@ pub use super::*; -use rust_decimal_macros::dec; use sea_orm::error::*; #[cfg(any( feature = "sqlx-mysql", @@ -12,7 +11,7 @@ use uuid::Uuid; pub async fn test_cake_error_sqlx(db: &DbConn) { let mud_cake = cake::ActiveModel { name: Set("Moldy Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(None), diff --git a/tests/crud/mod.rs b/tests/crud/mod.rs index 3a629d7acf..d1f0f1b9f5 100644 --- a/tests/crud/mod.rs +++ b/tests/crud/mod.rs @@ -15,6 +15,7 @@ pub use error::*; pub use updates::*; pub use super::common::bakery_chain::*; +pub use crate::common::setup::rust_dec; use sea_orm::{entity::*, DbConn}; pub async fn test_create_bakery(db: &DbConn) { diff --git a/tests/crud/updates.rs b/tests/crud/updates.rs index c5abeb65b6..082b8a747b 100644 --- a/tests/crud/updates.rs +++ b/tests/crud/updates.rs @@ -1,5 +1,4 @@ pub use super::*; -use rust_decimal_macros::dec; use sea_orm::{query::*, DbErr}; use uuid::Uuid; @@ -16,7 +15,7 @@ pub async fn test_update_cake(db: &DbConn) { let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(bakery_insert_res.last_insert_id)), @@ -36,7 +35,7 @@ pub async fn test_update_cake(db: &DbConn) { assert!(cake.is_some()); let cake_model = cake.unwrap(); assert_eq!(cake_model.name, "Mud Cake"); - assert_eq!(cake_model.price, dec!(10.25)); + assert_eq!(cake_model.price, rust_dec(10.25)); assert!(!cake_model.gluten_free); let large_number = (u64::MAX as u128 + 1).to_string().parse().unwrap(); diff --git a/tests/cursor_tests.rs b/tests/cursor_tests.rs index e843086894..0d1d54eb78 100644 --- a/tests/cursor_tests.rs +++ b/tests/cursor_tests.rs @@ -579,7 +579,7 @@ pub async fn create_baker_cake(db: &DatabaseConnection) -> Result<(), DbErr> { }); cakes.push(cake::ActiveModel { name: Set(c.to_ascii_lowercase().to_string()), - price: Set(rust_decimal_macros::dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some((c as i32 - 65) % 10 + 1)), diff --git a/tests/pi_tests.rs b/tests/pi_tests.rs index 0d344ceee8..31f3b794b2 100644 --- a/tests/pi_tests.rs +++ b/tests/pi_tests.rs @@ -1,8 +1,7 @@ pub mod common; -use common::{features::*, TestContext}; +use common::{features::*, setup::*, TestContext}; use pretty_assertions::assert_eq; -use rust_decimal_macros::dec; use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection}; use std::str::FromStr; @@ -24,7 +23,7 @@ async fn main() -> Result<(), DbErr> { pub async fn create_and_update_pi(db: &DatabaseConnection) -> Result<(), DbErr> { let pi = pi::Model { id: 1, - decimal: dec!(3.1415926536), + decimal: rust_dec(3.1415926536), big_decimal: BigDecimal::from_str("3.1415926536").unwrap(), decimal_opt: None, big_decimal_opt: None, @@ -37,7 +36,7 @@ pub async fn create_and_update_pi(db: &DatabaseConnection) -> Result<(), DbErr> assert_eq!(model, Some(pi.clone())); let res = pi::ActiveModel { - decimal_opt: Set(Some(dec!(3.1415926536))), + decimal_opt: Set(Some(rust_dec(3.1415926536))), big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())), ..pi.clone().into_active_model() } @@ -50,9 +49,9 @@ pub async fn create_and_update_pi(db: &DatabaseConnection) -> Result<(), DbErr> model, Some(pi::Model { id: 1, - decimal: dec!(3.1415926536), + decimal: rust_dec(3.1415926536), big_decimal: BigDecimal::from_str("3.1415926536").unwrap(), - decimal_opt: Some(dec!(3.1415926536)), + decimal_opt: Some(rust_dec(3.1415926536)), big_decimal_opt: Some(BigDecimal::from_str("3.1415926536").unwrap()), }) ); diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 9e643c449c..0ac1d41f73 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -4,7 +4,6 @@ pub use chrono::offset::Utc; pub use common::{bakery_chain::*, setup::*, TestContext}; use pretty_assertions::assert_eq; pub use rust_decimal::prelude::*; -pub use rust_decimal_macros::dec; use sea_orm::{entity::*, query::*, DbErr, DerivePartialModel, FromQueryResult}; use sea_query::{Alias, Expr, Func, SimpleExpr}; pub use uuid::Uuid; @@ -151,7 +150,7 @@ pub async fn right_join() { let _order = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(15.10)), + total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -180,7 +179,7 @@ pub async fn right_join() { .await .unwrap() .unwrap(); - assert_eq!(result.order_total, Some(dec!(15.10))); + assert_eq!(result.order_total, Some(rust_dec(15.10))); let select = order::Entity::find() .right_join(customer::Entity) @@ -238,7 +237,7 @@ pub async fn inner_join() { let kate_order_1 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(15.10)), + total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -250,7 +249,7 @@ pub async fn inner_join() { let kate_order_2 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(100.00)), + total: Set(rust_dec(100.00)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -320,7 +319,7 @@ pub async fn group_by() { let kate_order_1 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(99.95)), + total: Set(rust_dec(99.95)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -332,7 +331,7 @@ pub async fn group_by() { let kate_order_2 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(200.00)), + total: Set(rust_dec(200.00)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -441,7 +440,7 @@ pub async fn having() { let kate_order_1 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(100.00)), + total: Set(rust_dec(100.00)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -453,7 +452,7 @@ pub async fn having() { let _kate_order_2 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_kate.id), - total: Set(dec!(12.00)), + total: Set(rust_dec(12.00)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -473,7 +472,7 @@ pub async fn having() { let _bob_order_1 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_bob.id), - total: Set(dec!(50.0)), + total: Set(rust_dec(50.0)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -485,7 +484,7 @@ pub async fn having() { let _bob_order_2 = order::ActiveModel { bakery_id: Set(bakery.id), customer_id: Set(customer_bob.id), - total: Set(dec!(50.0)), + total: Set(rust_dec(50.0)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -812,7 +811,7 @@ pub async fn linked() -> Result<(), DbErr> { let baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?; let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), @@ -837,7 +836,7 @@ pub async fn linked() -> Result<(), DbErr> { let baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?; let cheese_cake = cake::ActiveModel { name: Set("Cheese Cake".to_owned()), - price: Set(dec!(20.5)), + price: Set(rust_dec(20.5)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), @@ -853,7 +852,7 @@ pub async fn linked() -> Result<(), DbErr> { .await?; let chocolate_cake = cake::ActiveModel { name: Set("Chocolate Cake".to_owned()), - price: Set(dec!(30.15)), + price: Set(rust_dec(30.15)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), @@ -889,7 +888,7 @@ pub async fn linked() -> Result<(), DbErr> { let kate_order_1 = order::ActiveModel { bakery_id: Set(seaside_bakery_res.last_insert_id), customer_id: Set(customer_kate_res.last_insert_id), - total: Set(dec!(15.10)), + total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -897,7 +896,7 @@ pub async fn linked() -> Result<(), DbErr> { lineitem::ActiveModel { cake_id: Set(cheese_cake_res.last_insert_id), order_id: Set(kate_order_1_res.last_insert_id), - price: Set(dec!(7.55)), + price: Set(rust_dec(7.55)), quantity: Set(2), ..Default::default() } @@ -906,7 +905,7 @@ pub async fn linked() -> Result<(), DbErr> { let kate_order_2 = order::ActiveModel { bakery_id: Set(seaside_bakery_res.last_insert_id), customer_id: Set(customer_kate_res.last_insert_id), - total: Set(dec!(29.7)), + total: Set(rust_dec(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -914,7 +913,7 @@ pub async fn linked() -> Result<(), DbErr> { lineitem::ActiveModel { cake_id: Set(chocolate_cake_res.last_insert_id), order_id: Set(kate_order_2_res.last_insert_id), - price: Set(dec!(9.9)), + price: Set(rust_dec(9.9)), quantity: Set(3), ..Default::default() } @@ -931,7 +930,7 @@ pub async fn linked() -> Result<(), DbErr> { let kara_order_1 = order::ActiveModel { bakery_id: Set(seaside_bakery_res.last_insert_id), customer_id: Set(customer_kara_res.last_insert_id), - total: Set(dec!(15.10)), + total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -939,7 +938,7 @@ pub async fn linked() -> Result<(), DbErr> { lineitem::ActiveModel { cake_id: Set(mud_cake_res.last_insert_id), order_id: Set(kara_order_1_res.last_insert_id), - price: Set(dec!(7.55)), + price: Set(rust_dec(7.55)), quantity: Set(2), ..Default::default() } @@ -948,7 +947,7 @@ pub async fn linked() -> Result<(), DbErr> { let kara_order_2 = order::ActiveModel { bakery_id: Set(seaside_bakery_res.last_insert_id), customer_id: Set(customer_kara_res.last_insert_id), - total: Set(dec!(29.7)), + total: Set(rust_dec(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; @@ -956,7 +955,7 @@ pub async fn linked() -> Result<(), DbErr> { lineitem::ActiveModel { cake_id: Set(cheese_cake_res.last_insert_id), order_id: Set(kara_order_2_res.last_insert_id), - price: Set(dec!(9.9)), + price: Set(rust_dec(9.9)), quantity: Set(3), ..Default::default() } diff --git a/tests/sequential_op_tests.rs b/tests/sequential_op_tests.rs index 208b388c6e..d84f6bfed5 100644 --- a/tests/sequential_op_tests.rs +++ b/tests/sequential_op_tests.rs @@ -3,7 +3,6 @@ pub mod common; pub use chrono::offset::Utc; pub use common::{bakery_chain::*, setup::*, TestContext}; pub use rust_decimal::prelude::*; -pub use rust_decimal_macros::dec; pub use uuid::Uuid; #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] @@ -63,7 +62,7 @@ async fn seed_data(db: &DatabaseConnection) { let mud_cake = cake::ActiveModel { name: Set("Mud Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(bakery.id.clone().unwrap())), @@ -100,7 +99,7 @@ async fn seed_data(db: &DatabaseConnection) { let kate_order_1 = order::ActiveModel { bakery_id: Set(bakery.id.clone().unwrap()), customer_id: Set(customer_kate.id.clone().unwrap()), - total: Set(dec!(99.95)), + total: Set(rust_dec(99.95)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -111,7 +110,7 @@ async fn seed_data(db: &DatabaseConnection) { let _lineitem = lineitem::ActiveModel { cake_id: Set(cake_insert_res.last_insert_id), - price: Set(dec!(10.00)), + price: Set(rust_dec(10.00)), quantity: Set(12), order_id: Set(kate_order_1.id.clone().unwrap()), ..Default::default() @@ -122,7 +121,7 @@ async fn seed_data(db: &DatabaseConnection) { let _lineitem2 = lineitem::ActiveModel { cake_id: Set(cake_insert_res.last_insert_id), - price: Set(dec!(50.00)), + price: Set(rust_dec(50.00)), quantity: Set(2), order_id: Set(kate_order_1.id.clone().unwrap()), ..Default::default() @@ -199,7 +198,7 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option { let new_cake = cake::ActiveModel { name: Set("New Cake".to_owned()), - price: Set(dec!(8.00)), + price: Set(rust_dec(8.00)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(baker.bakery_id.unwrap())), @@ -244,7 +243,7 @@ async fn create_order(db: &DatabaseConnection, cake: cake::Model) { let order = order::ActiveModel { bakery_id: Set(cake.bakery_id.unwrap()), customer_id: Set(another_customer.id.clone().unwrap()), - total: Set(dec!(200.00)), + total: Set(rust_dec(200.00)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() @@ -255,7 +254,7 @@ async fn create_order(db: &DatabaseConnection, cake: cake::Model) { let _lineitem = lineitem::ActiveModel { cake_id: Set(cake.id), - price: Set(dec!(10.00)), + price: Set(rust_dec(10.00)), quantity: Set(300), order_id: Set(order.id.clone().unwrap()), ..Default::default() diff --git a/tests/sql_err_tests.rs b/tests/sql_err_tests.rs index e086d730c2..4f032a4867 100644 --- a/tests/sql_err_tests.rs +++ b/tests/sql_err_tests.rs @@ -1,6 +1,5 @@ pub mod common; pub use common::{bakery_chain::*, setup::*, TestContext}; -use rust_decimal_macros::dec; pub use sea_orm::{ entity::*, error::DbErr, error::SqlErr, tests_cfg, DatabaseConnection, DbBackend, EntityName, ExecResult, @@ -23,7 +22,7 @@ async fn main() { pub async fn test_error(db: &DatabaseConnection) { let mud_cake = cake::ActiveModel { name: Set("Moldy Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(None), @@ -48,7 +47,7 @@ pub async fn test_error(db: &DatabaseConnection) { let fk_cake = cake::ActiveModel { name: Set("fk error Cake".to_owned()), - price: Set(dec!(10.25)), + price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), bakery_id: Set(Some(1000)), diff --git a/tests/transaction_tests.rs b/tests/transaction_tests.rs index ffc937a6d7..fea3951897 100644 --- a/tests/transaction_tests.rs +++ b/tests/transaction_tests.rs @@ -358,7 +358,6 @@ pub async fn transaction_closure_rollback() -> Result<(), DbErr> { feature = "sqlx-postgres" ))] pub async fn transaction_with_active_model_behaviour() -> Result<(), DbErr> { - use rust_decimal_macros::dec; let ctx = TestContext::new("transaction_with_active_model_behaviour_test").await; create_tables(&ctx.db).await?; @@ -366,7 +365,7 @@ pub async fn transaction_with_active_model_behaviour() -> Result<(), DbErr> { assert_eq!( cake::ActiveModel { name: Set("Cake with invalid price".to_owned()), - price: Set(dec!(0)), + price: Set(rust_dec(0)), gluten_free: Set(false), ..Default::default() } @@ -382,7 +381,7 @@ pub async fn transaction_with_active_model_behaviour() -> Result<(), DbErr> { assert_eq!( cake::ActiveModel { name: Set("Cake with invalid price".to_owned()), - price: Set(dec!(-10)), + price: Set(rust_dec(-10)), gluten_free: Set(false), ..Default::default() } @@ -397,7 +396,7 @@ pub async fn transaction_with_active_model_behaviour() -> Result<(), DbErr> { let readonly_cake_1 = cake::ActiveModel { name: Set("Readonly cake (err_on_before_delete)".to_owned()), - price: Set(dec!(10)), + price: Set(rust_dec(10)), gluten_free: Set(true), ..Default::default() } @@ -417,7 +416,7 @@ pub async fn transaction_with_active_model_behaviour() -> Result<(), DbErr> { let readonly_cake_2 = cake::ActiveModel { name: Set("Readonly cake (err_on_after_delete)".to_owned()), - price: Set(dec!(10)), + price: Set(rust_dec(10)), gluten_free: Set(true), ..Default::default() }