Skip to content

Commit 7e3669b

Browse files
author
Tyson Brown
committed
Fix user_account_associations update for a restored enrollment
Test Plan 1) enroll a User in a Course 2) remove them from the Course 3) re-add them to Course * verify the User has a corresponding user_account_association again Change-Id: I37534ed332a964e65346976941ab0629847f316c Reviewed-on: https://gerrit.instructure.com/75433 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Tyson Brown <tbrown@instructure.com>
1 parent 766363c commit 7e3669b

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/models/enrollment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def should_update_user_account_association?
316316

317317
def update_user_account_associations_if_necessary
318318
return if self.fake_student?
319-
if id_was.nil?
319+
if id_was.nil? || (workflow_state_changed? && workflow_state_was == 'deleted')
320320
return if %w{creation_pending deleted}.include?(self.user.workflow_state)
321321
associations = User.calculate_account_associations_from_accounts([self.course.account_id, self.course_section.course.account_id, self.course_section.nonxlist_course.try(:account_id)].compact.uniq)
322322
self.user.update_account_associations(:incremental => true, :precalculated_associations => associations)

spec/models/enrollment_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,4 +2053,19 @@ def enrollment_dates_override_test
20532053
expect(@enrollment.readable_state_based_on_date).to eq :completed
20542054
end
20552055
end
2056+
2057+
describe "update user account associations if necessary" do
2058+
it "should create a user_account_association when restoring a deleted enrollment" do
2059+
sub_account = Account.default.sub_accounts.create!
2060+
course = Course.create!(:account => sub_account)
2061+
@enrollment = course.enroll_student(user)
2062+
expect(@user.user_account_associations.where(account: sub_account).exists?).to eq true
2063+
2064+
@enrollment.destroy
2065+
expect(@user.user_account_associations.where(account: sub_account).exists?).to eq false
2066+
2067+
@enrollment.restore
2068+
expect(@user.user_account_associations.where(account: sub_account).exists?).to eq true
2069+
end
2070+
end
20562071
end

0 commit comments

Comments
 (0)