Skip to content

Commit

Permalink
Fix ordering of combined program enrollments
Browse files Browse the repository at this point in the history
The dataset version was not specifying an explicit order
(the eager version was), so which one came back first
(direct vs. indirect) was inconsistent.
  • Loading branch information
rgalanakis committed Nov 21, 2024
1 parent 82c3c9d commit 3bd6dd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/suma/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class ReadOnlyMode < RuntimeError; end
self.direct_program_enrollments_dataset.union(
self.program_enrollments_via_organizations_dataset,
alias: :program_enrollments,
).distinct(:program_id)
).order(:program_id, :member_id).
distinct(:program_id)
},
eager_loader: (proc do |eo|
eo[:rows].each { |p| p.associations[:combined_program_enrollments] = [] }
Expand Down
6 changes: 3 additions & 3 deletions spec/suma/member_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ def skip_verification?(c, list=nil)
it "filters combined enrollments having the same program" do
o = Suma::Fixtures.organization.with_membership_of(member).create
program = Suma::Fixtures.program.create
member_enrollment = Suma::Fixtures.program_enrollment.create(member:, program:)
org_enrollment = Suma::Fixtures.program_enrollment.create(organization: o, program:)

# Create the enrollments in a random order to ensure we don't depend on random/chance ordering
[{member:}, {organization: o}].shuffle.each { |p| Suma::Fixtures.program_enrollment.create(program:, **p) }
member_enrollment = member.direct_program_enrollments.first
# Prefer the member/direct enrollment over the org/indirect enrollment
expect(member.combined_program_enrollments_dataset.all).to have_same_ids_as(member_enrollment)
expect(Suma::Member.all.last.combined_program_enrollments).to have_same_ids_as(member_enrollment)
Expand Down

0 comments on commit 3bd6dd4

Please sign in to comment.