CSC/ECE 517 Fall 2020 - E2068. Refactor quiz questionnaires controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

This project contributes to Expertiza, an open-source project using Ruby on Rails. Expertiza is a platform for student learning that encourages active and cooperative learning while discouraging plagiarism.

Background

quiz_questionnaires_controller.rb is used in Expertiza to handle all functionality related to quizzes. A quiz is a type of questionnaire that allows reviewees to interact with their reviewers and making sure they read the submissions before reviewing. The student creating a quiz is supposed to ask questions related to their work, which, ideally, a reviewer should be able to answer. (If a reviewer cannot answer the questions about the reviewed work, then we might doubt the quality of that reviewer’s review.) This controller needs some changes as detailed below.

Issues

  1. Change the way min_question_score and max_question_score are set for @questionnaire on lines 39-40, as well as on lines 53-54.
    • These statements set the min and max scores to 0 and 1, respectively, regardless of what the user enters, which is not intended.
    • Change it so that the values are set according to what the user enters from the UI.
  2. Change the error message on line 78:
  3. Consider lines 259-265, different methods are called with the same parameters (question, choice_key, q_choices) to create different types of questions, depending on q_type.
  4. Make appropriate changes to tests so that they pass after the above changes.


Implementation

Min and Max Question Score

Current Implementation

Quizzes are created with a default minimum_ and maximum_question_score, which is the minimum or maximum score that can be obtained. The values are automatically set by the controller as 0 and 1, respectively. The final score of a quiz is calculated by multiplying the weight of the question by the score and summing the value of each question.

Problem(s)

Currently, minimum and maximum values cannot be set in a custom way per quiz.

Solution

Fields for minimum_question_score and maximum_question_score have been added to the form for creating each new quiz, and subsequently passed to the controller. The value is set per quiz, not per question. The values are not restricted.

Error Message on Line 78

Current Implementation

The original error message stated "Your quiz has been taken by some other students, you cannot edit it anymore."

Problem(s)

This error message is vague and can be easily misunderstood.

Solution

The error message now states "Your quiz has been taken by one or more students; you cannot edit it anymore."

Creating Questions

Current Implementation

When creating a quiz, there are currently three different methods for each of the three different question types: true-false, radio, and multiple choice.

Problem(s)

Radio and multiple choice implement very similar, almost duplicated, functionality in both methods.

Solution

Radio and multiple choice questions have been combined into a single method so as to remove the duplicated functionality. True-false questions will remain separate, because the functionality is significantly different. Future adjustments would require too many changes in the code and tests.

Files Involved

app/controllers/quiz_questionnaires_controller.rb
app/views/questionnaires/_quiz_questionnaire.html.erb
app/views/questionnaires/view.html.erb
spec/controllers/quiz_questionnaires_controller_spec.rb
app/views/questionnaires/_new_question_template.html.erb
app/models/questionnaire.rb

Code Modifications

The image below shows the addition of the min_/max_question_score fields to the quiz questionnaire form.



The image below shows the values from the form used in the controller.



The image below shows the creation of a single function to handle both types of multiple choice questions. It also shows that the new function is called in the save_choices function instead of calling both the original functions.



The image below shows changes necessary for assigning the correct answer for radio button multiple choice questions after making the changes from the previous image (the changes to the functions in the controller).

Test Plan

Testing for the quiz_questionnaires_controller already existed, this project added and altered test cases that were affected by our project's implementation.

Edge Cases

Edge Case Scenarios: Max and Min Question Score

  • min_question_score and max_question_score score being negative
  • max_question_score score being less than min_question_score

Handling Edge Cases: Max and Min Question Score

  • Create test for raising an error if min_question_score is less than zero
  • Create test for raising an error if max_question_score is less than one
    • Testing based on less than one since:
      • min_question_score should be less than max_question_score
      • min_question_score must be greater than zero
      • therefore, max_question_score must be greater one
  • Create test for raising an error if max_question_score is less than min_question_score

Related rspec Tests

#save_choices

 describe '#save_choices' do
   it 'is able to save different kinds of quiz questions' do {code}
  • This test verifies that the save_choices method in quiz_questionnaires_controller.rb functions correctly
    • save_choices contains calls to create_truefalse and create_multchoice
  • This corresponds to our changes with merging create_checkbox and create_radio methods into create_multchoice method

#create and #save

 describe '#create and #save' do
   context 'when questionnaire type is QuizQuestionnaire' do
       it 'redirects to submitted_content#edit page' do
  • This test verifies that a quiz with valid parameters can be created and saved correctly
    • This test case verifies that min_question_score and max_question_score error
   context 'when questionnaire type is QuizQuestionnaire and min_question_score value is negative' do
     it 'creates error: The minimum question score must be a positive integer.' do
  • This test verifies that quiz_questionnaires_controller.rb flashes an error when max_question_score is less than min_question_score
    • This handles an edge case scenario
   context 'when questionnaire type is QuizQuestionnaire and max_question_score value is negative' do
       it 'creates error: The maximum question score must be a positive integer.' do
  • This test verifies that quiz_questionnaires_controller.rb flashes an error when max_question_score and min_question_score are less than 0
    • This handles an edge case scenario
 describe '#create and #save' do
   context 'when questionnaire type is QuizQuestionnaire and max_question_score is less than min_question_score' do
     it 'creates error: The minimum question score must be less than the maximum.' do
  • This test verifies that the questionnaires.rb model raises an error when max_question_score is less than min_question_score
    • This handles an edge case scenario

Code Coverage

  • Coverage increased (+0.03%) to 42.982%
  • Coverage for related files
    • quiz_questionnaires_controller.rb 96.2%
    • questionnaire.rb 81.25%

Testing our Solutions

Running Tests

rspec spec/controllers/quiz_questionnaires_controller.rb

Testing Server

http://152.7.98.81:8080

The instructions below can also be found here with screenshots to follow along.

Creating New Assignment

  1. On the main menu, click on “Manage.” Note: If you click on "Assignments" from the drop down menu here, you will incur an error that is outside of the scope of our project.
  2. The following page will have a sub-menu for Courses, Assignments, and Questionnaires. Click on "Assignment."
  3. Click on the plus sign on the right side of the page to create a new assignment.
  4. Under the “General” tab, fill out the “Assignment Name,” select a course from the drop down menu, and check “has quiz.”
  5. Once you have filled out the form, click on the “Create” button at the bottom of the page to create the assignment.
  6. Once the assignment is created, a new field called “Number of Quiz questions” will be created on the right side of the page. Its default value will be 0. Change it to your desired number of questions. (Note: There are three different kinds of questions: Multiple Choice (four answer choices), Radio (four answer choices), and True-False. In order to test all answer possibilities, you can set this value to 17.)
  7. Click on the Due Dates tab.
  8. Set the dates for submission and review to any date after the current date.
  9. Click "Save."
  10. Under editing the assignment, click on the Other Stuff tab.
  11. Click on “Add Participant.”
  12. Add instructor6 as a participant.

Creating New Quiz

  1. On the main menu, go to the "Assignments" tab.
  2. This page will look similar to the Expertiza home page for the class. Find the assignment you just created under the “Tasks you have not yet started” list and click on it.
  3. On the assignment page, click on "Create New Quiz" under “Quiz.”
  4. Fill out the form. Once you select the type for each question, the view will update to allow you to enter your answer options. Remember these settings to check the correctness later. (Note: If you only provide one potential answer for the “Multiple Choice - Checkbox” option, the quiz will not be created and the entire form will clear.)
  5. Once you have filled out the entire form, click "Save" at the bottom of the page.
  6. You will be returned to the “Submit work for Assignment” page. There will be new options under “Quiz.” Click on “View Quiz.”
  7. This page should show all of the settings of your quiz, including correct answers, weight, and minimum and maximum question score.

Team Information

Colleen "Bria" Engen (ceengen)
Justin Kirschner (jkirsch)
Darby Madewell (demadewe)
Mentor: Sanket Pai (sgpai)

References