Unit test DeriveIntoActiveModel
This commit is contained in:
parent
d5e95b0f8f
commit
760c439c83
@ -71,12 +71,12 @@ impl IntoActiveModel {
|
||||
let field_ident = field.ident.as_ref().unwrap();
|
||||
|
||||
quote!(
|
||||
::sea_orm::IntoActiveValue::<_>::into_active_value(self.#field_ident).into()
|
||||
sea_orm::IntoActiveValue::<_>::into_active_value(self.#field_ident).into()
|
||||
)
|
||||
});
|
||||
|
||||
quote!(
|
||||
impl ::sea_orm::IntoActiveModel<#active_model_ident> for #ident {
|
||||
impl sea_orm::IntoActiveModel<#active_model_ident> for #ident {
|
||||
fn into_active_model(self) -> #active_model_ident {
|
||||
#active_model_ident {
|
||||
#( #field_idents: #expanded_fields_into_active_model, )*
|
||||
|
@ -380,3 +380,41 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn test_derive_into_active_model_1() {
|
||||
use crate::entity::*;
|
||||
|
||||
mod my_fruit {
|
||||
pub use super::fruit::*;
|
||||
use crate as sea_orm;
|
||||
use crate::entity::prelude::*;
|
||||
|
||||
#[derive(DeriveIntoActiveModel)]
|
||||
pub struct NewFruit {
|
||||
// id is omitted
|
||||
pub name: String,
|
||||
// it is required as opposed to optional in Model
|
||||
pub cake_id: i32,
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
my_fruit::NewFruit {
|
||||
name: "Apple".to_owned(),
|
||||
cake_id: 1,
|
||||
}
|
||||
.into_active_model(),
|
||||
fruit::ActiveModel {
|
||||
id: Unset(None),
|
||||
name: Set("Apple".to_owned()),
|
||||
cake_id: Set(Some(1)),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub use crate::{
|
||||
#[cfg(feature = "macros")]
|
||||
pub use crate::{
|
||||
DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn, DeriveCustomColumn, DeriveEntity,
|
||||
DeriveEntityModel, DeriveModel, DerivePrimaryKey, DeriveRelation, DeriveIntoActiveModel
|
||||
DeriveEntityModel, DeriveIntoActiveModel, DeriveModel, DerivePrimaryKey, DeriveRelation,
|
||||
};
|
||||
|
||||
#[cfg(feature = "with-json")]
|
||||
|
@ -287,7 +287,8 @@ pub use schema::*;
|
||||
#[cfg(feature = "macros")]
|
||||
pub use sea_orm_macros::{
|
||||
DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn, DeriveCustomColumn, DeriveEntity,
|
||||
DeriveEntityModel, DeriveModel, DerivePrimaryKey, DeriveRelation, FromQueryResult, DeriveIntoActiveModel,
|
||||
DeriveEntityModel, DeriveIntoActiveModel, DeriveModel, DerivePrimaryKey, DeriveRelation,
|
||||
FromQueryResult,
|
||||
};
|
||||
|
||||
pub use sea_query;
|
||||
|
Loading…
x
Reference in New Issue
Block a user