From 935ce9bec564288c158add34fc73406342a61b7d Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:04:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E8=A8=AD=E5=AE=9A=E3=81=8COFF=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AF?= =?UTF-8?q?=E3=80=81=E7=9B=B8=E8=AB=87=E9=83=A8=E5=B1=8B=E3=81=8B=E3=82=89?= =?UTF-8?q?=E3=81=AE=E3=83=A1=E3=83=BC=E3=83=AB=E9=80=9A=E7=9F=A5=E3=81=8C?= =?UTF-8?q?=E9=A3=9B=E3=81=B0=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/activity_mailer.rb | 2 ++ app/models/comment_notifier_for_admin.rb | 1 + test/mailers/activity_mailer_test.rb | 27 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/app/mailers/activity_mailer.rb b/app/mailers/activity_mailer.rb index 01a760233f2..d3e539dcf89 100644 --- a/app/mailers/activity_mailer.rb +++ b/app/mailers/activity_mailer.rb @@ -43,6 +43,8 @@ def came_comment(args = {}) @message ||= args[:message] @receiver ||= args[:receiver] + return unless @receiver.mail_notification + @user = @receiver link = "/#{@comment.commentable_type.downcase.pluralize}/#{@comment.commentable.id}" @link_url = notification_redirector_path( diff --git a/app/models/comment_notifier_for_admin.rb b/app/models/comment_notifier_for_admin.rb index f225c0e5c38..83d091cda88 100644 --- a/app/models/comment_notifier_for_admin.rb +++ b/app/models/comment_notifier_for_admin.rb @@ -6,6 +6,7 @@ def call(comment) User.admins.each do |admin_user| next if comment.sender == admin_user + next unless admin_user.mail_notification? commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable) ActivityDelivery.with( diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 2a573829e9a..44f599b68af 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -1099,4 +1099,31 @@ class ActivityMailerTest < ActionMailer::TestCase assert_equal '[FBC] 相談部屋でkomagataさんからコメントがありました。', email.subject assert_match(/コメント/, email.body.to_s) end + + test 'came_comment for admin with mail_notification off' do + ActionMailer::Base.deliveries.clear + + admin = users(:komagata) + admin.update(mail_notification: false) + + comment = comments(:commentOfTalk) + commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable) + + Notification.create!( + kind: Notification.kinds['came_comment'], + user: comment.receiver, + sender: comment.sender, + link: "#{commentable_path}#latest-comment", + message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。", + read: false + ) + + ActivityMailer.came_comment( + comment: comment, + message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。", + receiver: comment.receiver + ).deliver_now + + assert ActionMailer::Base.deliveries.empty? + end end From a757e926f61ff900f3f5852950b1e52ff305e180 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 20 Oct 2023 19:18:14 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Rubocop=E3=81=AE=E8=AD=A6=E5=91=8A=EF=BC=88?= =?UTF-8?q?=E6=9C=AB=E5=B0=BE=E3=81=AE=E7=A9=BA=E7=99=BD=E3=81=AE=E5=89=8A?= =?UTF-8?q?=E9=99=A4=EF=BC=89=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mailers/activity_mailer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 44f599b68af..f46e240503c 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -1102,7 +1102,7 @@ class ActivityMailerTest < ActionMailer::TestCase test 'came_comment for admin with mail_notification off' do ActionMailer::Base.deliveries.clear - + admin = users(:komagata) admin.update(mail_notification: false) From d603814253dbeaf2a9147025cf086bea9d9bf142 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 22 Oct 2023 10:46:33 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=81=A8=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/activity_mailer.rb | 2 +- app/models/comment_notifier_for_admin.rb | 1 - test/mailers/activity_mailer_test.rb | 27 ------------------------ 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/app/mailers/activity_mailer.rb b/app/mailers/activity_mailer.rb index d3e539dcf89..d210006d204 100644 --- a/app/mailers/activity_mailer.rb +++ b/app/mailers/activity_mailer.rb @@ -43,7 +43,7 @@ def came_comment(args = {}) @message ||= args[:message] @receiver ||= args[:receiver] - return unless @receiver.mail_notification + return unless @receiver.mail_notification? @user = @receiver link = "/#{@comment.commentable_type.downcase.pluralize}/#{@comment.commentable.id}" diff --git a/app/models/comment_notifier_for_admin.rb b/app/models/comment_notifier_for_admin.rb index 83d091cda88..f225c0e5c38 100644 --- a/app/models/comment_notifier_for_admin.rb +++ b/app/models/comment_notifier_for_admin.rb @@ -6,7 +6,6 @@ def call(comment) User.admins.each do |admin_user| next if comment.sender == admin_user - next unless admin_user.mail_notification? commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable) ActivityDelivery.with( diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index f46e240503c..2a573829e9a 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -1099,31 +1099,4 @@ class ActivityMailerTest < ActionMailer::TestCase assert_equal '[FBC] 相談部屋でkomagataさんからコメントがありました。', email.subject assert_match(/コメント/, email.body.to_s) end - - test 'came_comment for admin with mail_notification off' do - ActionMailer::Base.deliveries.clear - - admin = users(:komagata) - admin.update(mail_notification: false) - - comment = comments(:commentOfTalk) - commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable) - - Notification.create!( - kind: Notification.kinds['came_comment'], - user: comment.receiver, - sender: comment.sender, - link: "#{commentable_path}#latest-comment", - message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。", - read: false - ) - - ActivityMailer.came_comment( - comment: comment, - message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。", - receiver: comment.receiver - ).deliver_now - - assert ActionMailer::Base.deliveries.empty? - end end From 76ffe0fd65742f8c2129883db0c22545ed6a26b9 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:26:45 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E5=85=83=E3=80=85=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AE=E5=86=85=E5=AE=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mailers/activity_mailer_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 2a573829e9a..ef6bcc81e97 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -1099,4 +1099,19 @@ class ActivityMailerTest < ActionMailer::TestCase assert_equal '[FBC] 相談部屋でkomagataさんからコメントがありました。', email.subject assert_match(/コメント/, email.body.to_s) end + + test 'came_comment for admin with mail_notification off' do + admin = users(:komagata) + admin.update(mail_notification: false) + + comment = comments(:commentOfTalk) + + ActivityMailer.came_comment( + comment: comment, + message: "相談部屋で#{comment.sender.login_name}さんからコメントがありました。", + receiver: comment.receiver + ).deliver_now + + assert ActionMailer::Base.deliveries.empty? + end end