-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slightly larger refactor to get notifications working again
- Loading branch information
Showing
13 changed files
with
237 additions
and
219 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../mailer/builds_grouping_mailer_message.rb → ...ices/mailer/build_group_mailer_message.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Notify | ||
class UseEmailToDeliverNotification | ||
def initialize | ||
@retrieves_slack_user_info = Slack::RetrievesSlackUserInfo.new | ||
@build_group_mailer_message = Mailer::BuildGroupMailerMessage.new | ||
end | ||
|
||
def call(notification, group) | ||
return unless notification.use_email? | ||
|
||
match = notification.historical_match | ||
|
||
member_users = match.members.map { |id| convert_to_match_member(id) } | ||
member_users.each do |user| | ||
mailer = @build_group_mailer_message.render( | ||
recipient: user, | ||
channel: group.slack_channel_name, | ||
grouping: match.grouping, | ||
other_members: member_users.reject { |u| u.email == user.email } | ||
) | ||
|
||
mailer.deliver_now | ||
end | ||
end | ||
|
||
private | ||
|
||
def convert_to_match_member(member_id) | ||
slack_user = @retrieves_slack_user_info.call(user: member_id) | ||
Mailer::MatchMember.from_slack_user(slack_user) | ||
end | ||
end | ||
end |
15 changes: 8 additions & 7 deletions
15
...ify/uses_slack_to_deliver_notification.rb → ...tify/use_slack_to_deliver_notification.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
spec/lib/notify/uses_email_to_deliver_notification_spec.rb
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
spec/lib/notify/uses_slack_to_deliver_notification_spec.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "test_helper" | ||
|
||
module Mailer | ||
class BuildGroupMailerMessageTest < ActiveSupport::TestCase | ||
setup do | ||
@retrieves_slack_user_info = Mocktail.of_next(Slack::RetrievesSlackUserInfo) | ||
@subject = BuildGroupMailerMessage.new | ||
end | ||
|
||
test "builds a mailer message for a group" do | ||
recipient = Mailer::MatchMember.new( | ||
email: "[email protected]", | ||
name: "Sherlock" | ||
) | ||
other_member = Mailer::MatchMember.new( | ||
email: "[email protected]", | ||
name: "John Watson" | ||
) | ||
|
||
mailer = @subject.render( | ||
recipient: recipient, | ||
grouping: "test_time", | ||
channel: "rotating-test", | ||
other_members: [other_member] | ||
) | ||
|
||
assert_equal ["[email protected]"], mailer.to | ||
assert_equal ["[email protected]"], mailer.from | ||
assert_equal ["[email protected]"], mailer.reply_to | ||
assert_equal "Test Time with John Watson", mailer.subject | ||
assert_match(/Howdy Sherlock/, mailer.body.to_s) | ||
assert_match(/You've been matched up with John Watson for Test Time from the #rotating-test Slack channel/, mailer.body.to_s) | ||
end | ||
end | ||
end |
Oops, something went wrong.