From b1b5f95c1db231fe41bb4a486991b884c58c9459 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Fri, 17 Sep 2021 22:21:54 +0800 Subject: [PATCH] Unit tests --- src/entity/base_entity.rs | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/entity/base_entity.rs b/src/entity/base_entity.rs index e09fa0a8..6f770162 100644 --- a/src/entity/base_entity.rs +++ b/src/entity/base_entity.rs @@ -541,3 +541,58 @@ pub trait EntityTrait: EntityName { Delete::many(Self::default()) } } + +#[cfg(test)] +mod tests { + #[test] + #[cfg(feature = "macros")] + fn entity_model_1() { + use crate::entity::*; + + mod hello { + use crate as sea_orm; + use crate::entity::prelude::*; + + #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] + #[sea_orm(table_name = "hello")] + pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + } + + #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] + pub enum Relation {} + + impl ActiveModelBehavior for ActiveModel {} + } + + assert_eq!(hello::Entity.table_name(), "hello"); + assert_eq!(hello::Entity.schema_name(), None); + } + + #[test] + #[cfg(feature = "macros")] + fn entity_model_2() { + use crate::entity::*; + + mod hello { + use crate as sea_orm; + use crate::entity::prelude::*; + + #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] + #[sea_orm(table_name = "hello", schema_name = "world")] + pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + } + + #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] + pub enum Relation {} + + impl ActiveModelBehavior for ActiveModel {} + } + + assert_eq!(hello::Entity.table_name(), "hello"); + assert_eq!(hello::Entity.schema_name(), Some("world")); + } +}