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

Update resource before to process email so that partner invitation emails have correct body #3027

Conversation

italomatos
Copy link
Contributor

Resolves #2985

Description

This PR has goal to fix email message when a partner agency is invited.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • create a new partner
  • invite them

Screenshots

before

image

after

image

@@ -7,6 +7,8 @@ def subject_for(key)
# Replace the invitation instruction subject for partner users
# that were invited by other partner users.

resource.reload

if resource.is_a?(PartnerUser) && resource.id == resource.partner.primary_user&.id
Copy link
Contributor Author

@italomatos italomatos Jul 13, 2022

Choose a reason for hiding this comment

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

The problem is partner primary user is nil, when test in this condition.

Before check this condition is necessary update resource data.

@edwinthinks edwinthinks requested a review from cielf July 17, 2022 15:06
@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from 228706f to 1b53c37 Compare July 17, 2022 15:34
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hi Italo,
Could you also add a test for this?

@italomatos
Copy link
Contributor Author

Hi Italo,
Could you also add a test for this?

Hi @cielf I'm trying to identify where I will create a test.
Because this method belongs to devise_invitable

@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch 2 times, most recently from 7c7b232 to 2863fc1 Compare July 20, 2022 01:00
@italomatos italomatos requested a review from cielf July 20, 2022 01:01
@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from 2863fc1 to d84ef30 Compare July 20, 2022 01:04
@cielf
Copy link
Collaborator

cielf commented Jul 20, 2022

Hi Italo,
Could you also add a test for this?

Hi @cielf I'm trying to identify where I will create a test. Because this method belongs to devise_invitable

Myself, I would put the test in spec/mailers/custom_devise_mailer_spec.rb, which doesn't exist yet.

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Can you test that the right text is shown? (That's what the initial problem was)

@italomatos
Copy link
Contributor Author

Can you test that the right text is shown? (That's what the initial problem was)

@cielf Sure, actually I tested and attached print in PR description ( before fix and after fix).

@italomatos
Copy link
Contributor Author

Hi Italo,
Could you also add a test for this?

Hi @cielf I'm trying to identify where I will create a test. Because this method belongs to devise_invitable

Myself, I would put the test in spec/mailers/custom_devise_mailer_spec.rb, which doesn't exist yet.

Hi @cielf

Actually I had created this spec, so, I didnt like put business solution in Mailer file. So, I moved reload to InviteService, and created a test to cover that. But I aggree that We need to have spec to CustomDeviseMailer, but I didnt submit in this PR because it is not sollution to this problem. What do you think that I create a new PR to create spec to CustomDeviseMailer ?

@italomatos italomatos requested a review from cielf July 20, 2022 22:08
@cielf
Copy link
Collaborator

cielf commented Jul 20, 2022

I'd like to see tests showing that the issue is fixed -- that the right text comes out in each case, if that can be done without too much pain. We do check that the right text is sent in other mailer specs.

Comment on lines 290 to 291
expect(ActionMailer::Base.deliveries.last.subject).to eq("You've been invited to be a partner with #{@organization.name}")
expect(ActionMailer::Base.deliveries.last.html_part.body).to include("You've been invited to become a partner organization with <strong>#{@organization.name}!</strong>")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @cielf , this test check subject and body, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@italomatos I think we don't need to test the text in both the mailer spec and the requests spec -- following the patterns that I see in the current tests, I would use the mailer spec for testing the text. Does that make sense to you?

@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch 2 times, most recently from 1f2518c to eceded4 Compare July 21, 2022 08:50
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hi @italomatos -- a couple of questions/comments:
1/ there is already a partners_user in factories/partners/user -- does that not serve the purpose?
2/ Can we check the body text in the custom_devise_mailer_spec?
3/ I don't think we need to also check the text in the requests spec if we can check the body in the custom_devise_mailer_spec

Comment on lines 290 to 291
expect(ActionMailer::Base.deliveries.last.subject).to eq("You've been invited to be a partner with #{@organization.name}")
expect(ActionMailer::Base.deliveries.last.html_part.body).to include("You've been invited to become a partner organization with <strong>#{@organization.name}!</strong>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@italomatos I think we don't need to test the text in both the mailer spec and the requests spec -- following the patterns that I see in the current tests, I would use the mailer spec for testing the text. Does that make sense to you?

@italomatos
Copy link
Contributor Author

Hi @cielf

  1. factories/partners/user not work, because this factory is object from Partners::User , and the implementation is considering a instance of PartnerUser . I think a little bit confusing these models. But there is a comment in PartnerUser , the explain the reason to created it.

  2. Sure, I'm modifying to check body text too.

  3. make sense.

@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from eceded4 to 5558e84 Compare July 22, 2022 01:40
@italomatos italomatos requested a review from cielf July 22, 2022 01:41
@cielf
Copy link
Collaborator

cielf commented Jul 25, 2022

I agree that the model is confusing -- we're in the midst of consolidating the user models -- see Daniel's PR 3013: Consolidate users #3050.

@cielf
Copy link
Collaborator

cielf commented Jul 25, 2022

Indeed, I think it might be a good idea to hold off on this one, rebase and rework according to his changes when it's been merged. It's not a high priority change. What do you think?

@italomatos
Copy link
Contributor Author

Indeed, I think it might be a good idea to hold off on this one, rebase and rework according to his changes when it's been merged. It's not a high priority change. What do you think?

ok, make sense

@edwinthinks edwinthinks changed the title update resource before to process email [BLOCKED] Update resource before to process email so that partner invitation emails have correct body Jul 28, 2022
@edwinthinks
Copy link
Collaborator

@italomatos just a quick update on the title so we know this is blocked :)

@edwinthinks edwinthinks changed the title [BLOCKED] Update resource before to process email so that partner invitation emails have correct body Update resource before to process email so that partner invitation emails have correct body Jul 31, 2022
@edwinthinks
Copy link
Collaborator

@italomatos the PR for merging the user models #3050 have been completed! I think you can continue working on this :)

@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from 5558e84 to b549a09 Compare July 31, 2022 12:57
@italomatos italomatos changed the title Update resource before to process email so that partner invitation emails have correct body WIP - Update resource before to process email so that partner invitation emails have correct body Jul 31, 2022
@italomatos italomatos marked this pull request as draft July 31, 2022 12:59
@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from 7368644 to e598b34 Compare July 31, 2022 17:11
@italomatos italomatos changed the title WIP - Update resource before to process email so that partner invitation emails have correct body Update resource before to process email so that partner invitation emails have correct body Jul 31, 2022
@italomatos italomatos marked this pull request as ready for review July 31, 2022 17:11
@italomatos
Copy link
Contributor Author

@italomatos the PR for merging the user models #3050 have been completed! I think you can continue working on this :)

Hi @edwinthinks I did rebase, and this PR is ready to review :)

@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from e598b34 to 52f3acd Compare July 31, 2022 17:32
@italomatos italomatos force-pushed the hotfix/2985-wrong-message-email-to-partner-organization branch from 52f3acd to 8e0d1cb Compare August 1, 2022 11:35
Copy link
Collaborator

@edwinthinks edwinthinks left a comment

Choose a reason for hiding this comment

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

Thanks @italomatos a few minor suggestions and once those have been addressed I think we a good to go!

Comment on lines +14 to +15
user.reload
user.deliver_invitation
Copy link
Collaborator

Choose a reason for hiding this comment

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

One minor suggestion, can you add a comment to explain why this was added? I sense it will be unclear to future maintainers about why this was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @edwinthinks, I agree. Is it ok? Thanks

<% is_primary_partner = @resource.id == @resource.partner&.primary_user&.id %>
<p>Hello <%= @resource.email %></p>
<% if @resource.partner.present? && is_primary_partner %>
<p>You've been invited to become a partner organization with <strong><%= organization.name %>!</strong></p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<p>You've been invited to become a partner organization with <strong><%= organization.name %>!</strong></p>
<p>You've been invited to become a partner with <strong><%= organization.name %>!</strong></p>

Comment on lines 376 to 377
<p>Feel free to ignore this email if you are not interested or if you feel it was sent by
mistake.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<p>Feel free to ignore this email if you are not interested or if you feel it was sent by
mistake.</p>
<p>Feel free to ignore this email if you are not interested or if you feel it was sent by mistake.</p>

…on user object needs to reload before send email
@edwinthinks
Copy link
Collaborator

Hey @italomatos -- I think there is just a few specs to fix. Probably from the changes suggested.

@italomatos italomatos requested a review from edwinthinks August 6, 2022 22:16
Italo Matos and others added 2 commits August 6, 2022 19:52
@edwinthinks edwinthinks merged commit d36a88b into rubyforgood:main Aug 7, 2022
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.

[BUG] Initial email to partner organization is showing the text for additional accounts
3 participants