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

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Background

In Expertiza, teams are used to allow students to work together in group projects. The teams controller is responsible for assigning students to teams, as well as performing CRUD operations. In this project we will refactor teams_controller.rb and add tests to increase test coverage. This project is a continuation of our previous work as described below, and we will build our existing code changes.

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).

Project Overview

There are several issues we plan to address as part of this project.

  • 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 its own method that can be used in all instances. By moving this code to its own method and replacing with the previous code, it will be following the DRY princple because there's less code being repeated.

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

Use Case Diagram

The teams controller is mainly responsible for dealing with the Team model. It can perform CRUD operations with teams and manage them on assignments and courses. It also has methods that can move the teams between them.

Test Plan

RSpec Tests

As mentioned for Issue 6, we plan to write several RSpec tests to increase test coverage of the teams_controller file by 10-20%. Specific test cases are list in the issue's section.

Manual Testing

Randomize Teams Testing

Given you are logged in as an instructor

  • Username: instructor6 Password password

And you are on the Manage Assignments page

When you click on create teams for an assignment with participants

And you click "Create Team"

And enter appropriate information

Then teams should be randomized and created

Bequeath all Testing

Given a team has been created for an assignment

And I am on the create teams page for an assignment

When I click "Bequeath All Teams"

Then I should be able to move the team from an assignment to a course

Course teams before bequeath all:

Course teams after bequeath all: