QuickFactory.Counters (quick_factory v0.1.0)
View SourceThis is a counter module that wraps :counters
Setup
We can use this in our application by calling QuickFactory.Counters.start()
inside our test/test_helper.exs
file.
Using Counters
We can then use this module to add unique integers to each field, each value
will only be used once provided we continue to call QuickFactory.Counters.next
QuickFactory.Counters.next("my_schema_field")
Summary
Functions
Gets the counter for a specific key
Increments the counter for a specific key
Increments and gets the current value for a specific key
Puts the counter for a specific key
This starts the Counters, you need to call this before calling any of the other
functions in this module. Most commonly this will go in your test/test_helper.exs
file
Functions
Gets the counter for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> QuickFactory.Counters.increment(key)
:ok
iex> QuickFactory.Counters.get(key)
1
@spec increment(key :: any()) :: :ok
Increments the counter for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> QuickFactory.Counters.increment(key)
:ok
iex> QuickFactory.Counters.get(key)
1
Increments and gets the current value for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> QuickFactory.Counters.next(key)
0
iex> QuickFactory.Counters.next(key)
1
iex> QuickFactory.Counters.next(key)
2
Puts the counter for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> QuickFactory.Counters.increment(key)
:ok
iex> QuickFactory.Counters.put(key, 1234)
:ok
iex> QuickFactory.Counters.get(key)
1234
@spec start() :: :ok
This starts the Counters, you need to call this before calling any of the other
functions in this module. Most commonly this will go in your test/test_helper.exs
file