Skip to content

Commit 846de4d

Browse files
committed
Fix lint
1 parent edff876 commit 846de4d

7 files changed

Lines changed: 55 additions & 18 deletions

File tree

crates/vespera_macro/src/schema_macro/circular.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,13 @@ mod tests {
412412

413413
#[test]
414414
fn test_is_circular_relation_required_invalid_struct() {
415-
assert!(!analyze_circular_refs(&[], "not valid rust")
416-
.circular_field_required
417-
.get("user")
418-
.copied()
419-
.unwrap_or(false));
415+
assert!(
416+
!analyze_circular_refs(&[], "not valid rust")
417+
.circular_field_required
418+
.get("user")
419+
.copied()
420+
.unwrap_or(false)
421+
);
420422
}
421423

422424
#[test]
@@ -436,11 +438,13 @@ mod tests {
436438
pub id: i32,
437439
pub name: String,
438440
}";
439-
assert!(!analyze_circular_refs(&[], model_def)
440-
.circular_field_required
441-
.get("nonexistent")
442-
.copied()
443-
.unwrap_or(false));
441+
assert!(
442+
!analyze_circular_refs(&[], model_def)
443+
.circular_field_required
444+
.get("nonexistent")
445+
.copied()
446+
.unwrap_or(false)
447+
);
444448
}
445449

446450
#[test]

crates/vespera_macro/src/schema_macro/inline_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use quote::quote;
99
use super::{
1010
circular::analyze_circular_refs,
1111
file_lookup::find_model_from_schema_path,
12-
seaorm::{convert_type_with_chrono, RelationFieldInfo},
12+
seaorm::{RelationFieldInfo, convert_type_with_chrono},
1313
type_utils::{
1414
extract_module_path_from_schema_path, is_seaorm_relation_type, snake_to_pascal_case,
1515
},

crates/vespera_macro/src/schema_macro/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ fn sql_function_default_body(original_ty: &syn::Type) -> Option<TokenStream> {
726726

727727
match type_name.as_str() {
728728
// Types implementing Default (returns zero/empty values)
729-
"i8" | "i16" | "i32" | "i64" | "i128" | "isize" | "u8" | "u16" | "u32" | "u64"
730-
| "u128" | "usize" | "f32" | "f64" | "bool" | "String" | "Decimal" | "Uuid" => {
729+
"i8" | "i16" | "i32" | "i64" | "i128" | "isize" | "u8" | "u16" | "u32" | "u64" | "u128"
730+
| "usize" | "f32" | "f64" | "bool" | "String" | "Decimal" | "Uuid" => {
731731
Some(quote! { Default::default() })
732732
}
733733
// SeaORM datetime types → chrono epoch

crates/vespera_macro/src/schema_macro/tests.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn test_sea_orm_default_attrs_no_default_value() {
311311
}
312312

313313
#[test]
314-
fn test_sea_orm_default_attrs_sql_function_skips() {
314+
fn test_sea_orm_default_attrs_sql_function_supported_type() {
315315
let attrs: Vec<syn::Attribute> = vec![syn::parse_quote!(#[sea_orm(default_value = "NOW()")])];
316316
let struct_name = syn::Ident::new("Test", proc_macro2::Span::call_site());
317317
let ty: syn::Type = syn::parse_str("String").unwrap();
@@ -325,8 +325,42 @@ fn test_sea_orm_default_attrs_sql_function_skips() {
325325
false,
326326
&mut fns,
327327
);
328+
// Supported type with SQL function → generates serde(default) to mark field not-required
329+
let serde_str = serde.to_string();
330+
assert!(
331+
serde_str.contains("serde"),
332+
"should have serde default attr: {serde_str}"
333+
);
334+
assert!(
335+
serde_str.contains("default_Test_created_at"),
336+
"should reference generated default fn: {serde_str}"
337+
);
338+
// No JSON default for SQL functions (value is DB-side only)
339+
assert!(schema.is_empty());
340+
// Default function was generated
341+
assert_eq!(fns.len(), 1, "should generate one default function");
342+
}
343+
344+
#[test]
345+
fn test_sea_orm_default_attrs_sql_function_unsupported_type_skips() {
346+
let attrs: Vec<syn::Attribute> =
347+
vec![syn::parse_quote!(#[sea_orm(default_value = "MY_FUNC()")])];
348+
let struct_name = syn::Ident::new("Test", proc_macro2::Span::call_site());
349+
let ty: syn::Type = syn::parse_str("MyCustomType").unwrap();
350+
let mut fns = Vec::new();
351+
let (serde, schema) = generate_sea_orm_default_attrs(
352+
&attrs,
353+
&struct_name,
354+
"custom_field",
355+
&ty,
356+
&ty,
357+
false,
358+
&mut fns,
359+
);
360+
// Unsupported type with SQL function → still skips entirely
328361
assert!(serde.is_empty());
329362
assert!(schema.is_empty());
363+
assert!(fns.is_empty());
330364
}
331365

332366
#[test]

examples/axum-example/src/models/memo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use sea_orm::entity::prelude::*;
22
use serde::{Deserialize, Serialize};
33

4-
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, vespera::Schema)]
4+
#[derive(
5+
Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, vespera::Schema,
6+
)]
57
#[serde(rename_all = "camelCase")]
68
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "memo_memo_status")]
79
pub enum MemoStatus {
@@ -35,7 +37,6 @@ pub struct Model {
3537
pub memo_comments: HasMany<super::memo_comment::Entity>,
3638
}
3739

38-
3940
// Index definitions (SeaORM uses Statement builders externally)
4041
// (unnamed) on [user_id]
4142
vespera::schema_type!(Schema from Model, name = "MemoSchema");

examples/axum-example/src/models/memo_comment.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub struct Model {
2121
pub memo: HasOne<super::memo::Entity>,
2222
}
2323

24-
2524
// Index definitions (SeaORM uses Statement builders externally)
2625
// (unnamed) on [user_id]
2726
// (unnamed) on [memo_id]

examples/axum-example/src/models/user.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub struct Model {
2525
pub memo_comments: HasMany<super::memo_comment::Entity>,
2626
}
2727

28-
2928
// Index definitions (SeaORM uses Statement builders externally)
3029
// (unnamed) on [email]
3130
vespera::schema_type!(Schema from Model, name = "UserSchema");

0 commit comments

Comments
 (0)