Fixed a bug where flatten could return songs from adjacent directories
This commit is contained in:
parent
99db3eda13
commit
d5c186579a
5 changed files with 36 additions and 15 deletions
|
@ -101,9 +101,13 @@ where
|
||||||
|
|
||||||
let real_songs: Vec<Song> = if virtual_path.as_ref().parent() != None {
|
let real_songs: Vec<Song> = if virtual_path.as_ref().parent() != None {
|
||||||
let real_path = vfs.virtual_to_real(virtual_path)?;
|
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
|
songs
|
||||||
.filter(path.like(&like_path))
|
.filter(path.like(&song_path_filter))
|
||||||
.order(path)
|
.order(path)
|
||||||
.load(&connection)?
|
.load(&connection)?
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,8 +13,8 @@ fn test_populate() {
|
||||||
let connection = db.connect().unwrap();
|
let connection = db.connect().unwrap();
|
||||||
let all_directories: Vec<Directory> = directories::table.load(&connection).unwrap();
|
let all_directories: Vec<Directory> = directories::table.load(&connection).unwrap();
|
||||||
let all_songs: Vec<Song> = songs::table.load(&connection).unwrap();
|
let all_songs: Vec<Song> = songs::table.load(&connection).unwrap();
|
||||||
assert_eq!(all_directories.len(), 5);
|
assert_eq!(all_directories.len(), 6);
|
||||||
assert_eq!(all_songs.len(), 12);
|
assert_eq!(all_songs.len(), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -101,9 +101,26 @@ fn test_browse() {
|
||||||
fn test_flatten() {
|
fn test_flatten() {
|
||||||
let db = db::get_test_db("flatten.sqlite");
|
let db = db::get_test_db("flatten.sqlite");
|
||||||
update(&db).unwrap();
|
update(&db).unwrap();
|
||||||
|
|
||||||
|
// Flatten all
|
||||||
let results = flatten(&db, Path::new("root")).unwrap();
|
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()));
|
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]
|
#[test]
|
||||||
|
|
|
@ -259,18 +259,18 @@ fn test_fill_playlist() {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.path)
|
.map(|s| s.path)
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(playlist_content.len(), 12);
|
assert_eq!(playlist_content.len(), 13);
|
||||||
|
|
||||||
let first_song = playlist_content[0].clone();
|
let first_song = playlist_content[0].clone();
|
||||||
playlist_content.push(first_song);
|
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();
|
save_playlist("all_the_music", "test_user", &playlist_content, &db).unwrap();
|
||||||
|
|
||||||
let songs = read_playlist("all_the_music", "test_user", &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[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;
|
use std::path::PathBuf;
|
||||||
let mut first_song_path = PathBuf::new();
|
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 again to verify that we don't dupe the content
|
||||||
save_playlist("all_the_music", "test_user", &playlist_content, &db).unwrap();
|
save_playlist("all_the_music", "test_user", &playlist_content, &db).unwrap();
|
||||||
let songs = read_playlist("all_the_music", "test_user", &db).unwrap();
|
let songs = read_playlist("all_the_music", "test_user", &db).unwrap();
|
||||||
assert_eq!(songs.len(), 13);
|
assert_eq!(songs.len(), 14);
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ fn test_service_trigger_index() {
|
||||||
|
|
||||||
let response = service.get_json::<Vec<index::Directory>>("/api/random");
|
let response = service.get_json::<Vec<index::Directory>>("/api/random");
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 2);
|
assert_eq!(entries.len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -317,11 +317,11 @@ fn test_service_flatten() {
|
||||||
|
|
||||||
let response = service.get_json::<Vec<index::Song>>("/api/flatten");
|
let response = service.get_json::<Vec<index::Song>>("/api/flatten");
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 12);
|
assert_eq!(entries.len(), 13);
|
||||||
|
|
||||||
let response = service.get_json::<Vec<index::Song>>("/api/flatten/collection");
|
let response = service.get_json::<Vec<index::Song>>("/api/flatten/collection");
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 12);
|
assert_eq!(entries.len(), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -333,7 +333,7 @@ fn test_service_random() {
|
||||||
|
|
||||||
let response = service.get_json::<Vec<index::Directory>>("/api/random");
|
let response = service.get_json::<Vec<index::Directory>>("/api/random");
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 2);
|
assert_eq!(entries.len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -345,7 +345,7 @@ fn test_service_recent() {
|
||||||
|
|
||||||
let response = service.get_json::<Vec<index::Directory>>("/api/recent");
|
let response = service.get_json::<Vec<index::Directory>>("/api/recent");
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 2);
|
assert_eq!(entries.len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Reference in a new issue