Skip to content
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

Merged
merged 1 commit into from
Dec 21, 2017

Conversation

zacck-zz
Copy link
Member

@zacck-zz zacck-zz commented Dec 19, 2017

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

Copy link
Contributor

@joshsmith joshsmith left a 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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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

@zacck-zz
Copy link
Member Author

@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?

Copy link
Contributor

@joshsmith joshsmith left a 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
Copy link
Contributor

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.


@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
Copy link
Contributor

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}.

def get_name(%User{ first_name: nil }), do: "there"
def get_name(%User{ first_name: name}), do: name


Copy link
Contributor

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


Copy link
Contributor

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.

@zacck-zz
Copy link
Member Author

@joshsmith pushed for those changes let me know if this is looking better?

Copy link
Contributor

@joshsmith joshsmith left a 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
Copy link
Contributor

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”.

Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nope! Nothing fancy. :)

Copy link
Member Author

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)
Copy link
Contributor

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}
Copy link
Contributor

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.

Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpha order here too.

@joshsmith
Copy link
Contributor

Looks good! Rebase and squash to one commit and this is mergeable!

@joshsmith joshsmith force-pushed the fix/null-name-fallback branch from 009d3bd to ffc2a1b Compare December 21, 2017 18:08
@joshsmith joshsmith force-pushed the fix/null-name-fallback branch from ffc2a1b to 5f7be46 Compare December 21, 2017 18:10
@joshsmith
Copy link
Contributor

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!

@joshsmith joshsmith merged commit 0592e5e into code-corps:develop Dec 21, 2017
@zacck-zz
Copy link
Member Author

zacck-zz commented Dec 23, 2017 via email

@zacck-zz zacck-zz deleted the fix/null-name-fallback branch December 31, 2017 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants