Skip to content

Ensure resource_text is a string in NotificationMailer#6685

Merged
tramuntanal merged 3 commits intodevelopfrom
fix/notification-mail-ensdure-string
Oct 15, 2020
Merged

Ensure resource_text is a string in NotificationMailer#6685
tramuntanal merged 3 commits intodevelopfrom
fix/notification-mail-ensdure-string

Conversation

@mrcasals
Copy link
Copy Markdown
Contributor

🎩 What? Why?

Sometimes the NotificationMailer fails with this error:

undefined method `html_safe' for #<Hash:0x000055a91b3be790>
Did you mean?  html_safe?
decidim-25dbc986173a/decidim-core/app/views/decidim/notification_mailer/event_received.html.erb at line 8
<% if @event_instance.try(:resource_text).present? %>
  <blockquote>
    <p>
      <%= @event_instance.resource_text.html_safe %>
    </p>
  </blockquote>
<% end %>

This means there's some event that's not properly cleaning the resource_text value to make it return a String.

Instead of chasing the event, this PR introduces a new method in the event base class called safe_resource_text which makes sure that whatever is set by the event#resource_text method is a String and it's HTML-safe.

📌 Related Issues

Link your PR to an issue
None

Testing

Not sure how to find the wrong event, thus I'm not sure how to test it. Since the event is an instantiated class, I don't have the information in my error tracking application (Sentry). But if we chased the culprit, the problem might arise in other events. I think the approach in this PR is safer.

Just in case, I added tests for the new method ensuring it works as expected.

📋 Checklist

🚨 Please review the guidelines for contributing to this repository.

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

📷 Screenshots

None

♥️ Thank you!

@tramuntanal tramuntanal self-assigned this Oct 15, 2020
@tramuntanal tramuntanal changed the title Ensure strings in NotificationMailer Ensure resource_text is a string in NotificationMailer Oct 15, 2020
@tramuntanal tramuntanal merged commit acd7ed7 into develop Oct 15, 2020
@tramuntanal tramuntanal deleted the fix/notification-mail-ensdure-string branch October 15, 2020 10:20
tramuntanal pushed a commit that referenced this pull request Oct 15, 2020
* Ensure strings in NotificationMailer

* Add specs

* Ensure all events return a string on `safe_resource_text`
@mrcasals mrcasals added module: core type: fix PRs that implement a fix for a bug labels Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-review module: core type: fix PRs that implement a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants