CSC/ECE 517 Fall 2022 - E2254: Refactor teams controller.rb
Introduction
In this project we refactored teams_controller.rb and some tests associated with it. Before we worked on it, teams_controller.rb had some problems that violated some essential Rails design principles. Some methods have been moved to the teams.rb model class. Some duplicate code was removed. We added some comments for readability. And, we fixed tests to be more consistent with the program and execution.
Issues Fixed
- Added more comments and briefly explained the functionality of custom methods like
action_allowed
, andlist
- Changed method name of
create_teams
to a better name:random_teams
- Found areas in the code where the DRY principle can be applied and did so
- The delete method manipulates a waitlist! This needs to be done in a model class, e.g., SignedUpTeam. And also check if this code is already present in the model or not. Explore the code base to find where else waitlist is manipulated. ----- John if you could describe briefly what you did here that'd be great -----
- Removed all extra added gems
- Renamed variable signUps to signups because it's a noun
- Moved list copying code from the
inherit
method to be a class method of the Team model:copy_teams_to_collection
. Also replaced identical code in bequeath_all to also use this class method. - Changed the name of the
inherit
method tocopy_to_assignment
so the name is more descriptive of it's purpose - Removed nested if statments and removed other return points from bequeath_all
- Removed unnecessary comments for methods like
update
and added meaningful comments to other methods
Files Changed
- app/controllers/teams_controller.rb
- app/models/team.rb
- app/views/teams/new.html.erb
- config/locales/en_US.yml
- config/locales/en_IN.yml
- config/routes.rb
- spec/controllers/teams_controller.rb
- spec/controllers/airbrake_exception_errors_controller_tests_spec.rb