Skip to content

Commit 805c20f

Browse files
author
Derek DeVries
committed
fix question counts for quizzes on index page
fixes CNVS-7357 test plan - make sure that the question counts are correct for both unpublished/published quizzes on the index page Change-Id: I7fdaa9d4d762455ad7caa2ac82282a98e8385811 Reviewed-on: https://gerrit.instructure.com/23053 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Stanley Stuart <stanley@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
1 parent 9ecd026 commit 805c20f

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

app/models/quiz.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ def question_count(force_check=false)
412412
end
413413
question_count || 0
414414
end
415-
415+
416+
def available_question_count
417+
published? ? question_count : unpublished_question_count
418+
end
419+
416420
# Returns data for the SAVED version of the quiz. That is, not
417421
# the version found by gathering relationships on the Quiz data models,
418422
# but the version being held in Quiz.quiz_data. Caches the result

lib/api/v1/quiz.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def quiz_json(quiz, context, user, session)
7878
hash = api_json(quiz, user, session, API_ALLOWED_QUIZ_OUTPUT_FIELDS).merge(
7979
:html_url => polymorphic_url([context, quiz]),
8080
:mobile_url => polymorphic_url([context, quiz], :persist_headless => 1, :force_user => 1),
81-
:question_count => quiz.question_count + quiz.unpublished_question_count,
81+
:question_count => quiz.available_question_count,
8282
:published => quiz.published?
8383
)
8484
locked_json(hash, quiz, user, 'quiz', :context => context)

spec/models/quiz_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,25 @@
323323
q.unpublished_question_count.should eql(3)
324324
end
325325

326+
it "should return an available question count for unpublished questions" do
327+
q = @course.quizzes.create!(:title => "new quiz")
328+
q.quiz_questions.create!
329+
q.quiz_questions.create!
330+
q.save
331+
332+
q.reload.available_question_count.should eql(2)
333+
end
334+
335+
it "should return an available question count for published questions" do
336+
q = @course.quizzes.create!(:title => "new quiz")
337+
q.quiz_questions.create!
338+
q.quiz_questions.create!
339+
q.save
340+
q.publish!
341+
342+
q.reload.available_question_count.should eql(2)
343+
end
344+
326345
it "should return processed root entries for each question/group" do
327346
q = @course.quizzes.create!(:title => "new quiz")
328347
g = q.quiz_groups.create!(:name => "group 1", :pick_count => 1, :question_points => 2)

0 commit comments

Comments
 (0)