account notifications by role bugfix
specs were not catching the case where the notification was created by site admin intended for account roles on other accounts; as a result, a NoMethodError slipped through. This commit fixes the error and adds specs for this case Change-Id: Ie3b3659aacae277a30a6e59ee0e0833504c0cd67 Reviewed-on: https://gerrit.instructure.com/31840 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Anthus Williams <awilliams@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Anthus Williams <awilliams@instructure.com>
This commit is contained in:
parent
f30cd0546e
commit
2955ee76b8
|
@ -36,7 +36,7 @@ class AccountNotification < ActiveRecord::Base
|
|||
# announcements intended for users not enrolled in any courses have the NilEnrollment role type
|
||||
user_role_types[announcement.account_id] = ["NilEnrollment"] if user_role_types[announcement.account_id].empty?
|
||||
# roles user holds with respect to accounts
|
||||
user_role_types[announcement.account_id] |= user.account_users.with_each_shard{ |scope| scope.select(:membership_type).uniq.map(&:type) }.uniq
|
||||
user_role_types[announcement.account_id] |= user.account_users.with_each_shard{ |scope| scope.select(:membership_type).uniq.map(&:membership_type) }.uniq
|
||||
else #if announcement.account == account
|
||||
# roles user holds with respect to courses
|
||||
user_role_types[account.id] = user.enrollments_for_account_and_sub_accounts(account).map(&:type)
|
||||
|
|
|
@ -56,6 +56,18 @@ describe AccountNotification do
|
|||
AccountNotification.for_user_and_account(@admin, @account).map(&:id).sort.should == [@a1.id, @a2.id, @a3.id]
|
||||
AccountNotification.for_user_and_account(@student, @account).map(&:id).sort.should == [@a3.id]
|
||||
AccountNotification.for_user_and_account(@unenrolled, @account).map(&:id).sort.should == [@a2.id, @a3.id]
|
||||
|
||||
account_notification(:account => Account.site_admin, :roles => ["TeacherEnrollment","AccountAdmin"], :message => "Announcement 1")
|
||||
@a4 = @announcement
|
||||
account_notification(:account => Account.site_admin, :roles => ["NilEnrollment"], :message => "Announcement 2") #students not currently taking a course
|
||||
@a5 = @announcement
|
||||
account_notification(:account => Account.site_admin, :message => "Announcement 3") # no roles, should go to all
|
||||
@a6 = @announcement
|
||||
|
||||
AccountNotification.for_user_and_account(@teacher, Account.site_admin).map(&:id).sort.should == [@a4.id, @a6.id]
|
||||
AccountNotification.for_user_and_account(@admin, Account.site_admin).map(&:id).sort.should == [@a4.id, @a5.id, @a6.id]
|
||||
AccountNotification.for_user_and_account(@student, Account.site_admin).map(&:id).sort.should == [@a6.id]
|
||||
AccountNotification.for_user_and_account(@unenrolled, Account.site_admin).map(&:id).sort.should == [@a5.id, @a6.id]
|
||||
end
|
||||
|
||||
it "should allow closing an announcement" do
|
||||
|
|
Loading…
Reference in New Issue