CSC/ECE 517 Spring 2023 - E2303 Refactor teams controller.rb
Expertiza
Expertiza is a Ruby on Rails based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.
Introduction
In this project we refactored teams_controller.rb and some tests associated with it. 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
- Refactored code in
teams_controller.rb
- Added more comments and briefly explained the functionality of all methods
- Found areas in the code where the DRY principle can be applied
- Refactored the function
bequeath_all
to improve readability by including functioncopy_teams
- Refactored function
copy_teams
that callschoose_copy_type
, which callsbequeath_copy
orinherit_copy
based on bequeath
- Refactored code in
teams.rb
- Added more comments to some methods in the code
- Made changes to
hi_IN.yml
file, by adding more annotations and some grammatical errors - Added more coverage to test by modifying
teams_controller_spec.rb
Files Changed
- app/controllers/teams_controller.rb
- app/models/teams.rb
- config/locales/hi_IN.yml
- spec/controllers/teams_controller_spec.rb
Changes
Fix #1
The code in teams_controller.rb for function bequath_all
was too long, which would make it unreadable. To achieve it, a function copy_teams
was added to the code.
# Handovers all teams to the course that contains the corresponding assignment # The team and team members are all copied. def bequeath_all if session[:team_type] == Team.allowed_types[1] flash[:error] = 'Invalid team type for bequeath all' redirect_to controller: 'teams', action: 'list', id: params[:id] else copy_teams(Team.team_operation[:bequeath]) end end
The function <code>copy_teams</code> is refactored further to improve it. The function <code>choose_copy_type</code> is refactored further to either perform <code>bequeath_copy</code> or <code>inherit_copy</code> based on team operation. <nowiki> # Method to abstract the functionality to copy teams. def copy_teams(operation) assignment = Assignment.find(params[:id]) if assignment.course_id choose_copy_type(assignment, operation) else flash[:error] = 'No course was found for this assignment.' end redirect_to controller: 'teams', action: 'list', id: assignment.id end # Abstraction over different methods def choose_copy_type(assignment, operation) course = Course.find(assignment.course_id) if operation == Team.team_operation[:bequeath] bequeath_copy(assignment, course) else inherit_copy(assignment, course) end end
Fix #2
This is Fix 2
Fix #3
This is Fix 3
Test Plan
This is Test Plan
Test Coverage
This is Test Coverage
Contributors
This project was done as part of Dr. Edward Gehringer's "CSC/ECE 517: Object-Oriented Design and Development" class, Spring 2023. The contributors were: Sasank Marabattula, Srilekha Gudipati and Varun Deepak Gudhe. Our project mentor was Divyang Doshi.