CSC/ECE 517 Spring 2023 -E2326 Refactor questionnaires controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Background

In Expertiza, Questionnaire is the superclass for all kinds of questionnaires and rubrics—rubrics for evaluating submissions and teammate contributions, and taking quizzes and surveys. All of these are subclasses of Questionnaire. questionnaires_controller.rb is charged with creating, displaying, and managing Questionnaires. Because it is used so widely, malfunctions could cause bugs in many parts of the system; hence it is especially important that the code be clear.

Project Purpose

In recent years, questionnaires_controller.rb has been refactored repeatedly. It is a lot clearer than it used to be. But rough edges still remain. question.rb contains a large number of constants. It is not clear what they are used for. There is a questionnaires_controller, but no questions_controller. The questionnaires_controller creates Question objects. This is not elegant, because a controller should only create objects of one type, the type of objects it controls.

Design

Tushar

 #  File/Function Change Proposed Rationale Commit Link
1 Refactored the create The cur Will be added later
2 Used We refa Will be added later
3 Renamed variable names Some Will be added later
4 Added comments to other helper methods Some functions had no comments which were needed. Will be added later

Ani

questionnaires_controller.rb

- Update the Create Method as it's too long and needs to be refactored. One way to do this is by breaking it down into smaller, more manageable methods. we can create separate methods to handle different parts of the creation process, such as one method to handle validation, one method to handle saving the questionnaire to the database, etc.

- Update confusing names: To avoid confusion, it's important to give methods and controllers descriptive names that accurately reflect their functionality and if there is another method with a similar name that performs a similar function, it should be renamed to avoid confusion. Ex. Create and Create_Questionare

- Unused methods should be removed. ( ex. create_questionnaire)

- Magic Strings should be declared globally or as a configuration: Magic strings, or hard-coded string values in the code, can be difficult to maintain and debug. To avoid this, we can declare them globally or as a configuration in the application. This makes it easier to manage and update these values in one place.

Factory methods for question and questionare

- previous PRs employed the Factory method for questions and questionnaire object creation which can be used for more readable code.

- There are no default else conditions/ error checks in factories as of now.

Jacob

  • Comments still need to be removed in create function
  • questionnaire helper needs to be case statement by type (checking same object 'type')
  • question helper needs to be case statement by type (checking same object 'type')
  • save_all_questions

Problems and planned changes

problems and planned changes

Important links

Github: https://github.com/Soultrekker21/expertiza

Test Plan

test1
test2