-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get_name function to the BaseEmail
- Loading branch information
Showing
5 changed files
with
28 additions
and
6 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,9 +1,14 @@ | ||
defmodule CodeCorps.Emails.BaseEmail do | ||
import Bamboo.Email, only: [from: 2, new_email: 0] | ||
alias CodeCorps.User | ||
|
||
@spec create :: Bamboo.Email.t | ||
def create do | ||
new_email() | ||
|> from("Code Corps<team@codecorps.org>") | ||
end | ||
|
||
@spec get_name(User.t) :: String.t | ||
def get_name(%User{first_name: nil}), do: "there" | ||
def get_name(%User{first_name: name}), do: name | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule CodeCorps.Emails.BaseEmailTest do | ||
use CodeCorps.ModelCase | ||
use Bamboo.Test | ||
alias CodeCorps.Emails.BaseEmail | ||
|
||
describe "get_name/1" do | ||
test "get_name returns there on nil name" do | ||
user = %CodeCorps.User{} | ||
assert BaseEmail.get_name(user) == "there" | ||
end | ||
|
||
test "get_name returns first_name of user" do | ||
user = %CodeCorps.User{first_name: "Zacck"} | ||
assert BaseEmail.get_name(user) == "Zacck" | ||
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