fix flaky tests due to scope overwriting

This commit is contained in:
Manuel Gugger 2023-01-11 19:01:05 +01:00
parent 4123b831b6
commit 1e916d1238
3 changed files with 11 additions and 13 deletions

View File

@ -203,12 +203,12 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
Some(scope) => {
let existing_scope = scope.route(path, route);
self.scopes
.insert(menu_element.link.to_string(), existing_scope);
.insert(E::get_entity_name(), existing_scope);
}
_ => {
let new_scope =
web::scope(&format!("/{}", E::get_entity_name())).route(path, route);
self.scopes.insert(menu_element.link.to_string(), new_scope);
self.scopes.insert(E::get_entity_name(), new_scope);
}
}

View File

@ -6,8 +6,7 @@ mod tests {
extern crate serde_derive;
use actix_web::test;
use actix_web::{middleware, web, App};
use actix_web::{web, App};
use actix_admin::prelude::*;
#[actix_web::test]
@ -36,21 +35,20 @@ mod tests {
}
async fn test_get_is_success(url: &str) {
let conn = super::create_tables_and_get_connection().await;
let db = super::create_tables_and_get_connection().await;
let actix_admin_builder = super::create_actix_admin_builder();
let actix_admin = actix_admin_builder.get_actix_admin();
let app_state = super::AppState {
db: conn,
actix_admin: actix_admin,
actix_admin,
db,
};
let app = test::init_service(
App::new()
.app_data(web::Data::new(app_state.clone()))
.app_data(web::Data::new(app_state))
.service(actix_admin_builder.get_scope::<super::AppState>())
.wrap(middleware::Logger::default()),
)
.await;
@ -59,6 +57,6 @@ mod tests {
.to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
assert_eq!(200, resp.status().as_u16());
}
}

View File

@ -49,7 +49,7 @@ pub fn create_actix_admin_builder() -> ActixAdminBuilder {
admin_builder.add_entity::<AppState, Comment>(&comment_view_model);
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
"Create Post From Plaintext",
"Create Comment From Plaintext",
"/create_post_from_plaintext",
web::post().to(create_post_from_plaintext::<AppState, Comment>), false);
@ -59,12 +59,12 @@ pub fn create_actix_admin_builder() -> ActixAdminBuilder {
web::post().to(create_post_from_plaintext::<AppState, Post>), false);
admin_builder.add_custom_handler_for_entity::<AppState, Post>(
"Create Post From Plaintext",
"Edit Post From Plaintext",
"/edit_post_from_plaintext/{id}",
web::post().to(edit_post_from_plaintext::<AppState, Post>), false);
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
"Create Post From Plaintext",
"Edit Comment From Plaintext",
"/edit_post_from_plaintext/{id}",
web::post().to(edit_post_from_plaintext::<AppState, Comment>), false);