include account groups in menu regardless of enrollments
account group memberships don't need a corresponding active enrollment to be displayed in the Courses & Groups menu. fixes #6008 Change-Id: I136f1b33ed650cc7a88eaefb7f72adc0e65486e0 Reviewed-on: https://gerrit.instructure.com/6344 Reviewed-by: Brian Palmer <brianp@instructure.com> Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
parent
b95a6a142c
commit
7a523474e4
|
@ -119,6 +119,7 @@ class GroupMembership < ActiveRecord::Base
|
|||
# provided enrollments
|
||||
def active_given_enrollments?(enrollments)
|
||||
state != :requested && state != :deleted &&
|
||||
enrollments.any?{ |e| e.user == self.user && e.course == self.group.context }
|
||||
(!self.group.context.is_a?(Course) ||
|
||||
enrollments.any?{ |e| e.user == self.user && e.course == self.group.context })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,6 +56,54 @@ describe GroupMembership do
|
|||
membership.should_not be_valid
|
||||
membership.errors[:user_id].should_not be_nil
|
||||
end
|
||||
|
||||
context 'active_given_enrollments?' do
|
||||
it 'should be false if the membership is pending (requested)' do
|
||||
course(:active_all => true)
|
||||
group = @course.groups.create
|
||||
student = user_model
|
||||
enrollment = @course.enroll_student(student)
|
||||
membership = group.add_user(student)
|
||||
membership.workflow_state = 'requested'
|
||||
membership.active_given_enrollments?([enrollment]).should be_false
|
||||
end
|
||||
|
||||
it 'should be false if the membership is terminated (deleted)' do
|
||||
course(:active_all => true)
|
||||
group = @course.groups.create
|
||||
student = user_model
|
||||
enrollment = @course.enroll_student(student)
|
||||
membership = group.add_user(student)
|
||||
membership.workflow_state = 'deleted'
|
||||
membership.active_given_enrollments?([enrollment]).should be_false
|
||||
end
|
||||
|
||||
it 'should be false given a course group without an enrollment in the list' do
|
||||
course(:active_all => true)
|
||||
group = @course.groups.create
|
||||
student = user_model
|
||||
enrollment = @course.enroll_student(student)
|
||||
membership = group.add_user(student)
|
||||
membership.active_given_enrollments?([]).should be_false
|
||||
end
|
||||
|
||||
it 'should be true for other course groups' do
|
||||
course(:active_all => true)
|
||||
group = @course.groups.create
|
||||
student = user_model
|
||||
enrollment = @course.enroll_student(student)
|
||||
membership = group.add_user(student)
|
||||
membership.active_given_enrollments?([enrollment]).should be_true
|
||||
end
|
||||
|
||||
it 'should be true for account groups regardless of enrollments' do
|
||||
account = Account.default
|
||||
group = account.groups.create
|
||||
student = user_model
|
||||
membership = group.add_user(student)
|
||||
membership.active_given_enrollments?([]).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def group_membership_model(opts={})
|
||||
|
|
Loading…
Reference in New Issue