CSC/ECE 517 Fall 2014/oss E1456 akk: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 40: Line 40:


=Code Snippets=
=Code Snippets=
The quiz questionnaire related methods such as view_quiz, update_quiz, new_quiz and validate_quiz are moved to questionnaire_helper.rb to make the questionnaires_controller thin and follow global rule of thin controllers and fat models.
1. The quiz questionnaire related methods such as view_quiz, update_quiz, new_quiz and validate_quiz are moved to questionnaire_helper.rb to make the questionnaires_controller thin and follow global rule of thin controllers and fat models.<br>
[[File:add_include_line.PNG|frame|center]]
[[File:add_include_line.PNG|frame|center]]
2. Non Restful method names changed accordingly to make them Restful. <br>
Before
After
[[File:after_refactoring_function_name_change.PNG|frame|center]]
3. Global rule changes for using Hash - value key pair
<pre>
Before Refactoring :-
def delete
.........
redirect_to :action => 'list', :controller => 'tree_display'
.........
After Refactoring :-
def delete
.........
redirect_to action: 'list', controller: 'tree_display'
.........
</pre>
=Conclusion=
=Conclusion=
*Refactoring was performed as per requirements in the files questionnaire_controller.rb, and advice_controller.rb.
*Refactoring was performed as per requirements in the files questionnaire_controller.rb, and advice_controller.rb.

Revision as of 22:48, 29 October 2014

Refactoring Questionnaire Controller

Introduction

Questionnaire Controller interacts with the user to create and edit questionnaires such as review rubrics, teammate-feedback rubrics, quizzes, and surveys. This page provides a detailed description of Open Source Project on Expertiza for refactoring the questionnaire controller.

Project Overview

Classes involved

  • questionnaire_controller.rb
  • questionnaire_helper.rb
  • advice_controller.rb

Changes made

  • Functionality moved to quiz_questionnaire.rb.
  • edit_advice method was not being used, so it was removed.
  • save_advice moved to the advice_controller.
  • copy, update_quiz, valid_quiz methods were long and have been broken up. clone_questionnaire_details was also broken up and renamed.
  • Added comments to select_questionnaire_type
  • Debug output (print statements) have been removed.
  • Changed code to follow the global rules.
  • save_new_questions, delete_questions, save_questions have been moved to a separate class.

Project Resources

GitHub Project Repository

VCL IP Address

Expertiza Wiki

UML CLass Diagram

A Subset of the UML class diagram including only the related classes for this project can be drawn as shown below.

Questionnaire Controller is the superclass of QuizQuestionnaire and all the other classes - User class, Advice class and Questionnaire classes are related Model Classes to the controllers that we have modified.

Participant Model

Code Snippets

1. The quiz questionnaire related methods such as view_quiz, update_quiz, new_quiz and validate_quiz are moved to questionnaire_helper.rb to make the questionnaires_controller thin and follow global rule of thin controllers and fat models.

2. Non Restful method names changed accordingly to make them Restful.

Before

After

3. Global rule changes for using Hash - value key pair

Before Refactoring :-
def delete
.........
redirect_to :action => 'list', :controller => 'tree_display'
.........
After Refactoring :-
def delete
.........
redirect_to action: 'list', controller: 'tree_display'
.........

Conclusion

  • Refactoring was performed as per requirements in the files questionnaire_controller.rb, and advice_controller.rb.
  • The code from models cannot be moved directly to controllers, so the code was moved to the helper class questionnaire_helper.rb.
  • Some methods with confusing method names have also been renamed.

References