fix flaky tests due to scope overwriting
This commit is contained in:
parent
4123b831b6
commit
1e916d1238
@ -203,12 +203,12 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
|
|||||||
Some(scope) => {
|
Some(scope) => {
|
||||||
let existing_scope = scope.route(path, route);
|
let existing_scope = scope.route(path, route);
|
||||||
self.scopes
|
self.scopes
|
||||||
.insert(menu_element.link.to_string(), existing_scope);
|
.insert(E::get_entity_name(), existing_scope);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let new_scope =
|
let new_scope =
|
||||||
web::scope(&format!("/{}", E::get_entity_name())).route(path, route);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ mod tests {
|
|||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use actix_web::{middleware, web, App};
|
use actix_web::{web, App};
|
||||||
|
|
||||||
use actix_admin::prelude::*;
|
use actix_admin::prelude::*;
|
||||||
|
|
||||||
#[actix_web::test]
|
#[actix_web::test]
|
||||||
@ -36,21 +35,20 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn test_get_is_success(url: &str) {
|
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_builder = super::create_actix_admin_builder();
|
||||||
let actix_admin = actix_admin_builder.get_actix_admin();
|
let actix_admin = actix_admin_builder.get_actix_admin();
|
||||||
|
|
||||||
let app_state = super::AppState {
|
let app_state = super::AppState {
|
||||||
db: conn,
|
actix_admin,
|
||||||
actix_admin: actix_admin,
|
db,
|
||||||
};
|
};
|
||||||
|
|
||||||
let app = test::init_service(
|
let app = test::init_service(
|
||||||
App::new()
|
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>())
|
.service(actix_admin_builder.get_scope::<super::AppState>())
|
||||||
.wrap(middleware::Logger::default()),
|
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -59,6 +57,6 @@ mod tests {
|
|||||||
.to_request();
|
.to_request();
|
||||||
let resp = test::call_service(&app, req).await;
|
let resp = test::call_service(&app, req).await;
|
||||||
|
|
||||||
assert!(resp.status().is_success());
|
assert_eq!(200, resp.status().as_u16());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ pub fn create_actix_admin_builder() -> ActixAdminBuilder {
|
|||||||
admin_builder.add_entity::<AppState, Comment>(&comment_view_model);
|
admin_builder.add_entity::<AppState, Comment>(&comment_view_model);
|
||||||
|
|
||||||
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
|
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
|
||||||
"Create Post From Plaintext",
|
"Create Comment From Plaintext",
|
||||||
"/create_post_from_plaintext",
|
"/create_post_from_plaintext",
|
||||||
web::post().to(create_post_from_plaintext::<AppState, Comment>), false);
|
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);
|
web::post().to(create_post_from_plaintext::<AppState, Post>), false);
|
||||||
|
|
||||||
admin_builder.add_custom_handler_for_entity::<AppState, Post>(
|
admin_builder.add_custom_handler_for_entity::<AppState, Post>(
|
||||||
"Create Post From Plaintext",
|
"Edit Post From Plaintext",
|
||||||
"/edit_post_from_plaintext/{id}",
|
"/edit_post_from_plaintext/{id}",
|
||||||
web::post().to(edit_post_from_plaintext::<AppState, Post>), false);
|
web::post().to(edit_post_from_plaintext::<AppState, Post>), false);
|
||||||
|
|
||||||
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
|
admin_builder.add_custom_handler_for_entity::<AppState, Comment>(
|
||||||
"Create Post From Plaintext",
|
"Edit Comment From Plaintext",
|
||||||
"/edit_post_from_plaintext/{id}",
|
"/edit_post_from_plaintext/{id}",
|
||||||
web::post().to(edit_post_from_plaintext::<AppState, Comment>), false);
|
web::post().to(edit_post_from_plaintext::<AppState, Comment>), false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user