CSC/ECE 517 Spring 2022 - E2217: Refactor questionnaires controller: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
Addition of constants to <code>scored_question.rb</code>: | Addition of constants to <code>scored_question.rb</code>: | ||
[[File:Scored_question_changes.png| | [[File:Scored_question_changes.png|upright]] | ||
*'''Problem''': Several methods have a <code>questionnaire_id</code> as a parameter, this may be unnecessary in several situations where <code>params[:id]</code> would suffice | *'''Problem''': Several methods have a <code>questionnaire_id</code> as a parameter, this may be unnecessary in several situations where <code>params[:id]</code> would suffice | ||
Line 24: | Line 24: | ||
Change of <code>questionnaire_id</code> to <code>params[:id]</code> in <code>save_all_questions</code>: | Change of <code>questionnaire_id</code> to <code>params[:id]</code> in <code>save_all_questions</code>: | ||
[[File:save_all_questions_changes.png| | [[File:save_all_questions_changes.png|upright]] | ||
*'''Problem''': Several bad <var>if</var> statements exist | *'''Problem''': Several bad <var>if</var> statements exist |
Revision as of 19:52, 17 March 2022
This page describes the changes made for the Spring 2022 OSS Project E2217: Refactoring Questionnaires Controller
Description
This project focused on sanding down the rough edges of questionnaires_controller.rb
through the removal of the unused create_questionnaire method, breaking up the exceedingly long create method, transfer of hardcoded values in the add_new_questions method, and general code cleanup.
Problems and Solutions
- Problem: The
create_questionnaire
method is not used.create_questionnaire
has no immediate apparent calls, and appears to have the same functionality ascreate
.- Solution:
- Problem: The
create
method is 49 lines long, and needs to be broken up- Solution:
- Problem: There are three checks for whether a question is a
QuizQuestionnaire
. These checks are likely unnecessary, and testing the class of an object carries potential problems.- Solution:
- Problem: There are assignment values hardwired into the code in
add_new_questions
. Although these fields are okay to default to the given values, these should be defined constants- Solution: As these values related to
ScoredQuestion
items, constants were created inscored_question.rb
.add_new_questions
now uses these class constants when assigning default values for fields. These values are all changeable in the UI after initialization.
- Solution: As these values related to
Addition of constants to scored_question.rb
:
- Problem: Several methods have a
questionnaire_id
as a parameter, this may be unnecessary in several situations whereparams[:id]
would suffice- Solution:
Change of questionnaire_id
to params[:id]
in save_all_questions
:
- Problem: Several bad if statements exist
- Solution:
Modified Files
(Add modified files and list of changes here)
Testing
Running Tests
rspec ./spec/controllers/questionnaires_controller_spec.rb
Future Improvements
Pull Request
GitHub link: https://github.com/expertiza/expertiza/pull/2320