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

From Expertiza_Wiki
Revision as of 21:00, 14 November 2022 by Jlholle2 (talk | contribs) (Make text appear below image)
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

A team in spring 2022 attempted to refactor the controller as shown here. This revision modified 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, we began a new refactor which can be found here. This revision involved renaming methods, improving how teams were removed from the waitlist, and drying code. Some code was also moved to the Team model (team.rb).

This project is a continuation of our previous work and we will build upon our existing code changes.

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 comments describing the functionality of the following methods.

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

Issue 2 Dry Code

Here's one fix that needs to be done that can be used to enfore the DRY principle in these the list, create, and delete_all methods in teams_controller.rb. To fix this, we can extract the Object.const_get(session[:team_type] + ... ) to it's own method that can be used in all instances.

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.

The code to rescue a TeamExistsError can also be removed since there will no longer be a check that could potentially throw such an error.

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