fix: change mutability to ref while deleting items from catalog
This commit is contained in:
@@ -16,7 +16,7 @@ impl Catalog {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `id` - The ID of the entity to mark for deletion.
|
/// * `id` - The ID of the entity to mark for deletion.
|
||||||
pub fn delete(&mut self, id: &str) {
|
pub fn delete(&self, id: &str) {
|
||||||
let _ = self.on_items(|items| {
|
let _ = self.on_items(|items| {
|
||||||
let entity = items.get_mut(id);
|
let entity = items.get_mut(id);
|
||||||
if let Some(entity) = entity {
|
if let Some(entity) = entity {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn delete_should_mark_entity_as_to_delete() {
|
fn delete_should_mark_entity_as_to_delete() {
|
||||||
// Should mark an existing entity's state as 'ToDelete'.
|
// Should mark an existing entity's state as 'ToDelete'.
|
||||||
let mut catalog = Catalog::new("dummy.db");
|
let catalog = Catalog::new("dummy.db");
|
||||||
let item = Item {
|
let item = Item {
|
||||||
id: "item-123".to_string(),
|
id: "item-123".to_string(),
|
||||||
name: "Test Item".to_string(),
|
name: "Test Item".to_string(),
|
||||||
@@ -27,7 +27,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn delete_should_have_no_effect_for_nonexistent_id() {
|
fn delete_should_have_no_effect_for_nonexistent_id() {
|
||||||
// Should have no effect if the entity ID does not exist.
|
// Should have no effect if the entity ID does not exist.
|
||||||
let mut catalog = Catalog::new("dummy.db");
|
let catalog = Catalog::new("dummy.db");
|
||||||
let item = Item {
|
let item = Item {
|
||||||
id: "item-123".to_string(),
|
id: "item-123".to_string(),
|
||||||
name: "Test Item".to_string(),
|
name: "Test Item".to_string(),
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ mod tests {
|
|||||||
std::fs::remove_file(path).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
// 1. Create catalog, insert an item, and persist it.
|
// 1. Create catalog, insert an item, and persist it.
|
||||||
let mut catalog1 = Catalog::new(db_path);
|
let catalog1 = Catalog::new(db_path);
|
||||||
catalog1.init().unwrap();
|
catalog1.init().unwrap();
|
||||||
let item1 = Item {
|
let item1 = Item {
|
||||||
id: "item-to-delete".to_string(),
|
id: "item-to-delete".to_string(),
|
||||||
@@ -248,7 +248,7 @@ mod tests {
|
|||||||
std::fs::remove_file(path).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
// 1. Setup: Create a catalog and pre-populate it with some data.
|
// 1. Setup: Create a catalog and pre-populate it with some data.
|
||||||
let mut catalog = Catalog::new(db_path);
|
let catalog = Catalog::new(db_path);
|
||||||
catalog.init().unwrap();
|
catalog.init().unwrap();
|
||||||
let item_to_update = Item {
|
let item_to_update = Item {
|
||||||
id: "update-me".to_string(),
|
id: "update-me".to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user