CSC/ECE 517 Fall 2022 - E2274: Refactor teams controller.rb

From Expertiza_Wiki
Revision as of 20:47, 14 November 2022 by Jlholle2 (talk | contribs) (Add description of issue 3)
Jump to navigation Jump to search

Introduction

In this project we refactored teams_controller.rb and added tests associated with its functionality. Before we worked on it, teams_controller.rb had some minor parts of a few methods that could be improved. More comments can be added to improve the readability of methods in the file as well as code more understandable for what custom methods do. Furthermore, test coverage could be improved.

Previous Work

Prior work can be found here. This work was done in spring 2022, and it mainly consisted of refactoring a few methods such as delete, inherit, and bequeath_all. It also added new methods like init_team_type, get_parent_by_id, get_parent_from_child.

More recently, work was done by us from first part of the OSS project, which can be found here. This revision involved refactoring the methods like create_teams method, which involved renaming it to randomize_teams. The delete method was refactored to improve how teams were removed from the waitlist. The inherit method was also refactored to be renamed to copy_to_assignment and part of the code was moved to the custom method copy_teams_to_collection in Team model (team.rb). Furthermore, bequeath_all was also refactored to remove nested if statements and other returns so the method is easier to follow from looking at it.

Issues Being Worked on

  • More comments need to be added to the controller to briefly explain functionality of custom methods.
  • Find and fix any code where the DRY principle can be applied. Two places that will be taken a look at for this are the create and update methods.
  • Try to refactor the update method to make it cleaner.
  • There are few methods such as team_size, team_parent which will be removed.
  • Fix the code and Hindi text in config/locales/hi_IN.yml.
  • Add tests to increase test coverage by 10-20% if able.

Issue 1 Add Comments

We plan to add a comment describing the functionality of the following methods.

  • list
  • new
  • update
  • edit
  • delete_all
  • delete

Issue 2 Dry Code

Issue 3 Refactor Update

We will analyze the update function in teams_controller.rb to see how we could refactor it to improve functionality. For example, the update method current checks to see if there is an existing team with the same id as highlighted below, but this check is not needed when updating as the team should in fact already exist.

Issue 4 Remove Methods

We will analyze teams_controller to find unused or one-line methods such as team_size and team_parent and remove or refactor them to clean up the code. The goal of this task is to remove unused or extra code to make the controller easier to read and understand.

Issue 5 Update Translations

The code that may need to changed is highlighted below. The translation needs to be ensured that it is proper and the frontend needs to make sure that it's mapped to the correct phrase.

Issue 6 Test Coverage

Before starting this project, the teams controller is 79.8% covered. If all of the below tests are added, the controller reach at 100% coverage. We plan to at least add some of the tests as part of this project.

  • Create team when team exists
  • Update team when team exists
  • Update team when team doesn't exist
  • Delete all when child nodes exist
  • Copy to assignment when no course
  • List when team parent is a Course