Skip to content

Commit

Permalink
Merge pull request #7627 from fjordllc/bug/not-receive-mail-notificat…
Browse files Browse the repository at this point in the history
…ion-of-question

プラクティス未選択で質問を作成した場合にメール通知が届かないバグの修正
  • Loading branch information
komagata authored Apr 24, 2024
2 parents 008c1c9 + 1a55218 commit 1affec9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/mailers/activity_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def came_question(args = {})
@question ||= args[:question]

@user = @receiver
@title = @question.practice.present? ? "「#{@question.practice.title}」についての質問がありました。" : '質問がありました。'
@link_url = notification_redirector_url(
link: "/questions/#{@question.id}",
kind: Notification.kinds[:came_question]
Expand Down
2 changes: 1 addition & 1 deletion app/views/activity_mailer/came_question.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= render '/notification_mailer/notification_mailer_template',
title: "「#{@question.practice.title}」についての質問がありました。",
title: @title,
link_url: @link_url,
link_text: '質問へ' do
p #{@question.user.login_name}さんから質問がありました。アドバイスや回答を投稿しよう!!
Expand Down
20 changes: 20 additions & 0 deletions test/mailers/activity_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,26 @@ class ActivityMailerTest < ActionMailer::TestCase
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">質問へ</a>}, email.body.to_s)
end

test 'came_question with no practice' do
question = questions(:question14)
user = question.user
mentor = users(:komagata)

ActivityMailer.came_question(
sender: user,
receiver: mentor,
question:
).deliver_now

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
query = CGI.escapeHTML({ kind: 6, link: "/questions/#{question.id}" }.to_param)
assert_equal ['[email protected]'], email.from
assert_equal ['[email protected]'], email.to
assert_equal '[FBC] kimuraさんから質問「プラクティスを選択せずに登録したテストの質問」が投稿されました。', email.subject
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">質問へ</a>}, email.body.to_s)
end

test 'mentioned' do
mentionable = comments(:comment9)
mentioned = notifications(:notification_mentioned)
Expand Down

0 comments on commit 1affec9

Please sign in to comment.