Skip to content

Commit f3e4a89

Browse files
rivernatesimonista
authored andcommitted
move ungraded count checking to it's own class
fixes CNVS-12392 test plan: regression test on alerts for ungraded assignments Change-Id: I0ee553666706e91a96b953b1796578b834fd88b7 Reviewed-on: https://gerrit.instructure.com/33284 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
1 parent 8002734 commit f3e4a89

3 files changed

Lines changed: 103 additions & 11 deletions

File tree

app/models/alert.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,7 @@ def self.evaluate_for_course(course, account_alerts, include_user_notes)
157157
end
158158
end
159159
if criterion_types.include? 'UngradedCount'
160-
ungraded_counts = course.submissions.
161-
group("submissions.user_id").
162-
where(:user_id => student_ids).
163-
where(Submission.needs_grading_conditions).
164-
except(:order).
165-
count
166-
ungraded_counts.each do |user_id, count|
167-
student = data[user_id]
168-
student[:ungraded_count] = count
169-
end
160+
ungraded_count_alert = Alerts::UngradedCount.new(course, student_ids)
170161
end
171162
if criterion_types.include? 'UngradedTimespan'
172163
ungraded_timespans = course.submissions.
@@ -212,7 +203,7 @@ def self.evaluate_for_course(course, account_alerts, include_user_notes)
212203
break
213204
end
214205
when 'UngradedCount'
215-
if (user_data[:ungraded_count].to_i < criterion.threshold.to_i)
206+
if ungraded_count_alert.should_not_receive_message?(user_id, criterion.threshold.to_i)
216207
matches = false
217208
break
218209
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Alerts
2+
class UngradedCount
3+
4+
def initialize(course, student_ids)
5+
@ungraded_count_for_student = {}
6+
ungraded_counts = course.submissions.
7+
group("submissions.user_id").
8+
where(:user_id => student_ids).
9+
where(Submission.needs_grading_conditions).
10+
except(:order).
11+
count
12+
ungraded_counts.each do |user_id, count|
13+
@ungraded_count_for_student[user_id] = count
14+
end
15+
end
16+
17+
def should_not_receive_message?(user_id, threshold)
18+
(@ungraded_count_for_student[user_id].to_i < threshold)
19+
end
20+
21+
end
22+
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# Copyright (C) 2014 Instructure, Inc.
3+
#
4+
# This file is part of Canvas.
5+
#
6+
# Canvas is free software: you can redistribute it and/or modify it under
7+
# the terms of the GNU Affero General Public License as published by the Free
8+
# Software Foundation, version 3 of the License.
9+
#
10+
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12+
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13+
# details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License along
16+
# with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper.rb')
20+
21+
module Alerts
22+
describe Alerts::UngradedCount do
23+
24+
describe "#should_not_receive_message?" do
25+
before(:each) do
26+
course_with_teacher(:active_all => 1)
27+
@teacher = @user
28+
@user = nil
29+
student_in_course(:active_all => 1)
30+
@assignment = @course.assignments.new(:title => "some assignment")
31+
@assignment.workflow_state = "published"
32+
@assignment.save
33+
@opts = {
34+
submission_type: 'online_text_entry',
35+
body: 'submission body'
36+
}
37+
end
38+
39+
40+
it 'returns true when the student submissions are below the threshold' do
41+
42+
@assignment.submit_homework(@user, @opts)
43+
44+
ungraded_count = Alerts::UngradedCount.new(@course, [@student.id])
45+
ungraded_count.should_not_receive_message?(@student.id, 2).should == true
46+
end
47+
48+
it 'returns false when the student submissions are above or equal to the threshold' do
49+
second_assignment = @course.assignments.new(:title => "some assignment")
50+
second_assignment.workflow_state = "published"
51+
second_assignment.save
52+
53+
@assignment.submit_homework(@user, @opts)
54+
second_assignment.submit_homework(@user, @opts)
55+
56+
ungraded_count = Alerts::UngradedCount.new(@course, [@student.id])
57+
ungraded_count.should_not_receive_message?(@student.id, 2).should == false
58+
end
59+
60+
it 'returns true when the student has no submissions' do
61+
ungraded_count = Alerts::UngradedCount.new(@course, [@student.id])
62+
ungraded_count.should_not_receive_message?(@student.id, 2).should == true
63+
end
64+
65+
it 'handles submissions from multiple students' do
66+
student_1 = @student
67+
course_with_student({course: @course})
68+
student_2 = @student
69+
@assignment.submit_homework(student_1, @opts)
70+
@assignment.submit_homework(student_2, @opts)
71+
72+
ungraded_count = Alerts::UngradedCount.new(@course, [student_1.id, student_2.id])
73+
ungraded_count.should_not_receive_message?(student_1.id, 2).should == true
74+
end
75+
76+
end
77+
78+
end
79+
end

0 commit comments

Comments
 (0)