pub struct Factory<M> { /* private fields */ }Expand description
Builds models for a test.
Implementations§
Source§impl<M> Factory<M>
impl<M> Factory<M>
Sourcepub fn new(make: impl Fn(usize) -> M + Send + Sync + 'static) -> Self
pub fn new(make: impl Fn(usize) -> M + Send + Sync + 'static) -> Self
Build each model with make, which is handed the row’s index.
Sourcepub fn state(self, state: impl Fn(&mut M) + Send + Sync + 'static) -> Self
pub fn state(self, state: impl Fn(&mut M) + Send + Sync + 'static) -> Self
Adjust every model this factory builds.
The field the test is actually about. Applied in the order added, after the base model is built.
Sourcepub fn sequence(
self,
state: impl Fn(&mut M, usize) + Send + Sync + 'static,
) -> Self
pub fn sequence( self, state: impl Fn(&mut M, usize) + Send + Sync + 'static, ) -> Self
Adjust each model, knowing which one it is.
For anything that has to differ between rows — a unique email, an ordering, a timestamp that has to be distinct.
Source§impl<M: Model> Factory<M>
impl<M: Model> Factory<M>
Sourcepub async fn create(&self, repository: &dyn Repository<M>) -> Result<Vec<M>>
pub async fn create(&self, repository: &dyn Repository<M>) -> Result<Vec<M>>
Build them and insert them.
Returns what the repository returned — so a database-assigned key is on the model a test goes on to use, rather than the zero it was built with.
Sourcepub async fn create_one(&self, repository: &dyn Repository<M>) -> Result<M>
pub async fn create_one(&self, repository: &dyn Repository<M>) -> Result<M>
Build one and insert it.
Trait Implementations§
Auto Trait Implementations§
impl<M> !RefUnwindSafe for Factory<M>
impl<M> !UnwindSafe for Factory<M>
impl<M> Freeze for Factory<M>
impl<M> Send for Factory<M>
impl<M> Sync for Factory<M>
impl<M> Unpin for Factory<M>
impl<M> UnsafeUnpin for Factory<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
A human-readable name, used by wildcard listeners and log output.
Always the Rust type path; see the trait docs.