From 8b9e82ade848f556cdf21d8fff07dbff31306996 Mon Sep 17 00:00:00 2001 From: Ahmad Amireh Date: Thu, 5 Jun 2014 10:35:45 +0300 Subject: [PATCH] Quiz Stats - don't count teacher previews Exclude preview quiz submission from student analysis (item analysis was already accounting for this) based on the "was_preview" field. Closes CNVS-8203 TEST PLAN ---- ---- - create a quiz - take it as a preview by the teacher - request the stats from the API (or visit ember quiz stats) - verify that your attempt does not show up - take it by a student - verify everything is ok - now preview it again as a teacher - verify your attempt still doesn't add to the stats Change-Id: I62bf1dd6c0bedb26ee55d029ac0f015b2ad48e91 Reviewed-on: https://gerrit.instructure.com/35954 Tested-by: Jenkins Reviewed-by: Derek DeVries QA-Review: Clare Strong Product-Review: Derek DeVries --- .../quiz_statistics/student_analysis.rb | 2 +- .../quiz_statistics/student_analysis_spec.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/quizzes/quiz_statistics/student_analysis.rb b/app/models/quizzes/quiz_statistics/student_analysis.rb index e299c324a80..193ab16e91b 100644 --- a/app/models/quizzes/quiz_statistics/student_analysis.rb +++ b/app/models/quizzes/quiz_statistics/student_analysis.rb @@ -309,7 +309,7 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report #submissions from users for_users = quiz.context.student_ids scope = quiz.quiz_submissions.where(:user_id => for_users) - logged_out = quiz.quiz_submissions.logged_out + logged_out = quiz.quiz_submissions.logged_out.where('NOT was_preview') all_submissions = [] all_submissions = prep_submissions scope diff --git a/spec/models/quizzes/quiz_statistics/student_analysis_spec.rb b/spec/models/quizzes/quiz_statistics/student_analysis_spec.rb index 551d0996f9a..cb4a7345e69 100644 --- a/spec/models/quizzes/quiz_statistics/student_analysis_spec.rb +++ b/spec/models/quizzes/quiz_statistics/student_analysis_spec.rb @@ -316,6 +316,26 @@ describe Quizzes::QuizStatistics::StudentAnalysis do stats.last[9].should == "lolcats,lolrus" end + it 'should not count teacher preview submissions' do + teacher_in_course(:active_all => true) + q = @course.quizzes.create! + q.update_attribute(:published_at, Time.now) + q.quiz_questions.create!(:question_data => {:name => 'q1', :points_possible => 1, 'question_type' => 'multiple_choice_question', 'answers' => [{'answer_text' => '', 'answer_html' => 'zero', 'answer_weight' => '100'}, {'answer_text' => "", 'answer_html' => "

one

", 'answer_weight' => '0'}]}) + q.quiz_questions.create!(:question_data => {:name => 'q2', :points_possible => 1, 'question_type' => 'multiple_answers_question', 'answers' => [{'answer_text' => '', 'answer_html' => "lolcats", 'answer_weight' => '100'}, {'answer_text' => 'lolrus', 'answer_weight' => '100'}]}) + q.generate_quiz_data + q.save + qs = q.generate_submission(@teacher, true) + qs.submission_data = { + "question_#{q.quiz_data[0][:id]}" => "#{q.quiz_data[0][:answers][0][:id]}", + "question_#{q.quiz_data[1][:id]}_answer_#{q.quiz_data[1][:answers][0][:id]}" => "1", + "question_#{q.quiz_data[1][:id]}_answer_#{q.quiz_data[1][:answers][1][:id]}" => "1" + } + Quizzes::SubmissionGrader.new(qs).grade_submission + + stats = q.statistics + stats[:unique_submission_count].should == 0 + end + describe 'question statistics' do subject { Quizzes::QuizStatistics::StudentAnalysis.new({}) }