Add proc macro to implement models
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
		
							
								
								
									
										31
									
								
								heromodels/heromodels-derive/tests/test_model_macro.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								heromodels/heromodels-derive/tests/test_model_macro.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
use heromodels::model;
 | 
			
		||||
use heromodels::models::core::model::{BaseModelData, Model, Index};
 | 
			
		||||
 | 
			
		||||
#[model]
 | 
			
		||||
struct TestUser {
 | 
			
		||||
    base_data: BaseModelData,
 | 
			
		||||
    
 | 
			
		||||
    #[index]
 | 
			
		||||
    username: String,
 | 
			
		||||
    
 | 
			
		||||
    #[index]
 | 
			
		||||
    is_active: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_basic_model() {
 | 
			
		||||
    assert_eq!(TestUser::db_prefix(), "test_user");
 | 
			
		||||
    
 | 
			
		||||
    let user = TestUser {
 | 
			
		||||
        base_data: BaseModelData::new(1),
 | 
			
		||||
        username: "test".to_string(),
 | 
			
		||||
        is_active: true,
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    let keys = user.db_keys();
 | 
			
		||||
    assert_eq!(keys.len(), 2);
 | 
			
		||||
    assert_eq!(keys[0].name, "username");
 | 
			
		||||
    assert_eq!(keys[0].value, "test");
 | 
			
		||||
    assert_eq!(keys[1].name, "is_active");
 | 
			
		||||
    assert_eq!(keys[1].value, "true");
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user