diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-06-16 07:44:06 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-06-16 08:44:28 +0200 |
commit | 5cdffd6e0e9eb0a408cec6e5a143231e139970fe (patch) | |
tree | a2c803de0fac66fa07f217878479fdb87143cb93 | |
parent | d4c13f5b4367fd3ca57fc14fdcf1d01694060c7a (diff) | |
download | askama-5cdffd6e0e9eb0a408cec6e5a143231e139970fe.tar.gz askama-5cdffd6e0e9eb0a408cec6e5a143231e139970fe.tar.bz2 askama-5cdffd6e0e9eb0a408cec6e5a143231e139970fe.zip |
Update to Rocket 0.5
Though Rocket 0.5 still only a release candidate, Rocket 0.4 severely
outdated, and depends on a bunch of crates with active security
advisories. Rocket 0.5 updates its dependencies to fixes versions.
Also Rocket 0.4 needs a nightly Rust, which caused multiple problems.
-rw-r--r-- | .github/workflows/rust.yml | 2 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 2 | ||||
-rw-r--r-- | askama_rocket/Cargo.toml | 5 | ||||
-rw-r--r-- | askama_rocket/src/lib.rs | 2 | ||||
-rw-r--r-- | askama_rocket/tests/basic.rs | 28 |
5 files changed, 22 insertions, 17 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 26ca174..6e4e4bc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -81,7 +81,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly + toolchain: stable override: true components: clippy - run: cargo test --package askama_rocket --all-targets diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index fdc9cae..142ff7f 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -506,7 +506,7 @@ impl<'a> Generator<'a> { let param = syn::GenericParam::Lifetime(syn::LifetimeDef::new(lifetime)); self.write_header( buf, - "::askama_rocket::Responder<'askama>", + "::askama_rocket::Responder<'askama, 'askama>", Some(vec![param]), )?; diff --git a/askama_rocket/Cargo.toml b/askama_rocket/Cargo.toml index bdace04..53a0953 100644 --- a/askama_rocket/Cargo.toml +++ b/askama_rocket/Cargo.toml @@ -14,7 +14,10 @@ edition = "2018" [dependencies] askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-rocket", "mime", "mime_guess"] } -rocket = { version = "0.4", default-features = false } +rocket = { version = "0.5.0-rc.2", default-features = false } + +[dev-dependencies] +futures-lite = "1.12.0" [features] default = ["askama/default"] diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs index f10ba87..fb231a4 100644 --- a/askama_rocket/src/lib.rs +++ b/askama_rocket/src/lib.rs @@ -14,6 +14,6 @@ pub fn respond<T: Template>(t: &T, _ext: &str) -> Result<'static> { let rsp = t.render().map_err(|_| Status::InternalServerError)?; Response::build() .header(Header::new("content-type", T::MIME_TYPE)) - .sized_body(Cursor::new(rsp)) + .sized_body(rsp.len(), Cursor::new(rsp)) .ok() } diff --git a/askama_rocket/tests/basic.rs b/askama_rocket/tests/basic.rs index 0671c4c..a61c188 100644 --- a/askama_rocket/tests/basic.rs +++ b/askama_rocket/tests/basic.rs @@ -1,12 +1,8 @@ -#![feature(proc_macro_hygiene, decl_macro)] - -#[macro_use] -extern crate rocket; - use askama::Template; +use futures_lite::future::block_on; use rocket::http::{ContentType, Status}; -use rocket::local::Client; +use rocket::local::asynchronous::Client; #[derive(Template)] #[template(path = "hello.html")] @@ -14,17 +10,23 @@ struct HelloTemplate<'a> { name: &'a str, } -#[get("/")] +#[rocket::get("/")] fn hello() -> HelloTemplate<'static> { HelloTemplate { name: "world" } } #[test] fn test_rocket() { - let rocket = rocket::ignite().mount("/", routes![hello]); - let client = Client::new(rocket).unwrap(); - let mut rsp = client.get("/").dispatch(); - assert_eq!(rsp.status(), Status::Ok); - assert_eq!(rsp.content_type(), Some(ContentType::HTML)); - assert_eq!(rsp.body_string().unwrap(), "Hello, world!"); + block_on(async { + let rocket = rocket::build() + .mount("/", rocket::routes![hello]) + .ignite() + .await + .unwrap(); + let client = Client::untracked(rocket).await.unwrap(); + let rsp = client.get("/").dispatch().await; + assert_eq!(rsp.status(), Status::Ok); + assert_eq!(rsp.content_type(), Some(ContentType::HTML)); + assert_eq!(rsp.into_string().await.as_deref(), Some("Hello, world!")); + }); } |