Skip to content

Commit

Permalink
Adds gen_import_active_enum tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onefifth committed Nov 2, 2023
1 parent 34f212a commit 9ec8107
Showing 1 changed file with 127 additions and 1 deletion.
128 changes: 127 additions & 1 deletion sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ mod tests {
};
use pretty_assertions::assert_eq;
use proc_macro2::TokenStream;
use sea_query::{ColumnType, ForeignKeyAction, RcOrArc};
use quote::quote;
use sea_query::{Alias, ColumnType, ForeignKeyAction, RcOrArc, SeaRc};
use std::io::{self, BufRead, BufReader, Read};

fn setup() -> Vec<Entity> {
Expand Down Expand Up @@ -2283,4 +2284,129 @@ mod tests {

Ok(())
}

#[test]
fn test_gen_import_active_enum() -> io::Result<()> {
let entities = vec![
Entity {
table_name: "tea_pairing".to_owned(),
columns: vec![
Column {
name: "id".to_owned(),
col_type: ColumnType::Integer,
auto_increment: true,
not_null: true,
unique: false,
},
Column {
name: "first_tea".to_owned(),
col_type: ColumnType::Enum {
name: SeaRc::new(Alias::new("tea_enum")),
variants: vec![
SeaRc::new(Alias::new("everyday_tea")),
SeaRc::new(Alias::new("breakfast_tea")),
],
},
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "second_tea".to_owned(),
col_type: ColumnType::Enum {
name: SeaRc::new(Alias::new("tea_enum")),
variants: vec![
SeaRc::new(Alias::new("everyday_tea")),
SeaRc::new(Alias::new("breakfast_tea")),
],
},
auto_increment: false,
not_null: true,
unique: false,
},
],
relations: vec![],
conjunct_relations: vec![],
primary_keys: vec![PrimaryKey {
name: "id".to_owned(),
}],
},
Entity {
table_name: "tea_pairing_with_size".to_owned(),
columns: vec![
Column {
name: "id".to_owned(),
col_type: ColumnType::Integer,
auto_increment: true,
not_null: true,
unique: false,
},
Column {
name: "first_tea".to_owned(),
col_type: ColumnType::Enum {
name: SeaRc::new(Alias::new("tea_enum")),
variants: vec![
SeaRc::new(Alias::new("everyday_tea")),
SeaRc::new(Alias::new("breakfast_tea")),
],
},
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "second_tea".to_owned(),
col_type: ColumnType::Enum {
name: SeaRc::new(Alias::new("tea_enum")),
variants: vec![
SeaRc::new(Alias::new("everyday_tea")),
SeaRc::new(Alias::new("breakfast_tea")),
],
},
auto_increment: false,
not_null: true,
unique: false,
},
Column {
name: "size".to_owned(),
col_type: ColumnType::Enum {
name: SeaRc::new(Alias::new("tea_size")),
variants: vec![
SeaRc::new(Alias::new("small")),
SeaRc::new(Alias::new("medium")),
SeaRc::new(Alias::new("huge")),
],
},
auto_increment: false,
not_null: true,
unique: false,
},
],
relations: vec![],
conjunct_relations: vec![],
primary_keys: vec![PrimaryKey {
name: "id".to_owned(),
}],
},
];

assert_eq!(
quote!(
use super::sea_orm_active_enums::TeaEnum;
)
.to_string(),
EntityWriter::gen_import_active_enum(&entities[0]).to_string()
);

assert_eq!(
quote!(
use super::sea_orm_active_enums::TeaEnum;
use super::sea_orm_active_enums::TeaSize;
)
.to_string(),
EntityWriter::gen_import_active_enum(&entities[1]).to_string()
);

Ok(())
}
}

0 comments on commit 9ec8107

Please sign in to comment.