Skip to content

Commit

Permalink
Merge pull request #6506 from fjordllc/feature/active_delivery_use_in…
Browse files Browse the repository at this point in the history
…_hibernate_notification

休会通知をactive_delivery化する
  • Loading branch information
komagata authored May 17, 2023
2 parents fb6226d + bb9cfab commit 418f439
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/controllers/hibernation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions app/mailers/activity_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,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
8 changes: 0 additions & 8 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,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
Expand Down
10 changes: 0 additions & 10 deletions app/models/notification_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,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
Expand Down
1 change: 1 addition & 0 deletions app/views/activity_mailer/hibernated.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render '/notification_mailer/notification_mailer_template', title: "#{@sender.login_name}さんが休会しました。", link_url: @link_url, link_text: "#{@sender.login_name}さんのページへ" do
1 change: 0 additions & 1 deletion app/views/notification_mailer/hibernated.html.slim

This file was deleted.

24 changes: 24 additions & 0 deletions test/deliveries/activity_delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions test/mailers/activity_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,56 @@ class ActivityMailerTest < ActionMailer::TestCase
).deliver_now
assert_not ActionMailer::Base.deliveries.empty?
end

test 'hibernated using synchronous mailer' 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 using asynchronous mailer' 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
28 changes: 0 additions & 28 deletions test/mailers/notification_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,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)
Expand Down
7 changes: 7 additions & 0 deletions test/mailers/previews/activity_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,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
7 changes: 0 additions & 7 deletions test/mailers/previews/notification_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,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))
Expand Down

0 comments on commit 418f439

Please sign in to comment.