CSC/ECE 517 Fall 2019- Project E1946 Refactor Questionnaire Controller

From Expertiza_Wiki
Revision as of 23:57, 30 October 2019 by Ggarima (talk | contribs)
Jump to navigation Jump to search

E1946. Refactoring the Questionnaire Controller

This page provides a description of the Expertiza based OSS project.



About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

About Questionnaire Controller

Questionnaire is the superclass for all kinds of questionnaires and rubrics, rubrics is used for evaluating submissions and teammate contributions, and taking quizzes and surveys. All of these are subclasses of Questionnaire. This controller is used for creating, displaying, and managing Questionnaires. Different type of questionnaire can be created in Expertiza like Review, Metareview, Teammate review, Quiz Questionnaire, Global Survey, Course Survey and many more. This Controller is widely used and malfunctions can cause many issues in different parts of the system.

Why Refactor Questionnaire Controller

In Questionnaire controller below are some of the problems which needs refactoring:

  • Renaming the methods breaking Rubys naming conventions.
  • Refactoring the methods doing multiple tasks and breaking them in different modules.
  • Reducing the length of methods longer than 50 lines of code.
  • Removing the string literal values used in controller.
  • Separating the business logic from controller and putting it in method.
  • Remove variables behaving same as ruby's given functionality.
  • Commenting the code properly for easy understanding.

Files Modified

Below are the five file we changed as part of refactoring

Questionnaire Controller

This is the questionnaires_controller.rb which handles all the CRUD operation performed on any kind of questionnaire - review or surveys, add weightage to all questions, selecting type of questions. This controller holds the major part of work done for creating questions. Creating of questionnaire was one method which was extremely complicated and not well commented about what is going on. Multiple things were done in just one method which we broke in modules doing that specific task. This controller was holding the business logic as well, which we can move to model. Variables were created separate to get value from UI. At many places string literals were being hardcoded, which were made as constants.

Questionnaire Model

This is the questionnaire.rb model file and we have added self method in it, which will create questionnaire object for us and we will get that object in controller and process it in controller.

Questionnaire SPEC

This is the questionnaire_controller_spec.rb file and we have changed this file in order to test the changes we have made in Questionnaire controller.

Quiz Questionnaire Controller

This file is quiz_questionnaire_controller.rb and was calling multiple methods of quiz questionnaire by passing questionnaire id as parameter which we have removed.

Quiz Questionnaire SPEC

This is quiz_questionnaire_spec.rb was changed as we have removed questionnaire ID from methods in Quiz Questionnaire controller.

User Stories

We have used Github project board to keep track of work that needs to be refactored. Below were the user stories that we have created:

  • US1 - As a developer i want to analyze create questionnaire so that i can refactor and break it into modules.
  • US2 - As a developer i want to refactor the create_questionnaire method by giving it meaningful name and improving code so that it does not conflict with ruby naming standard.
  • US3 - As a developer i want to remove questionnaire_id with params[:id] so that we can remove unnecessary variables.
  • US4 - As a developer i want to remove all hardcoded values of alternatives, min label and max label and put them in literals, so that code can be aligned to coding standards.
  • US5 - As a developer i want to analyse why Questionnaire is being checked as QuizQuestionnaire multiple times and functionality is being changed, so that we can make quiz questionnaire same as rest.
  • US6 - As a developer i want to run rspecs in Questionnaire spec to so that i can make sure the changes made are working correct.
  • US7 - As a developer i want to run rspecs in Quiz Questionnaire spec to so that i can make sure the changes made are working correct.

Refactoring

Refactor Create Method

In this user story we created self method in questionnaire model which will create questionnaire object and pass it in controller. Self method was divided in to two different modules which we then called into self.

Method create_questionnaire_node(questionnaire) Method display_type_for_questionnaire(params) Self - Assigning all variable values from UI into questionnaire object + create_questionnaire_node(questionnaire) + display_type_for_questionnaire(params)

Refactor Create Questionnaire Method
Remove Unnecessary Variables=
Remove Hardcoded String Literals
Remove Unnecessary Checks
Update Questionnaire SPEC
Update Quiz Questionnaire SPEC

Scope for Improvement or Testing

Team Members

====Mentor==== Prof. Edward Gehringer

  • Garima Garima, Ggarima
  • Bharat Bhardwaj, Bbdhwaj
  • Piyush Tiwari, Piyushtiw

References

  1. Expertiza
  2. Expertiza GitHub
  3. Pull Request to Merge
  4. GitHub Project Board