move macro import to lib.rs
This commit is contained in:
parent
0d03ce3d12
commit
5f02fb265a
3 changed files with 39 additions and 37 deletions
37
src/lib.rs
37
src/lib.rs
|
@ -18,6 +18,7 @@ mod util;
|
||||||
mod watches;
|
mod watches;
|
||||||
|
|
||||||
// things we want in the crate namespace
|
// things we want in the crate namespace
|
||||||
|
use optional_optional_user::OptionalOptionalUser;
|
||||||
use templates::*;
|
use templates::*;
|
||||||
use users::User;
|
use users::User;
|
||||||
use watches::{templates::*, ShowKind, Watch};
|
use watches::{templates::*, ShowKind, Watch};
|
||||||
|
@ -62,3 +63,39 @@ pub async fn app(db_pool: sqlx::SqlitePool, session_secret: &[u8]) -> axum::Rout
|
||||||
.layer(session_layer)
|
.layer(session_layer)
|
||||||
.with_state(db_pool)
|
.with_state(db_pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-************************************************************************
|
||||||
|
// tests for the proc macro for optional user
|
||||||
|
//-************************************************************************
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::{CreateUserSuccess, MainPage, OptionalOptionalUser, User};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn main_page_has_optional_user() {
|
||||||
|
assert!(MainPage::default().has_optional_user());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn signup_success_has_no_optional_user() {
|
||||||
|
assert!(!CreateUserSuccess::default().has_optional_user());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn user_is_not_optional() {
|
||||||
|
#[derive(Default, OptionalOptionalUser)]
|
||||||
|
struct TestThing {
|
||||||
|
user: User,
|
||||||
|
}
|
||||||
|
assert!(!TestThing::default().has_optional_user());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn user_is_not_user() {
|
||||||
|
#[derive(Default, OptionalOptionalUser)]
|
||||||
|
struct TestThing {
|
||||||
|
user: Option<bool>,
|
||||||
|
}
|
||||||
|
assert!(!TestThing::default().has_optional_user());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use optional_optional_user::OptionalOptionalUser;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::User;
|
use crate::{OptionalOptionalUser, User};
|
||||||
|
|
||||||
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
||||||
#[template(path = "signup.html")]
|
#[template(path = "signup.html")]
|
||||||
|
@ -47,36 +46,3 @@ pub struct LogoutPost;
|
||||||
pub struct MainPage {
|
pub struct MainPage {
|
||||||
pub user: Option<User>,
|
pub user: Option<User>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn main_page_has_optional_user() {
|
|
||||||
assert!(MainPage::default().has_optional_user());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn signup_success_has_no_optional_user() {
|
|
||||||
assert!(!CreateUserSuccess::default().has_optional_user());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn user_is_not_optional() {
|
|
||||||
#[derive(Default, OptionalOptionalUser)]
|
|
||||||
struct TestThing {
|
|
||||||
user: User,
|
|
||||||
}
|
|
||||||
assert!(!TestThing::default().has_optional_user());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn user_is_not_user() {
|
|
||||||
#[derive(Default, OptionalOptionalUser)]
|
|
||||||
struct TestThing {
|
|
||||||
user: Option<bool>,
|
|
||||||
}
|
|
||||||
assert!(!TestThing::default().has_optional_user());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use optional_optional_user::OptionalOptionalUser;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{User, Watch};
|
use crate::{OptionalOptionalUser, User, Watch};
|
||||||
|
|
||||||
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq, OptionalOptionalUser)]
|
||||||
#[template(path = "get_watches.html")]
|
#[template(path = "get_watches.html")]
|
||||||
|
|
Loading…
Reference in a new issue