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
|
||||
if comment
|
||||
@email = EvaluationCommentEmail.new(comment)
|
||||
@email_to = @email.to.first
|
||||
@email_to = @email.to.first || current_user
|
||||
else
|
||||
redirect_to admin_system_emails_path,
|
||||
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."
|
||||
end
|
||||
|
||||
scenario "#evaluation_comment" do
|
||||
admin = create(:administrator, user: create(:user, username: "Baby Doe"))
|
||||
investment = create(:budget_investment,
|
||||
title: "Cleaner city",
|
||||
heading: heading,
|
||||
author: user,
|
||||
administrator: admin)
|
||||
comment = create(:comment, :valuation, commentable: investment)
|
||||
describe "#evaluation_comment" do
|
||||
scenario "render correctly evaluaton comment mailer with valuator as a sample user" do
|
||||
admin = create(:administrator, user: create(:user, username: "Baby Doe"))
|
||||
investment = create(:budget_investment,
|
||||
title: "Cleaner city",
|
||||
heading: heading,
|
||||
author: user,
|
||||
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 "Hi #{admin.name}"
|
||||
expect(page).to have_content "There is a new evaluation comment from #{comment.user.name} "\
|
||||
"to the budget investment Cleaner city"
|
||||
expect(page).to have_content comment.body
|
||||
expect(page).to have_content "New evaluation comment for Cleaner city"
|
||||
expect(page).to have_content "Hi #{admin.name}"
|
||||
expect(page).to have_content "There is a new evaluation comment from #{comment.user.name} "\
|
||||
"to the budget investment Cleaner city"
|
||||
expect(page).to have_content comment.body
|
||||
|
||||
expect(page).to have_link "Cleaner city",
|
||||
href: admin_budget_budget_investment_url(investment.budget, investment, anchor: "comments", host: app_host)
|
||||
expect(page).to have_link "Cleaner city",
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user