From 735f99f87742b2951455c48ae47b4a9cc688050f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 29 Nov 2021 15:55:06 +0100 Subject: [PATCH] Fix comment notifications on legislation proposals The `commentable_url` method wasn't updated when we added legislation proposals. Back when we first created this method, we couldn't pass budget investments or topics directly to `polymorphic_url` because they are nested resources. That isn't the case since commit ff93f5a59, so now we can simplify this method. We're keeping the `commentable_url` method for now in order to keep compatibility with custom changes that might use it, although this method isn't consistent with the `commentable_path` method (which receives a comment, and not a commentable), and so we might have to revisit this code in the future. --- app/helpers/mailer_helper.rb | 6 +----- spec/mailers/mailer_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index 8a0e1e2f1..b6de1620a 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -1,10 +1,6 @@ module MailerHelper def commentable_url(commentable) - return poll_url(commentable) if commentable.is_a?(Poll) - return debate_url(commentable) if commentable.is_a?(Debate) - return proposal_url(commentable) if commentable.is_a?(Proposal) - return community_topic_url(commentable.community_id, commentable) if commentable.is_a?(Topic) - return budget_investment_url(commentable.budget_id, commentable) if commentable.is_a?(Budget::Investment) + polymorphic_url(commentable) end def valuation_comments_url(commentable) diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index 19e30ed34..d69d9cc01 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -22,5 +22,11 @@ describe Mailer do expect(email).to deliver_from "New organization " end + + it "sends emails for comments on legislation proposals" do + email = Mailer.comment(create(:legislation_proposal_comment)) + + expect(email.subject).to include("commented on your proposal") + end end end