-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from annatel/refacto
Refacto
- Loading branch information
Showing
4 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
defmodule Queuetopia.Test.Assertions do | ||
import ExUnit.Assertions | ||
require Ecto.Query | ||
alias Queuetopia.Jobs.Job | ||
|
||
@doc """ | ||
Asserts the job has juste been created | ||
""" | ||
|
||
def assert_job_created(queue, %{} = params) do | ||
repo = queue.repo() | ||
def assert_job_created(queuetopia) when is_atom(queuetopia) do | ||
repo = queuetopia.repo() | ||
|
||
job = Job |> Ecto.Query.last() |> repo.one() | ||
refute is_nil(job) | ||
job | ||
end | ||
|
||
def assert_job_created(queuetopia, queue) when is_atom(queuetopia) and is_binary(queue) do | ||
repo = queuetopia.repo() | ||
|
||
job = | ||
Job | ||
|> Ecto.Query.where([job], job.queue == ^queue) | ||
|> Ecto.Query.last() | ||
|> repo.one() | ||
|
||
refute is_nil(job) && assert(^params = job) | ||
refute is_nil(job) | ||
job | ||
end | ||
|
||
def assert_job_created(queuetopia, %{} = params) when is_atom(queuetopia) do | ||
job = assert_job_created(queuetopia) | ||
assert ^params = job | ||
end | ||
|
||
def assert_job_created(queuetopia, queue, %{} = params) | ||
when is_atom(queuetopia) and is_binary(queue) do | ||
job = assert_job_created(queuetopia, queue) | ||
assert ^params = job | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters