toasty_driver_integration_suite/tests/
missing_registrations.rs

1use crate::prelude::*;
2
3#[driver_test(id(ID))]
4pub async fn missing_registration_belongs_to(t: &mut Test) -> Result<()> {
5    #[derive(Debug, toasty::Model)]
6    struct Parent {
7        #[key]
8        #[auto]
9        id: ID,
10
11        child_id: ID,
12        #[belongs_to(key = child_id, references = id)]
13        child: toasty::BelongsTo<Child>,
14    }
15
16    #[derive(Debug, toasty::Model)]
17    struct Child {
18        #[key]
19        #[auto]
20        id: ID,
21    }
22
23    let error = t.try_setup_db(models!(Parent)).await.unwrap_err();
24    assert!(error.is_invalid_schema());
25    assert!(format!("{error}").contains("Parent::child"));
26
27    Ok(())
28}
29
30#[driver_test(id(ID))]
31pub async fn missing_registration_has_one(t: &mut Test) -> Result<()> {
32    #[derive(Debug, toasty::Model)]
33    struct Parent {
34        #[key]
35        #[auto]
36        id: ID,
37
38        #[has_one]
39        child: toasty::HasOne<Child>,
40    }
41
42    #[derive(Debug, toasty::Model)]
43    struct Child {
44        #[key]
45        #[auto]
46        id: ID,
47
48        parent_id: ID,
49        #[belongs_to(key = parent_id, references = id)]
50        parent: toasty::BelongsTo<Parent>,
51    }
52
53    let error = t.try_setup_db(models!(Parent)).await.unwrap_err();
54    assert!(error.is_invalid_schema());
55    assert!(format!("{error}").contains("Parent::child"));
56
57    Ok(())
58}
59
60#[driver_test(id(ID))]
61pub async fn missing_registration_has_many(t: &mut Test) -> Result<()> {
62    #[derive(Debug, toasty::Model)]
63    struct Parent {
64        #[key]
65        #[auto]
66        id: ID,
67
68        #[has_many]
69        children: toasty::HasMany<Child>,
70    }
71
72    #[derive(Debug, toasty::Model)]
73    struct Child {
74        #[key]
75        #[auto]
76        id: ID,
77
78        #[index]
79        parent_id: ID,
80        #[belongs_to(key = parent_id, references = id)]
81        parent: toasty::BelongsTo<Parent>,
82    }
83
84    let error = t.try_setup_db(models!(Parent)).await.unwrap_err();
85    assert!(error.is_invalid_schema());
86    assert!(format!("{error}").contains("Parent::child"));
87
88    Ok(())
89}
90
91#[driver_test(id(ID))]
92pub async fn missing_registration_embedded(t: &mut Test) -> Result<()> {
93    #[derive(Debug, toasty::Model)]
94    struct Parent {
95        #[key]
96        #[auto]
97        id: ID,
98
99        detail: Detail,
100    }
101
102    #[derive(Debug, toasty::Embed)]
103    struct Detail {
104        x: i32,
105    }
106
107    let error = t.try_setup_db(models!(Parent)).await.unwrap_err();
108    assert!(error.is_invalid_schema());
109    assert!(format!("{error}").contains("Parent::detail"));
110
111    Ok(())
112}