Skip to main content

Factory

Struct Factory 

Source
pub struct Factory<M> { /* private fields */ }
Expand description

Builds models for a test.

Implementations§

Source§

impl<M> Factory<M>

Source

pub fn new(make: impl Fn(usize) -> M + Send + Sync + 'static) -> Self

Build each model with make, which is handed the row’s index.

Source

pub fn count(self, count: usize) -> Self

How many to build.

Source

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.

Source

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

pub fn make(&self) -> Vec<M>

Build them, without touching a database.

For a test about a pure function, a serialiser or a policy — none of which need a row to exist anywhere.

Source

pub fn make_one(&self) -> M

Build exactly one.

§Panics

Never — count is ignored and one is built.

Source§

impl<M: Model> Factory<M>

Source

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.

Source

pub async fn create_one(&self, repository: &dyn Repository<M>) -> Result<M>

Build one and insert it.

Trait Implementations§

Source§

impl<M> Clone for Factory<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for Factory<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Factory<M>

§

impl<M> !UnwindSafe for Factory<M>

§

impl<M> Freeze for Factory<M>
where Arc<dyn Fn(usize) -> M + Sync + Send>: Freeze, Vec<Arc<dyn Fn(&mut M, usize) + Sync + Send>>: Freeze,

§

impl<M> Send for Factory<M>
where Arc<dyn Fn(usize) -> M + Sync + Send>: Send, Vec<Arc<dyn Fn(&mut M, usize) + Sync + Send>>: Send,

§

impl<M> Sync for Factory<M>
where Arc<dyn Fn(usize) -> M + Sync + Send>: Sync, Vec<Arc<dyn Fn(&mut M, usize) + Sync + Send>>: Sync,

§

impl<M> Unpin for Factory<M>
where Arc<dyn Fn(usize) -> M + Sync + Send>: Unpin, Vec<Arc<dyn Fn(&mut M, usize) + Sync + Send>>: Unpin,

§

impl<M> UnsafeUnpin for Factory<M>
where Arc<dyn Fn(usize) -> M + Sync + Send>: UnsafeUnpin, Vec<Arc<dyn Fn(&mut M, usize) + Sync + Send>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more