diff --git a/src/index/query.rs b/src/index/query.rs index d3c16b2..fa643e4 100644 --- a/src/index/query.rs +++ b/src/index/query.rs @@ -101,9 +101,13 @@ where let real_songs: Vec = if virtual_path.as_ref().parent() != None { let real_path = vfs.virtual_to_real(virtual_path)?; - let like_path = real_path.as_path().to_string_lossy().into_owned() + "%"; + let song_path_filter = { + let mut path_buf = real_path.clone(); + path_buf.push("%"); + path_buf.as_path().to_string_lossy().into_owned() + }; songs - .filter(path.like(&like_path)) + .filter(path.like(&song_path_filter)) .order(path) .load(&connection)? } else { diff --git a/src/index/test.rs b/src/index/test.rs index 3645b4c..8cd13b6 100644 --- a/src/index/test.rs +++ b/src/index/test.rs @@ -13,8 +13,8 @@ fn test_populate() { let connection = db.connect().unwrap(); let all_directories: Vec = directories::table.load(&connection).unwrap(); let all_songs: Vec = songs::table.load(&connection).unwrap(); - assert_eq!(all_directories.len(), 5); - assert_eq!(all_songs.len(), 12); + assert_eq!(all_directories.len(), 6); + assert_eq!(all_songs.len(), 13); } #[test] @@ -101,9 +101,26 @@ fn test_browse() { fn test_flatten() { let db = db::get_test_db("flatten.sqlite"); update(&db).unwrap(); + + // Flatten all let results = flatten(&db, Path::new("root")).unwrap(); - assert_eq!(results.len(), 12); + assert_eq!(results.len(), 13); assert_eq!(results[0].title, Some("Above The Water".to_owned())); + + // Flatten a directory + let mut path = PathBuf::new(); + path.push("root"); + path.push("Tobokegao"); + let results = flatten(&db, &path).unwrap(); + assert_eq!(results.len(), 8); + + // Flatten a directory that is a prefix of another directory (Picnic Remixes) + let mut path = PathBuf::new(); + path.push("root"); + path.push("Tobokegao"); + path.push("Picnic"); + let results = flatten(&db, &path).unwrap(); + assert_eq!(results.len(), 7); } #[test] diff --git a/src/playlist.rs b/src/playlist.rs index 4d8bf88..2623102 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -259,18 +259,18 @@ fn test_fill_playlist() { .into_iter() .map(|s| s.path) .collect(); - assert_eq!(playlist_content.len(), 12); + assert_eq!(playlist_content.len(), 13); let first_song = playlist_content[0].clone(); playlist_content.push(first_song); - assert_eq!(playlist_content.len(), 13); + assert_eq!(playlist_content.len(), 14); save_playlist("all_the_music", "test_user", &playlist_content, &db).unwrap(); let songs = read_playlist("all_the_music", "test_user", &db).unwrap(); - assert_eq!(songs.len(), 13); + assert_eq!(songs.len(), 14); assert_eq!(songs[0].title, Some("Above The Water".to_owned())); - assert_eq!(songs[12].title, Some("Above The Water".to_owned())); + assert_eq!(songs[13].title, Some("Above The Water".to_owned())); use std::path::PathBuf; let mut first_song_path = PathBuf::new(); @@ -283,5 +283,5 @@ fn test_fill_playlist() { // Save again to verify that we don't dupe the content save_playlist("all_the_music", "test_user", &playlist_content, &db).unwrap(); let songs = read_playlist("all_the_music", "test_user", &db).unwrap(); - assert_eq!(songs.len(), 13); + assert_eq!(songs.len(), 14); } diff --git a/src/service/test.rs b/src/service/test.rs index f636115..bad1dbc 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -242,7 +242,7 @@ fn test_service_trigger_index() { let response = service.get_json::>("/api/random"); let entries = response.body(); - assert_eq!(entries.len(), 2); + assert_eq!(entries.len(), 3); } #[test] @@ -317,11 +317,11 @@ fn test_service_flatten() { let response = service.get_json::>("/api/flatten"); let entries = response.body(); - assert_eq!(entries.len(), 12); + assert_eq!(entries.len(), 13); let response = service.get_json::>("/api/flatten/collection"); let entries = response.body(); - assert_eq!(entries.len(), 12); + assert_eq!(entries.len(), 13); } #[test] @@ -333,7 +333,7 @@ fn test_service_random() { let response = service.get_json::>("/api/random"); let entries = response.body(); - assert_eq!(entries.len(), 2); + assert_eq!(entries.len(), 3); } #[test] @@ -345,7 +345,7 @@ fn test_service_recent() { let response = service.get_json::>("/api/recent"); let entries = response.body(); - assert_eq!(entries.len(), 2); + assert_eq!(entries.len(), 3); } #[test] diff --git a/test/collection/Tobokegao/Picnic (Remixes)/01 - ピクニック (Picnic) (Remix).mp3 b/test/collection/Tobokegao/Picnic (Remixes)/01 - ピクニック (Picnic) (Remix).mp3 new file mode 100644 index 0000000..110a965 Binary files /dev/null and b/test/collection/Tobokegao/Picnic (Remixes)/01 - ピクニック (Picnic) (Remix).mp3 differ