View Source FactoryEx.SchemaCounter (factory_ex v0.3.4)
This is a counter module that wraps :counters
Setting Up
We can use this in our application by calling FactoryEx.SchemaCounter.start()
inside our test/test_helper.exs
file.
Using SchemaCounter
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 FactoryEx.SchemaCounter.next
FactoryEx.SchemaCounter.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 SchemaCounter, 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> FactoryEx.SchemaCounter.increment(key)
:ok
iex> FactoryEx.SchemaCounter.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> FactoryEx.SchemaCounter.increment(key)
:ok
iex> FactoryEx.SchemaCounter.get(key)
1
Increments and gets the current value for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> FactoryEx.SchemaCounter.next(key)
0
iex> FactoryEx.SchemaCounter.next(key)
1
iex> FactoryEx.SchemaCounter.next(key)
2
Puts the counter for a specific key
Example
iex> key = Enum.random(1..10_000_000)
iex> FactoryEx.SchemaCounter.increment(key)
:ok
iex> FactoryEx.SchemaCounter.put(key, 1234)
:ok
iex> FactoryEx.SchemaCounter.get(key)
1234
@spec start() :: :ok
This starts the SchemaCounter, 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