Skip to content

Commit

Permalink
add test for ActiveModelTrait::is_changed()
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed May 7, 2022
1 parent 84f3837 commit c54ba8a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ pub trait ActiveModelTrait: Clone + Debug {

/// Returns `true` if any columns were changed.
fn is_changed(&self) -> bool {
<Self::Entity as EntityTrait>::Column::iter().any(|col| !self.get(col).is_unchanged())
<Self::Entity as EntityTrait>::Column::iter()
.any(|col| !self.get(col).is_unchanged() && self.get(col).is_set())
}
}

Expand Down Expand Up @@ -1093,4 +1094,13 @@ mod tests {

Ok(())
}

#[test]
fn test_active_model_is_changed() {
let mut fruit: fruit::ActiveModel = Default::default();
assert!(!fruit.is_changed());

fruit.set(fruit::Column::Name, "hello!".into());
assert!(fruit.is_changed());
}
}

0 comments on commit c54ba8a

Please sign in to comment.