♻️ Convierte initialize() y Application en async
`async_trait` se re-exporta desde `pagetop` y se añade al preludio; ya no es necesario declararlo como dependencia en las extensiones. `initialize()` es ahora verdaderamente `async` (con `.await`), y `Application::new()` y `prepare()` pasan también a ser funciones `async`.
This commit is contained in:
parent
54d5b3e53d
commit
8aa4372bdf
16 changed files with 159 additions and 107 deletions
|
|
@ -4,13 +4,13 @@ use pagetop::prelude::*;
|
|||
///
|
||||
/// Los tests de este módulo renderizan componentes directamente con `Context::default()`, por lo
|
||||
/// que sólo necesitan el subsistema de localización y las extensiones registradas, no un router.
|
||||
fn setup() {
|
||||
let _ = Application::new();
|
||||
async fn setup() {
|
||||
Application::new().await;
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_default_shows_only_pagetop_recognition() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
let mut p = PoweredBy::default();
|
||||
let html = p.render(&mut Context::default());
|
||||
|
|
@ -24,7 +24,7 @@ async fn poweredby_default_shows_only_pagetop_recognition() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_new_includes_current_year_and_app_name() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
let mut p = PoweredBy::new();
|
||||
let html = p.render(&mut Context::default());
|
||||
|
|
@ -48,7 +48,7 @@ async fn poweredby_new_includes_current_year_and_app_name() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_with_copyright_overrides_text() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
let custom = "2001 © FooBar Inc.";
|
||||
let mut p = PoweredBy::default().with_copyright(Some(custom));
|
||||
|
|
@ -60,7 +60,7 @@ async fn poweredby_with_copyright_overrides_text() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_with_copyright_none_hides_text() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
let mut p = PoweredBy::new().with_copyright(None::<String>);
|
||||
let html = p.render(&mut Context::default());
|
||||
|
|
@ -72,7 +72,7 @@ async fn poweredby_with_copyright_none_hides_text() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_link_points_to_crates_io() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
let mut p = PoweredBy::default();
|
||||
let html = p.render(&mut Context::default());
|
||||
|
|
@ -85,7 +85,7 @@ async fn poweredby_link_points_to_crates_io() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn poweredby_getter_reflects_internal_state() {
|
||||
setup();
|
||||
setup().await;
|
||||
|
||||
// Por defecto no hay copyright.
|
||||
let p0 = PoweredBy::default();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
async fn setup() {
|
||||
Application::new().await;
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn literal_text() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::n("© 2025 PageTop");
|
||||
assert_eq!(l10n.get(), Some("© 2025 PageTop".to_string()));
|
||||
|
|
@ -10,7 +14,7 @@ async fn literal_text() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn translation_without_args() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_world");
|
||||
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
||||
|
|
@ -19,7 +23,7 @@ async fn translation_without_args() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn translation_with_args() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_user").with_arg("userName", "Manuel");
|
||||
let translation = l10n.lookup(&Locale::resolve("es-ES"));
|
||||
|
|
@ -28,7 +32,7 @@ async fn translation_with_args() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn translation_with_plural_and_select() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_shared_photos").with_args(vec![
|
||||
("userName", "Roberto"),
|
||||
|
|
@ -41,7 +45,7 @@ async fn translation_with_plural_and_select() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn check_fallback_language() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("test_hello_world");
|
||||
let translation = l10n.lookup(&Locale::resolve("xx-YY")); // Retrocede a "en-US".
|
||||
|
|
@ -50,7 +54,7 @@ async fn check_fallback_language() {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn check_unknown_key() {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let l10n = L10n::l("non-existent-key");
|
||||
let translation = l10n.lookup(&Locale::resolve("en-US"));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
#[pagetop::test]
|
||||
async fn homepage_returns_404() {
|
||||
let app = web::test::init_router(Application::new().test());
|
||||
let app = web::test::init_router(Application::new().await.test());
|
||||
|
||||
let req = web::test::TestRequest::get().uri("/").to_request();
|
||||
let resp = web::test::send_request(&app, req).await;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ use pagetop::prelude::*;
|
|||
use std::{borrow::Cow, fs, io};
|
||||
use tempfile::TempDir;
|
||||
|
||||
async fn setup() {
|
||||
Application::new().await;
|
||||
}
|
||||
|
||||
// **< Testing normalize_ascii() >******************************************************************
|
||||
|
||||
fn assert_err(input: &str, expected: util::NormalizeAsciiError) {
|
||||
|
|
@ -265,7 +269,7 @@ mod unix {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn ok_absolute_dir() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
// /tmp/<rand>/sub
|
||||
let td = TempDir::new()?;
|
||||
|
|
@ -279,7 +283,7 @@ mod unix {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn ok_relative_dir_with_manifest() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let td = TempDir::new()?;
|
||||
let sub = td.path().join("sub");
|
||||
|
|
@ -293,7 +297,7 @@ mod unix {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn error_not_a_directory() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let td = TempDir::new()?;
|
||||
let file = td.path().join("foo.txt");
|
||||
|
|
@ -311,7 +315,7 @@ mod windows {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn ok_absolute_dir() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
// C:\Users\...\Temp\...
|
||||
let td = TempDir::new()?;
|
||||
|
|
@ -325,7 +329,7 @@ mod windows {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn ok_relative_dir_with_manifest() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let td = TempDir::new()?;
|
||||
let sub = td.path().join("sub");
|
||||
|
|
@ -339,7 +343,7 @@ mod windows {
|
|||
|
||||
#[pagetop::test]
|
||||
async fn error_not_a_directory() -> io::Result<()> {
|
||||
let _app = web::test::init_router(Application::new().test());
|
||||
setup().await;
|
||||
|
||||
let td = TempDir::new()?;
|
||||
let file = td.path().join("foo.txt");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue