CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

E1836. Refactor quiz_questionnaires_controller.rb

Files involved: Questionnaires_controller.rb, (quiz_questionnaire.rb) What it does: Manages questionnaires and quiz. What is wrong with it: questionnaires_controller is a very complex file, it contains some method that should appear in the questionnaires model and for the method that manages quiz created should be in a separate controller. Some methods are way too long to understand, please break them down into pieces for better understanding. Also, the few instances of code duplication that exist should also be removed. What needs to be done: Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created. Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc. Write tests to test the code first Replace switch statements with subclasses methods Create models for the subclasses Remove hardcoded parameters, such as save_choice method