-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update supermentor role when changing mentored tracks (#6609)
* Update mentored tracks in command * Update supermentor role when updating mentored tracks
- Loading branch information
1 parent
ad4aeb1
commit 0653a73
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
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,10 @@ | ||
class Mentor::UpdateMentoredTracks | ||
include Mandate | ||
|
||
initialize_with :mentor, :tracks | ||
|
||
def call | ||
mentor.update!(mentored_tracks: tracks) | ||
User::UpdateSupermentorRole.defer(mentor) | ||
end | ||
end |
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,52 @@ | ||
require "test_helper" | ||
|
||
class Mentor::UpdateMentoredTracksTest < ActiveSupport::TestCase | ||
test "adds new mentored tracks" do | ||
mentor = create :user | ||
track = create :track | ||
|
||
assert_empty mentor.mentored_tracks | ||
|
||
Mentor::UpdateMentoredTracks.(mentor, [track]) | ||
|
||
assert_equal [track], mentor.mentored_tracks | ||
end | ||
|
||
test "keeps existing tracks" do | ||
mentor = create :user | ||
track = create :track | ||
updated_at = Time.current - 2.weeks | ||
track_mentorship = create(:user_track_mentorship, track:, user: mentor, updated_at:) | ||
|
||
assert_equal [track], mentor.mentored_tracks | ||
|
||
Mentor::UpdateMentoredTracks.(mentor, [track]) | ||
|
||
assert_equal [track], mentor.mentored_tracks | ||
assert_equal updated_at, track_mentorship.updated_at | ||
end | ||
|
||
test "removes tracks no longer being mentored" do | ||
mentor = create :user | ||
track = create :track | ||
updated_at = Time.current - 2.weeks | ||
track_mentorship = create(:user_track_mentorship, track:, user: mentor, updated_at:) | ||
|
||
assert_equal [track], mentor.mentored_tracks | ||
|
||
Mentor::UpdateMentoredTracks.(mentor, []) | ||
|
||
assert_empty mentor.mentored_tracks | ||
assert_raises ActiveRecord::RecordNotFound do | ||
track_mentorship.reload | ||
end | ||
end | ||
|
||
test "updates supermentor role" do | ||
mentor = create :user | ||
|
||
User::UpdateSupermentorRole.expects(:defer).with(mentor) | ||
|
||
Mentor::UpdateMentoredTracks.(mentor, []) | ||
end | ||
end |