User:Mxu: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
CSC/ECE 517 Fall 2015 E1621: Refactor and test the quizzing feature
===CSC/ECE 517 Spring 2016 E1621: Refactor and test the quizzing feature===


= Introduction to Expertiza =
= 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 [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza GitHub]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.
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 [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza GitHub]. This application provides an efficient way to manage assignments, grades and reviews.


= Problem Statement =
= Problem Statement =
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.


== Classes involved ==
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.
*'''questionnaires_controller.rb'''
our own files in /specs/ folder.  


== What it does ==
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.
It does stuff


== What is wrong with it ==
A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]
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.


== What needs to be done ==
=Classes involved=
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:
* questionnaires_controller.rb
*Refactoring:
* quiz_quesetionnaire.rb
**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.
* quiz_question.rb
*Testing:
* quiz_question_choice.rb
**The instructor can set up an assignment which supports quizzing feature by
* spec/features/quiz_spec.rb
***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 =
=Use Case and Scenarios=
This project can be divided into major work items:
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.
#thing 1
#thing 2
#thing 3
#thing 4


= Implementation =
==Instructors are able to create and manage an assignment's quiz feature==
implementation details
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].


= Design =
* [S1] - When creating the assignment there is a checkbox labeled "has quiz." Checking this box creates an assignment that includes a quiz.
design
* [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.


== Use Cases ==
==Instructors can view quiz questions and scores from the tree view==
use cases
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].


= Accomplishments =
* [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.


Video demo of our work can be found at https://www.youtube.com/<br>
==Students can create and edit quizzes==
GitHub repository containing the refactoring changes can be found at https://github.com/<br>
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].
Link to the pull request to Expertiza is https://github.com/expertiza/expertiza/pull/


= Future Work =
* [S1] - A student may only create a quiz if they have not yet done so.
things to do in the future
* [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.
 
[[File:Expertiza_quiz_hierarchy.png|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 <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>.
 
===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 =
<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/>