Fix evaluation comment email on system emails
Currently with both seeds and dev_seeds, not only was this email not displayed from the system emails section, but it also caused an error in the application. @email_to had an empty value and in the view we tried to access @email_to.name which caused the error. We kept the same logic but added the current_user to make sure it always has a valid value. We add the current_user because the current_user is always present in this controller..
This commit is contained in:
@@ -104,7 +104,7 @@ class Admin::SystemEmailsController < Admin::BaseController
|
|||||||
comment = Comment.where(commentable_type: "Budget::Investment").last
|
comment = Comment.where(commentable_type: "Budget::Investment").last
|
||||||
if comment
|
if comment
|
||||||
@email = EvaluationCommentEmail.new(comment)
|
@email = EvaluationCommentEmail.new(comment)
|
||||||
@email_to = @email.to.first
|
@email_to = @email.to.first || current_user
|
||||||
else
|
else
|
||||||
redirect_to admin_system_emails_path,
|
redirect_to admin_system_emails_path,
|
||||||
alert: t("admin.system_emails.alert.no_evaluation_comments")
|
alert: t("admin.system_emails.alert.no_evaluation_comments")
|
||||||
|
|||||||
@@ -251,25 +251,36 @@ describe "System Emails" do
|
|||||||
expect(page).to have_content "Some example data is needed in order to preview the email."
|
expect(page).to have_content "Some example data is needed in order to preview the email."
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "#evaluation_comment" do
|
describe "#evaluation_comment" do
|
||||||
admin = create(:administrator, user: create(:user, username: "Baby Doe"))
|
scenario "render correctly evaluaton comment mailer with valuator as a sample user" do
|
||||||
investment = create(:budget_investment,
|
admin = create(:administrator, user: create(:user, username: "Baby Doe"))
|
||||||
title: "Cleaner city",
|
investment = create(:budget_investment,
|
||||||
heading: heading,
|
title: "Cleaner city",
|
||||||
author: user,
|
heading: heading,
|
||||||
administrator: admin)
|
author: user,
|
||||||
comment = create(:comment, :valuation, commentable: investment)
|
administrator: admin)
|
||||||
|
comment = create(:comment, :valuation, commentable: investment)
|
||||||
|
|
||||||
visit admin_system_email_view_path("evaluation_comment")
|
visit admin_system_email_view_path("evaluation_comment")
|
||||||
|
|
||||||
expect(page).to have_content "New evaluation comment for Cleaner city"
|
expect(page).to have_content "New evaluation comment for Cleaner city"
|
||||||
expect(page).to have_content "Hi #{admin.name}"
|
expect(page).to have_content "Hi #{admin.name}"
|
||||||
expect(page).to have_content "There is a new evaluation comment from #{comment.user.name} "\
|
expect(page).to have_content "There is a new evaluation comment from #{comment.user.name} "\
|
||||||
"to the budget investment Cleaner city"
|
"to the budget investment Cleaner city"
|
||||||
expect(page).to have_content comment.body
|
expect(page).to have_content comment.body
|
||||||
|
|
||||||
expect(page).to have_link "Cleaner city",
|
expect(page).to have_link "Cleaner city",
|
||||||
href: admin_budget_budget_investment_url(investment.budget, investment, anchor: "comments", host: app_host)
|
href: admin_budget_budget_investment_url(investment.budget, investment, anchor: "comments", host: app_host)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "uses a current_user as a sample user for sample regular comments" do
|
||||||
|
create(:budget_investment_comment, body: "This is a sample comment")
|
||||||
|
|
||||||
|
visit admin_system_email_view_path("evaluation_comment")
|
||||||
|
|
||||||
|
expect(page).to have_content "This is a sample comment"
|
||||||
|
expect(page).to have_content admin.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user