-
Notifications
You must be signed in to change notification settings - Fork 2
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 #415 from dwyl/chore/refactor-get-person-id
Chore: Creates the Person module and refactors a little
- Loading branch information
Showing
5 changed files
with
50 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule App.Person do | ||
@doc """ | ||
Gets the Person Id from the assigns on connection or socket. | ||
""" | ||
def get_person_id(assigns), do: assigns[:person][:id] || 0 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule App.PersonTest do | ||
use ExUnit.Case | ||
alias App.Person | ||
|
||
@doc """ | ||
Test for `get_person_id/1` | ||
""" | ||
describe "get_person_id/1" do | ||
test "returns id when person is present in assigns" do | ||
assigns = %{person: %{id: 1}} | ||
assert Person.get_person_id(assigns) == 1 | ||
end | ||
|
||
test "returns 0 when person is not present in assigns" do | ||
assigns = %{} | ||
assert Person.get_person_id(assigns) == 0 | ||
end | ||
|
||
test "returns 0 when id is not present in person" do | ||
assigns = %{person: %{}} | ||
assert Person.get_person_id(assigns) == 0 | ||
end | ||
|
||
test "returns 0 when id is nil in person" do | ||
assigns = %{person: %{id: nil}} | ||
assert Person.get_person_id(assigns) == 0 | ||
end | ||
end | ||
end |