-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Fix/null name fallback #1306
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a couple comments.
Also note to self that we will need to take the HTML changes here and propagate them to Postmark when this is merged.
def get_name(%User{ first_name: nil }), do: "there" | ||
|
||
@spec get_name(User.t) :: String.t | ||
def get_name(%User{ first_name: name}), do: name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can condense the spec to just above the first line and then not separate the lines between these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder whether we should place this fn into the BaseEmail
so that it's available to use across other emails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshsmith if the functionality is needed in other emails the function can live in BaseEmail
@joshsmith so I moved the function to BaseEmail and condensed the typespecs also the tests let me now if this what you are envisioning. How do we go about propagating the changes to postmark? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall logic looks great! Just need one more test and some minor formatting things.
test "get name returns there on nil name" do | ||
user = %CodeCorps.User{} | ||
assert BaseEmail.get_name(user) == "there" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to add another test for the non-nil
case.
lib/code_corps/emails/base_email.ex
Outdated
|
||
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer collapsing the spaces in the struct
, e.g. %User{first_name: name}
and %User{first_name: nil}
.
lib/code_corps/emails/base_email.ex
Outdated
def get_name(%User{ first_name: nil }), do: "there" | ||
def get_name(%User{ first_name: name}), do: name | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would remove these extra two lines.
@@ -5,10 +5,6 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do | |||
alias CodeCorps.Emails.ReceiptEmail | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would remove these extra two lines, too.
@joshsmith pushed for those changes let me know if this is looking better? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for back and forth. Couple more things I’d suggest.
f_name = "Zacck" | ||
user = %CodeCorps.User{first_name: f_name} | ||
assert BaseEmail.get_name(user) == f_name | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized too but you can wrap all these in a describe “get_name/2” do
block and write the test names like “when first_name is nil” and “when first_name is set”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you show me an example of that? very Keen to do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so the full thing would read:
describe "get_name/2" do
test "returns 'there' when first_name nil" do
user = %CodeCorps.User{first_name: nil}
assert BaseEmail.get_name(user) == "there"
end
test "returns first_name when first_name present" do
first_name = "Zacck"
user = %CodeCorps.User{first_name: first_name}
assert BaseEmail.get_name(user) == first_name
end
end
Does that help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zacck your pushes collapsed this comment, so hopefully you see this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see for the grouping of the tests for the functionality I though it was something with guards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nope! Nothing fancy. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thats done 😄
@@ -55,7 +55,7 @@ defmodule CodeCorps.Emails.ReceiptEmail do | |||
project_title: project.title, | |||
project_url: project |> url(), | |||
subject: project |> build_subject_line(), | |||
user_first_name: charge.user.first_name | |||
name: BaseEmail.get_name(charge.user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to alpha order these for consistency.
|
||
test "get_name returns first_name of user" do | ||
f_name = "Zacck" | ||
user = %CodeCorps.User{first_name: f_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don’t need the intermediate variable here. Can just put the string in directly as the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this. Refer to my example instead.
@@ -50,7 +50,7 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do | |||
project_url: "http://localhost:4200/#{project.organization.slug}/#{project.slug}", | |||
project_current_donation_goal_description: "Test goal", | |||
subject: "Your monthly donation to Code Corps", | |||
user_first_name: "Jimmy" | |||
name: "Jimmy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alpha order here too.
Looks good! Rebase and squash to one commit and this is mergeable! |
009d3bd
to
ffc2a1b
Compare
ffc2a1b
to
5f7be46
Compare
I went ahead and rebased/squashed and fixed a small formatting thing on one of the Thanks for the hard work on this! |
Thank you so much for this!!! Away from computers didn't see this yet
…On Thursday, December 21, 2017, Josh Smith ***@***.***> wrote:
I went ahead and rebased/squashed and fixed a small formatting thing on
one of the @SPEC's. An errant space got in there.
Thanks for the hard work on this!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1306 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA2ywzQkvgXEEgMsEch-eTZAhiGjoW9iks5tCp9kgaJpZM4RGeRV>
.
--
Regards
Isaac Osiemo - Software Developer
Skype: zacck.os
Tel: +27798259736
|
What's in this PR?
In this PR I am implementing a fallback for Users who donate without a name. I changed the reciept email mark up to more friendlier language.
I also changed the way RecieptEmail handles Users when they have a first and when they done
References
Fixes #819