From b27aa74778864b7aef78ad1d57bdfe99ab3140ce Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Mon, 8 May 2023 15:43:08 +0900 Subject: [PATCH 1/7] =?UTF-8?q?active=5Fdelivery=E3=82=92=E5=B0=8E?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 2 +- app/mailers/activity_mailer.rb | 18 ++++++++++++++++++ app/views/activity_mailer/hibernated.html.slim | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/views/activity_mailer/hibernated.html.slim diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index c40bb42d8ea..ca32de380cd 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -44,7 +44,7 @@ def destroy_subscription! def notify_to_mentors_and_admins User.admins_and_mentors.each do |admin_or_mentor| - NotificationFacade.hibernated(current_user, admin_or_mentor) + ActivityDelivery.with(sender: current_user, receiver: admin_or_mentor).notify(:hibernated) end end diff --git a/app/mailers/activity_mailer.rb b/app/mailers/activity_mailer.rb index b0713fe4dfd..85678fc1bf6 100644 --- a/app/mailers/activity_mailer.rb +++ b/app/mailers/activity_mailer.rb @@ -253,4 +253,22 @@ def assigned_as_checker(args = {}) message end + + # required params: sender, receiver + def hibernated(args = {}) + @sender ||= args[:sender] + @receiver ||= args[:receiver] + + @user = @receiver + @link_url = notification_redirector_url( + link: "/users/#{@sender.id}", + kind: Notification.kinds[:hibernated] + ) + + subject = "[FBC] #{@sender.login_name}さんが休会しました。" + message = mail to: @user.email, subject: subject + message.perform_deliveries = @user.mail_notification? && !@user.retired? + + message + end end diff --git a/app/views/activity_mailer/hibernated.html.slim b/app/views/activity_mailer/hibernated.html.slim new file mode 100644 index 00000000000..f10f30c2465 --- /dev/null +++ b/app/views/activity_mailer/hibernated.html.slim @@ -0,0 +1 @@ += render '/notification_mailer/notification_mailer_template', title: "#{@sender.login_name}さんが休会しました。", link_url: @link_url, link_text: "#{@sender.login_name}さんのページへ" do From 7bbb622dc816a83110be4986ed86ddb42611bfcf Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Mon, 8 May 2023 15:44:18 +0900 Subject: [PATCH 2/7] =?UTF-8?q?active=5Fdelivery=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88=E3=81=AB=E4=BC=B4=E3=81=84?= =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E6=B6=88=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/notification_mailer.rb | 8 -------- app/models/notification_facade.rb | 10 ---------- app/views/notification_mailer/hibernated.html.slim | 1 - 3 files changed, 19 deletions(-) delete mode 100644 app/views/notification_mailer/hibernated.html.slim diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index a71ec2d193f..37446467fa2 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -101,14 +101,6 @@ def consecutive_sad_report subject: "[FBC] #{@report.user.login_name}さんが#{User::DEPRESSED_SIZE}回連続でsadアイコンの日報を提出しました。" end - # required params: sender, receiver - def hibernated - @user = @receiver - @notification = @user.notifications.find_by(link: "/users/#{@sender.id}", kind: Notification.kinds[:hibernated]) - subject = "[FBC] #{@sender.login_name}さんが休会しました。" - mail to: @user.email, subject: subject - end - # required params: sender, receiver def signed_up @user = @receiver diff --git a/app/models/notification_facade.rb b/app/models/notification_facade.rb index 16e77764f89..cdc846923f3 100644 --- a/app/models/notification_facade.rb +++ b/app/models/notification_facade.rb @@ -70,16 +70,6 @@ def self.consecutive_sad_report(report, receiver) ).consecutive_sad_report.deliver_later(wait: 5) end - def self.hibernated(sender, receiver) - ActivityNotifier.with(sender: sender, receiver: receiver).hibernated.notify_now - return unless receiver.mail_notification? - - NotificationMailer.with( - sender: sender, - receiver: receiver - ).hibernated.deliver_later(wait: 5) - end - def self.tomorrow_regular_event(event) DiscordNotifier.with(event: event).tomorrow_regular_event.notify_now end diff --git a/app/views/notification_mailer/hibernated.html.slim b/app/views/notification_mailer/hibernated.html.slim deleted file mode 100644 index 3f4a10ddaf6..00000000000 --- a/app/views/notification_mailer/hibernated.html.slim +++ /dev/null @@ -1 +0,0 @@ -= render 'notification_mailer_template', title: "#{@sender.login_name}さんが休会しました。", link_url: notification_url(@notification), link_text: "#{@sender.login_name}さんのページへ" do From 4e541a227132e7b6c697841cd2756a7bfce18772 Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Mon, 8 May 2023 16:06:05 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=81=E7=A7=BB=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/deliveries/activity_delivery_test.rb | 24 +++++++++++++++++++ test/mailers/activity_mailer_test.rb | 28 +++++++++++++++++++++++ test/mailers/notification_mailer_test.rb | 28 ----------------------- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/test/deliveries/activity_delivery_test.rb b/test/deliveries/activity_delivery_test.rb index 081f5377053..e6c310b663c 100644 --- a/test/deliveries/activity_delivery_test.rb +++ b/test/deliveries/activity_delivery_test.rb @@ -224,4 +224,28 @@ class ActivityDeliveryTest < ActiveSupport::TestCase ActivityDelivery.with(**params).notify(:assigned_as_checker) end end + + test '.notify(:hibernated)' do + user = hibernations(:hibernation1).user + params = { + sender: user, + receiver: users(:komagata) + } + + assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do + ActivityDelivery.notify!(:hibernated, **params) + end + + assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do + ActivityDelivery.notify(:hibernated, **params) + end + + assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do + ActivityDelivery.with(**params).notify!(:hibernated) + end + + assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do + ActivityDelivery.with(**params).notify(:hibernated) + end + end end diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 696e91c2fcb..1055134a185 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -696,4 +696,32 @@ class ActivityMailerTest < ActionMailer::TestCase ).deliver_now assert_not ActionMailer::Base.deliveries.empty? end + + test 'hibernated' do + user = users(:kimura) + mentor = users(:komagata) + Notification.create!( + kind: 19, + sender: user, + user: mentor, + message: 'kimuraさんが休会しました。', + link: "/users/#{user.id}", + read: false + ) + mailer = ActivityMailer.with( + sender: user, + receiver: mentor + ).hibernated + + perform_enqueued_jobs do + mailer.deliver_later + end + + assert_not ActionMailer::Base.deliveries.empty? + email = ActionMailer::Base.deliveries.last + assert_equal ['noreply@bootcamp.fjord.jp'], email.from + assert_equal ['komagata@fjord.jp'], email.to + assert_equal '[FBC] kimuraさんが休会しました。', email.subject + assert_match(/休会/, email.body.to_s) + end end diff --git a/test/mailers/notification_mailer_test.rb b/test/mailers/notification_mailer_test.rb index aaa80e4eb77..8bb0ad57f7c 100644 --- a/test/mailers/notification_mailer_test.rb +++ b/test/mailers/notification_mailer_test.rb @@ -152,34 +152,6 @@ class NotificationMailerTest < ActionMailer::TestCase assert_match(/入会/, email.body.to_s) end - test 'hibernated' do - user = users(:kimura) - mentor = users(:komagata) - Notification.create!( - kind: 19, - sender: user, - user: mentor, - message: 'kimuraさんが休会しました。', - link: "/users/#{user.id}", - read: false - ) - mailer = NotificationMailer.with( - sender: user, - receiver: mentor - ).hibernated - - perform_enqueued_jobs do - mailer.deliver_later - end - - assert_not ActionMailer::Base.deliveries.empty? - email = ActionMailer::Base.deliveries.last - assert_equal ['noreply@bootcamp.fjord.jp'], email.from - assert_equal ['komagata@fjord.jp'], email.to - assert_equal '[FBC] kimuraさんが休会しました。', email.subject - assert_match(/休会/, email.body.to_s) - end - test 'update_regular_event' do regular_event = regular_events(:regular_event1) notification = notifications(:notification_regular_event_updated) From 634f0892df83a090faac2fd0716ec97892787317 Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Mon, 8 May 2023 16:07:19 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AArubocop=E7=84=A1?= =?UTF-8?q?=E5=8A=B9=E5=8C=96=E3=82=92=E6=B6=88=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/notification_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 37446467fa2..80012ff8a57 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class NotificationMailer < ApplicationMailer # rubocop:disable Metrics/ClassLength +class NotificationMailer < ApplicationMailer helper ApplicationHelper before_action do From 3a91ad60e840951306a01e908f99913c9db96fdf Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Mon, 8 May 2023 16:42:24 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=93=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=82=92=E7=A7=BB=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mailers/previews/activity_mailer_preview.rb | 7 +++++++ test/mailers/previews/notification_mailer_preview.rb | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/mailers/previews/activity_mailer_preview.rb b/test/mailers/previews/activity_mailer_preview.rb index f8a6abb8468..88578aaaf61 100644 --- a/test/mailers/previews/activity_mailer_preview.rb +++ b/test/mailers/previews/activity_mailer_preview.rb @@ -107,4 +107,11 @@ def assigned_as_checker ActivityMailer.with(product: product, receiver: receiver).assigned_as_checker end + + def hibernated + sender = User.find(ActiveRecord::FixtureSet.identify(:hatsuno)) + receiver = User.find(ActiveRecord::FixtureSet.identify(:mentormentaro)) + + ActivityMailer.with(sender: sender, receiver: receiver).hibernated + end end diff --git a/test/mailers/previews/notification_mailer_preview.rb b/test/mailers/previews/notification_mailer_preview.rb index 704722998f8..91667ab9fa3 100644 --- a/test/mailers/previews/notification_mailer_preview.rb +++ b/test/mailers/previews/notification_mailer_preview.rb @@ -81,13 +81,6 @@ def graduated NotificationMailer.with(sender: sender, receiver: receiver).graduated end - def hibernated - sender = User.find(ActiveRecord::FixtureSet.identify(:hatsuno)) - receiver = User.find(ActiveRecord::FixtureSet.identify(:mentormentaro)) - - NotificationMailer.with(sender: sender, receiver: receiver).hibernated - end - def update_regular_event regular_event = RegularEvent.find(ActiveRecord::FixtureSet.identify(:regular_event1)) receiver = User.find(ActiveRecord::FixtureSet.identify(:hatsuno)) From 53c6f806ee99b586226046b22ef2b2cfbf729935 Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Thu, 11 May 2023 19:06:08 +0900 Subject: [PATCH 6/7] =?UTF-8?q?test:=20=E5=90=8C=E6=9C=9F=E7=89=88?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?/2=E3=81=A4=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7Paramet?= =?UTF-8?q?erized=E3=81=A8=E9=80=9A=E5=B8=B8=E7=89=88=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 1055134a185..9a55be8b599 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -698,6 +698,30 @@ class ActivityMailerTest < ActionMailer::TestCase end test 'hibernated' do + user = users(:kimura) + mentor = users(:komagata) + Notification.create!( + kind: 19, + sender: user, + user: mentor, + message: 'kimuraさんが休会しました。', + link: "/users/#{user.id}", + read: false + ) + ActivityMailer.hibernated( + sender: user, + receiver: mentor + ).deliver_now + + assert_not ActionMailer::Base.deliveries.empty? + email = ActionMailer::Base.deliveries.last + assert_equal ['noreply@bootcamp.fjord.jp'], email.from + assert_equal ['komagata@fjord.jp'], email.to + assert_equal '[FBC] kimuraさんが休会しました。', email.subject + assert_match(/休会/, email.body.to_s) + end + + test 'hibernated with params' do user = users(:kimura) mentor = users(:komagata) Notification.create!( From bb9cfab917d9db5a2ac69f13489bc8d5df29b1e9 Mon Sep 17 00:00:00 2001 From: YukiWatanabe824 Date: Thu, 11 May 2023 19:09:59 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E5=90=8C=E6=9C=9F=E7=89=88=E3=81=A8?= =?UTF-8?q?=E9=9D=9E=E5=90=8C=E6=9C=9F=E7=89=88=E3=81=AE=E3=81=A9=E3=81=A1?= =?UTF-8?q?=E3=82=89=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=81=8B=E3=82=8F=E3=81=8B=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E5=90=8D=E3=81=AB=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mailers/activity_mailer_test.rb b/test/mailers/activity_mailer_test.rb index 9a55be8b599..6d75e3bac71 100644 --- a/test/mailers/activity_mailer_test.rb +++ b/test/mailers/activity_mailer_test.rb @@ -697,7 +697,7 @@ class ActivityMailerTest < ActionMailer::TestCase assert_not ActionMailer::Base.deliveries.empty? end - test 'hibernated' do + test 'hibernated using synchronous mailer' do user = users(:kimura) mentor = users(:komagata) Notification.create!( @@ -721,7 +721,7 @@ class ActivityMailerTest < ActionMailer::TestCase assert_match(/休会/, email.body.to_s) end - test 'hibernated with params' do + test 'hibernated with params using asynchronous mailer' do user = users(:kimura) mentor = users(:komagata) Notification.create!(