-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Update resource before to process email so that partner invitation emails have correct body #3027
Conversation
app/mailers/custom_devise_mailer.rb
Outdated
@@ -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 |
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.
The problem is partner primary user is nil, when test in this condition.
Before check this condition is necessary update resource data.
228706f
to
1b53c37
Compare
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.
Hi Italo,
Could you also add a test for this?
Hi @cielf I'm trying to identify where I will create a test. |
7c7b232
to
2863fc1
Compare
2863fc1
to
d84ef30
Compare
Myself, I would put the test in spec/mailers/custom_devise_mailer_spec.rb, which doesn't exist yet. |
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.
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). |
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 ? |
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. |
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>") |
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.
Hi @cielf , this test check subject and body, what do you think?
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.
@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?
1f2518c
to
eceded4
Compare
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.
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
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>") |
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.
@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?
Hi @cielf
|
eceded4
to
5558e84
Compare
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. |
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 |
@italomatos just a quick update on the title so we know this is blocked :) |
@italomatos the PR for merging the user models #3050 have been completed! I think you can continue working on this :) |
5558e84
to
b549a09
Compare
7368644
to
e598b34
Compare
Hi @edwinthinks I did rebase, and this PR is ready to review :) |
e598b34
to
52f3acd
Compare
52f3acd
to
8e0d1cb
Compare
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.
Thanks @italomatos a few minor suggestions and once those have been addressed I think we a good to go!
user.reload | ||
user.deliver_invitation |
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.
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.
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.
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> |
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.
<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> |
<p>Feel free to ignore this email if you are not interested or if you feel it was sent by | ||
mistake.</p> |
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.
<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
Hey @italomatos -- I think there is just a few specs to fix. Probably from the changes suggested. |
…tfix/2985-wrong-message-email-to-partner-organization
Resolves #2985
Description
This PR has goal to fix email message when a partner agency is invited.
Type of change
How Has This Been Tested?
Screenshots
before
after