User:Mister98/sandbox

This wiki page is for the description of changes made under E1602 OSS assignment for Spring 2016, CSC/ECE 517.

Introduction
Background

Expertiza is an open source project based on Ruby on Rails framework. Expertiza has a quizzing feature which allow student authors to create quiz questions and test the peer reviewers. The idea behind this i, if a reviewer can answer the quiz questions which were created by the author correctly, we assume that the reviewer has read the artifact carefully enough and thereby we trust the peer-review.

Current Implementation and Problems Changes Implemented
 * Following three different types of questions are supported in quizzing feature of Expertiza
 * 1) Multiple Choice Radio
 * 2) Multiple Choice Checkbox
 * 3) True/False
 * The current implementation of Quizzing feature is not consistent with the current questions and questionnaires. Since Quiz questionnaire is one sub type of questionnaire, so it should follow the design of other type of questionnaires. But, the current implementation is inconsistent with other questionnaires.
 * In order to create a quiz, the existing code is written in the views which has a series of if-then structures to implement the functionality of each different question type. This kind of implementation makes the code slower and violates the principles of MVC architecture.
 * Current HTML code doesn't looks like source code.
 * Code is repeated for different question types.
 * Proper Ruby naming conventions are not followed
 * All logic moved to model. Four separate methods - 'edit', 'view_question_text', 'complete' and 'view_completed_question' in order to generate the same html code for each of the question types. We used polymorphism by declaring all these methods in QuizQuestion class which inherits from Questions class and has sub-types MultipleChoiceRadio, MultipleChoiceCheckbox, and TrueFalse.
 * When questionnaire author creates a quiz, 'edit' method is called. To call this on UI, you can login as a student, click 'create quiz' / 'edit quiz' on 'Your Works' page. The 'edit' method is now called from /view/questionnaires/_quiz_question.html.erb
 * When questions are viewed by the author or the instructor, 'view_question_text' method is called. To call this on UI, you can either login as a student, click 'view quiz' on 'Ypur works' page or login as an instructor, find an assignment with quizzing feature and click the icon 'view quiz questions'. The 'view_question_text' calls view/questionnaires/view.html.erb


 * When the quiz takers tries to take the quiz, “complete” is called. To call this on UI, you can login as a quiz taker, request a quiz to take on “Take quizzes” page, then click “begin”. This method is now called on “view/student_quizzes/take_quiz”.
 * When the quiz taker finished taking a quiz and wants to view the quiz result again,  “view_completed_question” is called. To call this on UI, you can login as a quiz taker, find a finished quiz and click “view”. This method is called on “view/student_quizzes/finished_quiz”.
 * Using polymorphism and DRY principles, code repetition has been eliminated.

Refactoring complete
Logic is written in multiple_choice_checkbox model for multiple choice checkbox question type. Similarly, same process is followed for remaining question types. Now, to begin a quiz, complete method is called from the model.

Refactoring view_completed_question
The logic for viewing completed question and their answers is written in app/views/student_quizzes/finished_quiz.html.erb using a redundant if-elsif structure as shown below. The app/views/student_quizzes/finished_quiz.html.erb was refactored by removing the logic from the view and making it clean. We used a single construct which determines question type and answer type by calling view_completed_question method declared in quiz class as shown below. Similarly, logic was written in models for each of the question types. Following code snippet shows view_completed_question for true/false question type.

Remove irrelevant comments from the student_quizzes_controller
The student_quizzes_controller has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.