-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align action_list_item label with checkbox
- Loading branch information
1 parent
28645d2
commit 9b8cf74
Showing
8 changed files
with
181 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule PrimerLive.TestHelpers.Repo.Todo do | ||
use Ecto.Schema | ||
|
||
schema "todos" do | ||
field(:statuses, {:array, :string}, default: []) | ||
|
||
timestamps() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule PrimerLive.TestHelpers.Repo.Todos do | ||
import Ecto.Changeset, except: [change: 1] | ||
alias PrimerLive.TestHelpers.Repo.Todo | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking to do item changes. | ||
## Examples | ||
iex> change(to do item) | ||
%Ecto.Changeset{data: %Todo{}} | ||
""" | ||
def change(%Todo{} = todo, attrs \\ %{}) do | ||
todo | ||
|> changeset(attrs) | ||
end | ||
|
||
def init() do | ||
change(%Todo{}) | ||
end | ||
|
||
@status_options [ | ||
{"In progress", "in-progress"}, | ||
{"Needs review", "needs-review"}, | ||
{"Complete", "complete"} | ||
] | ||
|
||
def status_options, do: @status_options | ||
|
||
@allowed_fields [ | ||
:statuses | ||
] | ||
|
||
@required_fields [ | ||
:statuses | ||
] | ||
|
||
defp changeset(todo, attrs) do | ||
todo | ||
|> cast(attrs, @allowed_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_empty(:statuses, "must select a status") | ||
end | ||
|
||
defp validate_empty(changeset, field, message) do | ||
values = get_field(changeset, field) | ||
|
||
if Enum.empty?(values) do | ||
add_error(changeset, field, message) | ||
else | ||
changeset | ||
end | ||
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
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