@@ -828,10 +828,52 @@ fn build_default_impl_fn<'a>(
828828 )
829829}
830830
831+ #[ test]
832+ fn test_build_default_impl_fn ( ) {
833+ let fields = vec ! [
834+ StructField {
835+ name: String :: from( "id" ) ,
836+ column_name: String :: from( "id" ) ,
837+ base_type: String :: from( "i32" ) ,
838+ is_optional: false ,
839+ is_vec: false ,
840+ } ,
841+ StructField {
842+ name: String :: from( "title" ) ,
843+ column_name: String :: from( "title" ) ,
844+ base_type: String :: from( "String" ) ,
845+ is_optional: false ,
846+ is_vec: false ,
847+ } ,
848+ StructField {
849+ name: String :: from( "maybe_value" ) ,
850+ column_name: String :: from( "maybe_value" ) ,
851+ base_type: String :: from( "i64" ) ,
852+ is_optional: true ,
853+ is_vec: false ,
854+ } ,
855+ ] ;
856+
857+ let generated_code = build_default_impl_fn ( StructType :: Create , "CreateFake" , & fields) ;
858+
859+ let expected = r#"impl Default for CreateFake {
860+ fn default() -> Self {
861+ Self {
862+ id: 0,
863+ title: String::new(),
864+ maybe_value: None,
865+ }
866+ }
867+ }
868+ "# ;
869+
870+ assert_eq ! ( & generated_code, & expected) ;
871+ }
872+
831873/// Generate a full file for a given diesel table
832874pub fn generate_for_table ( table : & ParsedTableMacro , config : & GenerationConfig ) -> String {
833875 // early to ensure the table options are set for the current table
834- let table_options = config. table ( & table. name . to_string ( ) ) ;
876+ let table_options = config. table ( table. name . to_string ( ) . as_str ( ) ) ;
835877
836878 let mut ret_buffer = format ! ( "{FILE_SIGNATURE}\n \n " ) ;
837879
0 commit comments