moving to using a filter function for getting the item

This commit is contained in:
Chris Cochrun 2024-10-09 14:47:07 -05:00
parent f3c3e98e16
commit 0bfa2c6089
6 changed files with 16 additions and 18 deletions

View file

@ -48,7 +48,7 @@ mod test {
pub fn test_db_and_model() {
let mut video_model: Model<Video> = Model::default();
video_model.load_from_db();
if let Some(video) = video_model.get_item(3) {
if let Some(video) = video_model.get_item(|v| v.id == 3) {
let test_video = test_video("Getting started with Tokio. The ultimate starter guide to writing async Rust.".into());
assert_eq!(test_video.title, video.title);
} else {
@ -64,10 +64,10 @@ mod test {
let new_video = test_video("A newer video".into());
match result {
Ok(_) => {
assert_eq!(&video, video_model.get_item(0).unwrap());
assert_eq!(&video, video_model.get_item(|v| v.id == 0).unwrap());
assert_ne!(
&new_video,
video_model.get_item(0).unwrap()
video_model.get_item(|v| v.id == 0).unwrap()
);
}
Err(e) => assert!(