Ensure consistency between in-memory and database state #146

Merged
wojtek merged 8 commits from 120---ensure-consistency-between-in-memory-and-database-state into main 2024-03-01 09:00:53 +01:00
Showing only changes of commit 91945e7fcb - Show all commits

View File

@ -220,6 +220,8 @@ impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
Self::sort_albums_and_tracks(self.collection.iter_mut());
self.merge_collections();
self.pre_commit = self.collection.clone();
Ok(())
}
@ -398,7 +400,9 @@ mod tests {
let artist_id = ArtistId::new("an artist");
let artist_id_2 = ArtistId::new("another artist");
let with_artist = vec![Artist::new(artist_id.clone())];
let collection = FULL_COLLECTION.to_owned();
let mut with_artist = collection.clone();
with_artist.push(Artist::new(artist_id.clone()));
let mut database = MockIDatabase::new();
let mut seq = Sequence::new();
@ -407,7 +411,7 @@ mod tests {
.times(1)
.times(1)
.in_sequence(&mut seq)
.returning(|| Ok(vec![]));
.returning(|| Ok(FULL_COLLECTION.to_owned()));
database
.expect_save()
.times(1)
@ -418,10 +422,11 @@ mod tests {
.expect_save()
.times(1)
.in_sequence(&mut seq)
.with(predicate::eq(vec![]))
.with(predicate::eq(collection.clone()))
.returning(|_| Ok(()));
let mut music_hoard = MusicHoard::database(database).unwrap();
assert_eq!(music_hoard.collection, collection);
assert!(music_hoard.add_artist(artist_id.clone()).is_ok());
assert_eq!(music_hoard.collection, with_artist);
@ -433,7 +438,7 @@ mod tests {
assert_eq!(music_hoard.collection, with_artist);
assert!(music_hoard.remove_artist(&artist_id).is_ok());
assert_eq!(music_hoard.collection, vec![]);
assert_eq!(music_hoard.collection, collection);
}
#[test]