Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class SubscriptionMailer < ApplicationMailer
helper PostsHelper
helper UsersHelper

def subscription
Expand Down
3 changes: 1 addition & 2 deletions app/views/subscription_mailer/subscription.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<%= link_to question.title, post_url(question, host: @subscription.community.host) %>
</h3>
<p>
<%= question.body.first(150).gsub(/<\/?[^>]+>/, '') %>
<%= question.body.length > 150 ? '...' : '' %>
<%= sanitize(strip_tags(question.body).truncate(150), scrubber: scrubber) %>
</p>
<p>
&mdash; <%= user_link question.user, { host: @subscription.community.host } %>
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,17 @@ without_new_thread_followers:
community: sample
category: main
license: cc_by_sa

with_sanitized_html:
post_type: question
title: This post contains HTML in body that is sanitized away
body: |
This is the body of the post used to test HTML sanitization
<del>oops</del>
body_markdown: |
<p>
This is the body of the post used to test HTML sanitization
<del>oops</del>
</p>
community: sample
user: standard_user
25 changes: 22 additions & 3 deletions test/mailers/subscription_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
require 'test_helper'

class SubscriptionMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
test 'should correctly send subscription emails' do
all_sub = subscriptions(:all)
post_with_html = posts(:with_sanitized_html)

mailer = SubscriptionMailer.with(subscription: all_sub)
email = mailer.subscription

assert(all_sub.questions&.any? { |q| q.id == post_with_html.id })

assert_emails 1 do
email.deliver_later
end

assert email.from.include?(SiteSetting['SubscriptionSenderEmail'])
assert email.to.include?(all_sub.user.email)
assert email.subject.start_with?('Latest questions from your')

assert_dom_email do
assert_not_dom 'del'
assert_dom 'p', /oops/
end
end
end
Loading