Skip to content

remove more unnecessary redirects in search-results, and i'm feeling-lucky #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ fn redirect_to_random_crate(req: &Request, conn: &mut PoolClient) -> IronResult<
let url = ctry!(
req,
Url::parse(&format!(
"{}/{}/{}/{}",
"{}/{}/{}/{}/",
redirect_base(req),
name,
version,
Expand Down Expand Up @@ -618,7 +618,7 @@ pub fn search_handler(req: &mut Request) -> IronResult<Response> {
let url = if rustdoc_status {
ctry!(
req,
Url::parse(&format!("{}/{}/{}", redirect_base(req), query, version)),
Url::parse(&format!("{}/{}/{}/", redirect_base(req), query, version)),
)
} else {
ctry!(
Expand Down Expand Up @@ -721,7 +721,7 @@ pub fn build_queue_handler(req: &mut Request) -> IronResult<Response> {
#[cfg(test)]
mod tests {
use super::*;
use crate::test::{assert_success, wrapper, TestFrontend};
use crate::test::{assert_redirect, assert_success, wrapper, TestFrontend};
use chrono::TimeZone;
use failure::Error;
use kuchiki::traits::TendrilSink;
Expand Down Expand Up @@ -1100,7 +1100,12 @@ mod tests {
.github_stats("some/repo", 333, 22, 11)
.name("some_random_crate")
.create()?;
assert_success("/releases/search?query=&i-am-feeling-lucky=1", web)
assert_redirect(
"/releases/search?query=&i-am-feeling-lucky=1",
"/some_random_crate/1.0.0/some_random_crate/",
web,
)?;
Ok(())
})
}

Expand All @@ -1109,7 +1114,12 @@ mod tests {
wrapper(|env| {
let web = env.frontend();
env.fake_release().name("some_random_crate").create()?;
assert_success("/releases/search?query=some_random_crate", web)

let links = get_release_links("/releases/search?query=some_random_crate", web)?;

assert_eq!(links.len(), 1);
assert_eq!(links[0], "/some_random_crate/1.0.0/some_random_crate/",);
Ok(())
})
}

Expand Down