User:Mxu: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by one other user not shown)
Line 5: Line 5:


= Problem Statement =
= Problem Statement =
The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by questionnaires_controller#valid_quiz. This method is rather long, involved, and does not take advantage of object-oriented practices. We will refactor the method to construct a quiz question object and then call valid? to check if the question is valid. This is an improvement over the current code which checks all questions manually.
The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by <code>questionnaires_controller.valid_quiz</code>. This method is rather long, involved, and does not take advantage of object-oriented practices. It combs through the parameters hash received from a request and manually checks all quiz fields, all question fields, all question choice fields, and verifies that each question has a correct choice.


In addition to this refactoring we will implement integration testing on the quiz feature to verify that the correct behavior is present.
We will refactor the method to construct a quiz questionniare and then call <code>valid?</code> to recursively validate the object tree using ActiveRecord validations. This is an improvement over the current code which checks all questions manually. The purpose of refactoring in this manner is to enhance readability, DRYness, and maintainability of Expertiza code.
 
In addition to this refactoring we will implement integration testing on the quiz feature to verify that the expected behavior is present for all use cases.


A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]
A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]


== Classes involved ==
=Classes involved=
* questionnaires_controller.rb
* questionnaires_controller.rb
* quiz_quesetionnaire.rb
* quiz_question.rb
* quiz_question_choice.rb
* spec/features/quiz_spec.rb
* spec/features/quiz_spec.rb


== What it does ==
=Use Case and Scenarios=
The purpose of this assignment is to enhance readability, DRYness, and maintainability of Expertiza code through refactoring and functional testing.
The Quiz Use Case allows for instructors to create and manage assignments where students may write quizzes for reviewers on materials they have submitted. See the following scenarios for a complete description of how the feature is expected to work.
 
==Instructors are able to create and manage an assignment's quiz feature==
An instructor chooses to create an assignment that has a quiz [S1]. While editing the assignment they may choose the number of quiz questions [S2] and set which phases students are allowed to take the quizzes [S3].
 
* [S1] - When creating the assignment there is a checkbox labeled "has quiz." Checking this box creates an assignment that includes a quiz.
* [S2] - When an assignment has a quiz there is an input field that accepts the number of questions that will be on each quiz. Setting this number appropriately changes the number of quiz questions.
* [S3] - Students may not take quizzes on a phase that does not allow them to do so. When on a stage that does allow for quizzes, they may take quizzes on work that they have reviewed.
 
==Instructors can view quiz questions and scores from the tree view==
After an assignment has been created the instructor may choose to view student quizzes from the tree view [S1]. While on the quiz view page they see student quizzes [S2] and student responses [S3].
 
* [S1] - The instructor may navigate to the list of assignments. Assignments with quizzes enabled will provide a link for the instructor to follow and view student quizzes.
* [S2] - The instructor shall be presented with the quiz title, questions, and answer choices. The correct answer choices will be in bold.
* [S3] - The score for each student who has taken the quiz shall be listed along with the average quiz score.
 
==Students can create and edit quizzes==
A student navigates to the assignment work page and chooses to create a new quiz [S1] or edit an existing one [S2]. By doing so they are able to choose a quiz title  and quiz questions [S3]. Invalid input results in an error message prompting the student to fix the issue [E1].
 
* [S1] - A student may only create a quiz if they have not yet done so.
* [S2] - A student may only edit a quiz if they have previously created one.
* [S3] - The quiz has the number of quiz questions defined by the instructor in the assignment.
 
* [E1] - Possible errors include:
** The quiz has no name.
** One or more questions is missing text.
** One or more choices is missing text.
** A question is missing a correct answer choice.
 
==Students can take quizzes on assignments they have reviewed==
A student decides to take a quiz [S1] on another team's assignment that they have previously reviewed. They select an artifact for review [S2] and fill in their answers. After submitting the quiz they can view their score on the take quizzes page [S3] and see question-by-question scores by clicking view [S4].


== What is wrong with it ==
* [S1] - The student may only take a quiz during a stage in which the assignment is configured to allow them to do so.
The valid_quiz method in questionnaires_controller needs to be refactored. This method should not check the questions one by one, instead, it should create the quiz_question objects and quiz_choice objects, then call “quiz_question.valid?” to check whether the question is valid.
* [S2] - Only quizzes from submissions they have reviewed are available.
* [S3] - The take quizzes page lists the final score for each quiz.
* [S4] - Choosing to view a quiz will show a student each question along with their answers and the correct answers.


== What needs to be done ==
=Design and Implementation=
Student-generated quizzes is the feature that students use for writing quizzes for the Wikipedia contribution assignment. In this project, you need to do refactoring and create functional tests for this feature:
Design for the refactoring has been driven by object oriented principles and test-driven-development, and makes use of the existing object hierarchy described in the following UML diagram.  
* Refactoring:
** Refactor the valid_quiz method in questionnaires_controller. This method should not check the questions one by one, instead, it should create the quiz_question objects and quiz_choice objects, then call “quiz_question.valid?” to check whether the question is valid.
* Testing:
** The instructor can set up an assignment which supports quizzing feature by
*** Checking the “has quiz” box
*** Setting the # of question for each set of quiz
*** Setting in which deadline can student reviewers take the quizzes
** Student authors can create quizzes and edit them:
*** They can create quizzes on the “Your work” page
*** They can edit the quiz questions.
*** They can view the quiz questions.
*** If the quiz question has something missing, the system will flash an error message, either:
**** The name of quiz is missing.
**** The question text is missing for one or more questions.
**** The choices are missing for one or more questions.
**** The correct answer(s) have not been provided.
** Student reviewers can take the quizzes on the work they have reviewed/they need to review
*** They need to request the artifact to review first. If this artifact has a quiz associated, they can take the quiz in the round which quiz-taking is allowed.
*** They can click “take quiz” then request quizzes to take.
*** They can fill in their choices on the quizzes.
*** After taking the quizzes, and submitting, they will see their grade on the “Take quizzes” page
*** On the “take quizzes” page, they can see their question-by-question scores for finished quizzes by clicking “view”
** Instructor can view the quiz questions and quiz scores on the tree display by clicking “view quiz questions” icon.


= Scope =
[[File:Expertiza_quiz_hierarchy.png|Expertiza Quiz Hierarchy]]
This project can be divided into major work items:


# Instructors is able to create and manage an assignment's quiz feature.
See the below sections for a part-by-part breakdown of the planned implementation for this project.
# Instructors can view quiz questions and scores from the tree view.
# Students can create quizzes and edit them.
# Students can take quizzes on assignments they have reviewed.
# Refactor questionnaires_controller#valid_quiz


= Implementation =
==Tests==
Quiz test will be added to spec/features/quiz_spec.rb and will make use of
Quiz tests will be added to the file spec/features/quiz_spec.rb and will make use of
* rspec
* rspec
* capybara
* capybara
* selenium
* selenium


Additionally, refactoring on questionnaires_controller may include the creation of the valid? method in app/models/quiz_question.rb.
Tests will be made which fully cover the expected behavior of each listed scenario in the Use Case.
 
==Refactoring==
Each of the following files will be refactored as described.


=Design=
===QuestionnaireController===
Design for the refactoring will be driven by object oriented principles and test-driven-development.
Refactor the <code>valid_quiz</code> method. It will be renamed to <code>validate_quiz</code> to more properly describe the action that occurs as a result of it being called. The behavior will be changed to construct a new quiz questionnaire with submitted questions wich will be validated using <code>quiz.valid?</code>.


==QuizQuestion==
===QuizQuestionnaire===
Implement a <code>validate</code> method that validates a quiz question for correctness including
The following fields will be validated using ActiveRecord validations.
* Has text
* Presence of name
* Has type
 
* Has all options
===QuizQuestion===
The following fields will be validated using ActiveRecord validations
* Presence of text
* Presence of type
* Has a correct answer
* Has a correct answer
** If radio only one correct answer
** If checkbox at least one correct anser
==QuizQuestionnaire==
Implement a <code>validate></code> method that validate a quiz and all of its questions for correctness including
* Has name


==QuestionnaireController==
===QuizQuestionChoice===
Refactor the <code>valid_quiz</code> method to construct a new quiz object with submitted questions. This quiz object will be validated using <code>quiz.validate</code>.
The following fields will be validated using ActiveRecord validations
* Presence of text


==Test Cases==
===Test Cases===
Implement unit test cases for each of the methods listed above.
In order to verify that refactoring has been done correctly and maintains the same external behavior, we will write test cases to the existing implementation. These test cases will be the ground truth of the validation feature. Refactored code will not be considered complete until all of these test cases once again pass.


= References =
= References =
<references/>
<references/>

Latest revision as of 01:38, 16 April 2016

CSC/ECE 517 Spring 2016 E1621: Refactor and test the quizzing feature

Introduction to Expertiza

Expertiza<ref>https://github.com/expertiza/expertiza</ref> is a project developed using Ruby on Rails<ref>http://guides.rubyonrails.org/getting_started.html</ref>. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews.

Problem Statement

The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by questionnaires_controller.valid_quiz. This method is rather long, involved, and does not take advantage of object-oriented practices. It combs through the parameters hash received from a request and manually checks all quiz fields, all question fields, all question choice fields, and verifies that each question has a correct choice.

We will refactor the method to construct a quiz questionniare and then call valid? to recursively validate the object tree using ActiveRecord validations. This is an improvement over the current code which checks all questions manually. The purpose of refactoring in this manner is to enhance readability, DRYness, and maintainability of Expertiza code.

In addition to this refactoring we will implement integration testing on the quiz feature to verify that the expected behavior is present for all use cases.

A full description of the assignment may be found here

Classes involved

  • questionnaires_controller.rb
  • quiz_quesetionnaire.rb
  • quiz_question.rb
  • quiz_question_choice.rb
  • spec/features/quiz_spec.rb

Use Case and Scenarios

The Quiz Use Case allows for instructors to create and manage assignments where students may write quizzes for reviewers on materials they have submitted. See the following scenarios for a complete description of how the feature is expected to work.

Instructors are able to create and manage an assignment's quiz feature

An instructor chooses to create an assignment that has a quiz [S1]. While editing the assignment they may choose the number of quiz questions [S2] and set which phases students are allowed to take the quizzes [S3].

  • [S1] - When creating the assignment there is a checkbox labeled "has quiz." Checking this box creates an assignment that includes a quiz.
  • [S2] - When an assignment has a quiz there is an input field that accepts the number of questions that will be on each quiz. Setting this number appropriately changes the number of quiz questions.
  • [S3] - Students may not take quizzes on a phase that does not allow them to do so. When on a stage that does allow for quizzes, they may take quizzes on work that they have reviewed.

Instructors can view quiz questions and scores from the tree view

After an assignment has been created the instructor may choose to view student quizzes from the tree view [S1]. While on the quiz view page they see student quizzes [S2] and student responses [S3].

  • [S1] - The instructor may navigate to the list of assignments. Assignments with quizzes enabled will provide a link for the instructor to follow and view student quizzes.
  • [S2] - The instructor shall be presented with the quiz title, questions, and answer choices. The correct answer choices will be in bold.
  • [S3] - The score for each student who has taken the quiz shall be listed along with the average quiz score.

Students can create and edit quizzes

A student navigates to the assignment work page and chooses to create a new quiz [S1] or edit an existing one [S2]. By doing so they are able to choose a quiz title and quiz questions [S3]. Invalid input results in an error message prompting the student to fix the issue [E1].

  • [S1] - A student may only create a quiz if they have not yet done so.
  • [S2] - A student may only edit a quiz if they have previously created one.
  • [S3] - The quiz has the number of quiz questions defined by the instructor in the assignment.
  • [E1] - Possible errors include:
    • The quiz has no name.
    • One or more questions is missing text.
    • One or more choices is missing text.
    • A question is missing a correct answer choice.

Students can take quizzes on assignments they have reviewed

A student decides to take a quiz [S1] on another team's assignment that they have previously reviewed. They select an artifact for review [S2] and fill in their answers. After submitting the quiz they can view their score on the take quizzes page [S3] and see question-by-question scores by clicking view [S4].

  • [S1] - The student may only take a quiz during a stage in which the assignment is configured to allow them to do so.
  • [S2] - Only quizzes from submissions they have reviewed are available.
  • [S3] - The take quizzes page lists the final score for each quiz.
  • [S4] - Choosing to view a quiz will show a student each question along with their answers and the correct answers.

Design and Implementation

Design for the refactoring has been driven by object oriented principles and test-driven-development, and makes use of the existing object hierarchy described in the following UML diagram.

Expertiza Quiz Hierarchy

See the below sections for a part-by-part breakdown of the planned implementation for this project.

Tests

Quiz tests will be added to the file spec/features/quiz_spec.rb and will make use of

  • rspec
  • capybara
  • selenium

Tests will be made which fully cover the expected behavior of each listed scenario in the Use Case.

Refactoring

Each of the following files will be refactored as described.

QuestionnaireController

Refactor the valid_quiz method. It will be renamed to validate_quiz to more properly describe the action that occurs as a result of it being called. The behavior will be changed to construct a new quiz questionnaire with submitted questions wich will be validated using quiz.valid?.

QuizQuestionnaire

The following fields will be validated using ActiveRecord validations.

  • Presence of name

QuizQuestion

The following fields will be validated using ActiveRecord validations

  • Presence of text
  • Presence of type
  • Has a correct answer

QuizQuestionChoice

The following fields will be validated using ActiveRecord validations

  • Presence of text

Test Cases

In order to verify that refactoring has been done correctly and maintains the same external behavior, we will write test cases to the existing implementation. These test cases will be the ground truth of the validation feature. Refactored code will not be considered complete until all of these test cases once again pass.

References

<references/>