CSC/ECE 517 Fall 2016/E1635. Refactor join team requests controller.rb and invitation controller.rb

From Expertiza_Wiki
(Redirected from User:Ssethur2)
Jump to navigation Jump to search

E1635. Refactor invitations controller.rb

This page provides a description of the Expertiza based OSS project.

About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

Problem Statement

The following tasks were accomplished in this project:

  • Renamed the "invitation_controller.rb" to "invitation_controller.rb"
  • For simple if nested in else, we changed it to elsif and thus decreased number of layers in the if nest.
  • For added comments to explains what each method does and explaining important variables
  • refactored the create and update methods
  • changed the wordings of the flash messages to make them more meaningful

InvitationController

  • Rename to invitations_controller.rb, in accordance with current naming convention.
  • Convert if nested inside else to elsif.
  • Add comments explaining what each method does, and comments on how important variables are used.
  • Refactor create and accept methods. Shorten and clarify them by adding private methods (e.g. extract a ready_to_join? method and call it from accept method)
  • Change awkward flash messages.


Refactoring Implementation

1. Convert if nested inside else to elsif, and add comments explaining what each method does, and comments on how important variables are used.

The if else can extract from multiple nest to one.

There have two different functions in one nest, one is flash and another is invitation check.

Divided two different purpose to two if else nest.


2. Refactoring the accept method

JoinTeamRequestsController

  • Add comments on some important variables.
  • Convert if nested inside else to elsif
  • Remove duplicate code: Common code in index, show and new method are moved into a private method.
  • Create and update do not share any code. This raises the spectre of DRY problems. Make sure that all functionality used in creating a request is available when editing a request, and that no code is duplicated.
  • Fix wording of message.


Refactoring Implementation

1. Refactoring into small private method

Move the duplicated code into private method


2. Convert if nested inside else to elsif in the create function. This part of the code is moved into a separate function. There are lots of redundant code in the following snippet.

Extracted the flash function from rendering form.

Extracted the trivial if else function to make create function clear and more efficient.


3. add before_action to remove the duplicated code for find(params[:id])