Skip to content

Commit ffc2a1b

Browse files
zacckjoshsmith
authored andcommitted
Add get_name function to the BaseEmail
1 parent 15d84db commit ffc2a1b

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

emails/receipt.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<img src="{{high_five_image_url}}" width="100" height="100" />
4646
</p>
4747
<p class="donation_text center">
48-
<strong>{{user_first_name}}</strong>, thanks for your monthly donation to <a href="{{project_url}}">{{project_title}}</a>.
48+
Hey {{name}}, thanks for your monthly donation to <a href="{{project_url}}">{{project_title}}</a>.
4949
</p>
5050
<tr>
5151
<td class="donation_goal">

lib/code_corps/emails/base_email.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
defmodule CodeCorps.Emails.BaseEmail do
22
import Bamboo.Email, only: [from: 2, new_email: 0]
3+
alias CodeCorps.User
34

45
@spec create :: Bamboo.Email.t
56
def create do
67
new_email()
78
|> from("Code Corps<team@codecorps.org>")
89
end
10+
11+
@spec get_name(User.t) :: String.t
12+
def get_name(%User{first_name: nil}), do: "there"
13+
def get_name(%User{first_name: name}), do: name
914
end

lib/code_corps/emails/receipt_email.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule CodeCorps.Emails.ReceiptEmail do
55
alias CodeCorps.Emails.BaseEmail
66
alias CodeCorps.{DonationGoal, Project, Repo, StripeConnectCharge, StripeConnectSubscription, WebClient}
77

8-
@spec create(StripeConnectCharge.t, Stripe.Invoice.t) :: Bamboo.Email.t
8+
@spec create(StripeConnectCharge.t, Stripe.Invoice.t) :: Bamboo.Email.t
99
def create(%StripeConnectCharge{} = charge, %Stripe.Invoice{} = invoice) do
1010
with %StripeConnectCharge{} = charge <- Repo.preload(charge, :user),
1111
%Project{} = project <- get_project(invoice.subscription),
@@ -51,11 +51,11 @@ defmodule CodeCorps.Emails.ReceiptEmail do
5151
charge_amount: charge.amount |> format_amount(),
5252
charge_statement_descriptor: charge.statement_descriptor,
5353
high_five_image_url: high_five_image_url(),
54+
name: BaseEmail.get_name(charge.user),
5455
project_current_donation_goal_description: current_donation_goal.description,
5556
project_title: project.title,
5657
project_url: project |> url(),
57-
subject: project |> build_subject_line(),
58-
user_first_name: charge.user.first_name
58+
subject: project |> build_subject_line()
5959
}
6060
end
6161

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule CodeCorps.Emails.BaseEmailTest do
2+
use CodeCorps.ModelCase
3+
use Bamboo.Test
4+
alias CodeCorps.Emails.BaseEmail
5+
6+
describe "get_name/1" do
7+
test "get_name returns there on nil name" do
8+
user = %CodeCorps.User{}
9+
assert BaseEmail.get_name(user) == "there"
10+
end
11+
12+
test "get_name returns first_name of user" do
13+
user = %CodeCorps.User{first_name: "Zacck"}
14+
assert BaseEmail.get_name(user) == "Zacck"
15+
end
16+
end
17+
end

test/lib/code_corps/emails/receipt_email_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do
4646
assert template_model == %{
4747
charge_amount: "$5.00",
4848
charge_statement_descriptor: "Test descriptor",
49+
name: "Jimmy",
4950
project_title: "Code Corps",
5051
project_url: "http://localhost:4200/#{project.organization.slug}/#{project.slug}",
5152
project_current_donation_goal_description: "Test goal",
52-
subject: "Your monthly donation to Code Corps",
53-
user_first_name: "Jimmy"
53+
subject: "Your monthly donation to Code Corps"
5454
}
5555
assert high_five_image_url
5656
end

0 commit comments

Comments
 (0)