-
-
Notifications
You must be signed in to change notification settings - Fork 199
fix: deduplicate members in chapter_students and chapter_coaches #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mroderick
merged 1 commit into
codebar:master
from
mroderick:fix/deduplicate-chapter-members
Apr 9, 2026
+71
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,69 @@ | ||||||
| require 'rails_helper' | ||||||
|
|
||||||
| RSpec.describe InvitationManager do | ||||||
| subject(:manager) { InvitationManager.new } | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Very minor in this test file, but in other cases, when it's repeated a lot in a test, it makes renaming classes more cumbersome. |
||||||
|
|
||||||
| let(:chapter) { Fabricate(:chapter) } | ||||||
| let(:member_in_both_groups) { Fabricate(:member, accepted_toc_at: Time.zone.now) } | ||||||
|
|
||||||
| describe '#chapter_students' do | ||||||
| context 'when a member has multiple subscriptions to the same group type' do | ||||||
| before do | ||||||
| students_group1 = Fabricate(:group, name: 'Students', chapter: chapter) | ||||||
| students_group2 = Fabricate(:group, name: 'Students', chapter: chapter) | ||||||
| students_group1.members << member_in_both_groups | ||||||
| students_group2.members << member_in_both_groups | ||||||
| end | ||||||
|
|
||||||
| it 'returns unique members' do | ||||||
| result = manager.send(:chapter_students, chapter) | ||||||
|
|
||||||
| expect(result.count).to eq(1) | ||||||
| expect(result).to contain_exactly(member_in_both_groups) | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| describe '#chapter_coaches' do | ||||||
| context 'when a member has multiple subscriptions to the same group type' do | ||||||
| before do | ||||||
| coaches_group1 = Fabricate(:group, name: 'Coaches', chapter: chapter) | ||||||
| coaches_group2 = Fabricate(:group, name: 'Coaches', chapter: chapter) | ||||||
| coaches_group1.members << member_in_both_groups | ||||||
| coaches_group2.members << member_in_both_groups | ||||||
| end | ||||||
|
|
||||||
| it 'returns unique members' do | ||||||
| result = manager.send(:chapter_coaches, chapter) | ||||||
|
|
||||||
| expect(result.count).to eq(1) | ||||||
| expect(result).to contain_exactly(member_in_both_groups) | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| describe 'sending invitations to members in both students and coaches groups' do | ||||||
| let(:workshop) { Fabricate(:workshop, chapter: chapter) } | ||||||
| let(:students_group) { Fabricate(:group, name: 'Students', chapter: chapter) } | ||||||
| let(:coaches_group) { Fabricate(:group, name: 'Coaches', chapter: chapter) } | ||||||
|
|
||||||
| before do | ||||||
| students_group.members << member_in_both_groups | ||||||
| coaches_group.members << member_in_both_groups | ||||||
| end | ||||||
|
|
||||||
| it 'sends one invitation per role when audience is everyone' do | ||||||
| expect(WorkshopInvitation).to receive(:find_or_create_by) | ||||||
| .with(workshop: workshop, member: member_in_both_groups, role: 'Student') | ||||||
| .and_call_original | ||||||
| .once | ||||||
|
|
||||||
| expect(WorkshopInvitation).to receive(:find_or_create_by) | ||||||
| .with(workshop: workshop, member: member_in_both_groups, role: 'Coach') | ||||||
| .and_call_original | ||||||
| .once | ||||||
|
|
||||||
| manager.send_workshop_emails(workshop, 'everyone') | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ergonomics: I assume it'd be possible to have a
describe "handling deduplication"block, wrapping these test cases, and placing them in a spec/models/invitation_manager_spec.rb, so that "flipping between test and implementation" works in an expected way.