Permalink
Browse files

include previous complete submissions in quiz statistics csv

fixes #7497

test plan:
 * take a quiz as a student
 * retake the quiz, but don't submit it
 * the previous submission should be in the csv if Count All Attempts
   is clicked

Change-Id: I7b529f3d54c0dda5fa78b2d7128d63ecd8fea1ad
Reviewed-on: https://gerrit.instructure.com/9186
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
  • Loading branch information...
1 parent 631599c commit 6d1c5e089f53580848b21cac92db19c4421101af @ccutrer ccutrer committed with codekitchen Mar 5, 2012
Showing with 39 additions and 1 deletion.
  1. +2 −1 app/models/quiz.rb
  2. +37 −0 spec/models/quiz_spec.rb
View
@@ -744,10 +744,11 @@ def statistics_csv(options={})
columns << t('statistics.csv_columns.submitted', 'submitted')
columns << t('statistics.csv_columns.attempt', 'attempt') if options[:include_all_versions]
first_question_index = columns.length
- submissions = self.quiz_submissions.scoped(:include => (options[:include_all_versions] ? [:versions] : [])).select{|s| s.completed? && s.submission_data.is_a?(Array) && self.context.students.map(&:id).include?(s.user_id) }
+ submissions = self.quiz_submissions.scoped(:include => (options[:include_all_versions] ? [:versions] : [])).select { |s| self.context.students.map(&:id).include?(s.user_id) }
if options[:include_all_versions]
submissions = submissions.map(&:submitted_versions).flatten
end
+ submissions = submissions.select{|s| s.completed? && s.submission_data.is_a?(Array) }
submissions = submissions.sort_by(&:updated_at).reverse
found_question_ids = {}
quiz_datas = [quiz_data] + submissions.map(&:quiz_data)
View
@@ -504,6 +504,43 @@
stats[:submission_score_low].should == 15
stats[:submission_score_stdev].should be_close(Math::sqrt(4 + 2.0/9), 0.0000000001)
end
+
+ context 'csv' do
+ it 'should include previous versions even if the current version is incomplete' do
+ q = @course.quizzes.create!
+ q.quiz_questions.create!(:question_data => { :name => "test 1" })
+ q.generate_quiz_data
+ @user1 = User.create! :name => "some_user 1"
+ student_in_course :course => @course, :user => @user1
+ sub = q.generate_submission(@user1)
+ sub.workflow_state = 'complete'
+ sub.submission_data = [{ :points => 15, :text => "", :correct => "undefined", :question_id => -1 }]
+ sub.with_versioning(true, &:save!)
+ sub = q.generate_submission(@user1)
+ sub.save!
+
+ stats = FasterCSV.parse(q.statistics_csv(:include_all_versions => true))
+ stats.first.length.should == 3
+ end
+
+ it 'should not include previous versions even if not asked' do
+ q = @course.quizzes.create!
+ q.quiz_questions.create!(:question_data => { :name => "test 1" })
+ q.generate_quiz_data
+ @user1 = User.create! :name => "some_user 1"
+ student_in_course :course => @course, :user => @user1
+ sub = q.generate_submission(@user1)
+ sub.workflow_state = 'complete'
+ sub.submission_data = [{ :points => 15, :text => "", :correct => "undefined", :question_id => -1 }]
+ sub.with_versioning(true, &:save!)
+ sub = q.generate_submission(@user1)
+ sub.save!
+
+ stats = FasterCSV.parse(q.statistics_csv)
+ stats.first.length.should == 2
+ end
+
+ end
end
context "clone_for" do

0 comments on commit 6d1c5e0

Please sign in to comment.