CSC/ECE 517 Fall 2015/oss E1560 PSV

From Expertiza_Wiki
Revision as of 06:07, 31 October 2015 by Pdeka (talk | contribs)
Jump to navigation Jump to search

E1560. Refactoring PopUpController.rb and ParticipantsController.rb

This page provides a description of the Expertiza based OSS project. This project is aimed at refactoring PopUpController.rb and ParticipantsController.rb.


Introduction to Expertiza

Expertiza is an Open Source Rails application which is used by instructors and students for creating assignments and submitting peer reviews. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. The Source code of the application can be cloned from Github.


Project Desicription<ref>https://docs.google.com/document/d/1uWs3zyrupTmrOFuv5IbVWCF4NRvCXqJmg8dZ0wCqgus/edit</ref>

Files involved:

popUpController.rb

participantsController.rb

What they do

PopUpController displays a review when a user (instructor or student) clicks on a list of reviews.

ParticipantsController handles participants in an assignment.

What's wrong with them:

PopUpController contains only two prominent methods, but they are very big.

ParticipantsController contains redundant code.

What needs to be done:

1 popUpController.rb

1.1 Action_allowed method always returns true. It needs to be fixed.

1.2 Team_user_popup method needs refactoring. @teamId is assigned but never used. Add comments to make code more readable. Rename variables based on their usage

1.3 Instance variables need to be changed to local variable wherever possible.

1.4 Refactor Participants_popup and team_users_popup methods into smaller private methods.

2 participantsController.rb

2.1 In add and update_authorization methods, permissions collection object can be used to reference its elements without assigning each element to individual private variables.

2.2 Inherit and bequeath_all methods are similar. Common statements can be migrated to private method. Add comments in code to make it easy to understand.

2.3 Cluster all the flash messages under one private method to make the code more manageable

2.4 Fix email_sent method. It contains a dummy email address.

Changes Made<ref>https://github.com/viveksubbarao/expertiza/commits/master</ref>

PopUpController.rb

Case 1.1: Modified Action_allowed method to return true only if ..

Before Refactoring After Refactoring
 

Case 1.2: Refactored Team_user_popup method

Before Refactoring After Refactoring
 

Case 1.3: Redundant instance variables changed to local variables

Before Refactoring After Refactoring
 

Case 1.4: Refactored Participants_popup and team_users_popup methods into smaller private methods

Before Refactoring After Refactoring
 

ParticipantsController.rb

Case 2.1: Permissions collection object referenced directly in add and update_authorization methods

Before Refactoring After Refactoring
def add
......
    permissions = Participant.get_permissions(params[:authorization])
    can_submit = permissions[:can_submit]   
    can_review = permissions[:can_review]
    can_take_quiz = permissions[:can_take_quiz]
    curr_object.add_participant(params[:user][:name],can_submit,can_review,can_take_quiz)
......
end
def add
......
    curr_object.add_participant(params[:user][:name], permissions[:can_submit], 
              permissions[:can_review], permissions[:can_take_quiz])
......
end

Case 2.2: Moved common functionality in Inherit and bequeath_all to private methods

Before Refactoring After Refactoring
 

Case 2.3: Flash messages clustered under a single private method

Before Refactoring After Refactoring
 

Case 2.4: Fixed email_sent method

Before Refactoring After Refactoring
 

References

<references/>