CSC/ECE 517 Fall 2023 - E2373. Reimplement teams controllers.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including URLs and wiki pages.

Description of Project

The project involves a comprehensive restructuring of the teams_controller.rb file and the team.rb model within an application handling team functionalities in assignments or courses. The primary focus includes adhering to the Single Responsibility Principle (SRP) by reorganizing methods to have singular, focused tasks and separating team-copying functionalities. Additionally, the effort involves refining function names for better clarity and readability and enhancing comments across the codebase to improve understanding. This overhaul aims to optimize the codebase for maintainability and readability while preserving or enhancing the functionality of team-related operations in the application.

Problem Statement

The problem statement revolves around the inefficiencies and complexities present in the teams_controller.rb file and the team.rb model within an application managing team functionalities for assignments or courses. These inefficiencies primarily stem from violations of the Single Responsibility Principle (SRP), evident in functions that encompass multiple tasks and unclearly named functions that hinder code readability. Additionally, inadequate comments further exacerbate the code's readability issues. The challenge is to refactor these components, focusing on SRP compliance by restructuring methods, improving naming conventions for better understanding, and enhancing comments to facilitate code comprehension. The goal is to optimize the codebase for maintainability and readability while preserving or enhancing the functionality of team-related operations in the application.

Objectives

1. Single Responsibility Principle (SRP) Adherence

  • Refactor methods in teams_controller.rb and team.rb model to ensure each function has a singular, focused responsibility.
  • Separate team-related functionalities like copying between assignments/courses for better code organization.

2. Improved Naming Conventions

  • Rename ambiguous or confusingly named functions in both teams_controller.rb and team.rb for enhanced code readability and understanding.

3. Enhanced Comments and Documentation

  • Improve and add comments throughout the codebase to provide clearer explanations of complex functionalities and enhance overall code comprehension.
  • Document significant changes made during refactoring to aid future maintenance and development.

4. Code Refactoring and Consolidation

  • Identify and eliminate code repetitions across functions to streamline the codebase, enhancing maintainability and reducing redundancy.

5. Testing and Validation

  • Create or update unit tests to ensure the correctness and functionality of refactored methods in both the teams_controller.rb and team.rb model.
  • Conduct integration testing to verify the overall functionality of team-related operations post-refactoring.

The objectives aim to optimize the codebase by adhering to SRP principles, improving code readability through better naming conventions and comments, consolidating code where possible, and ensuring thorough testing for functionality validation.

Development Strategy

Our development strategy centers around Test-Driven Development (TDD) principles applied to refactoring the teams_controller.rb and team.rb model. Starting with the creation of failing test cases, we iteratively refactor code to address identified inefficiencies while ensuring successful test outcomes.

Additionally, we emphasize the adoption of a "Slim controller, Fat model" paradigm inspired by Rails conventions. Our goal is to migrate complex functionalities from the controller to the model, fostering a more organized and maintainable codebase. This approach not only enhances code clarity within the controller but also promotes reusability and scalability across the application.

Project Design and Implementation

Taking into account the current functionalities within the teams_controller.rb and team.rb model, our approach involves embracing the Strategy Pattern within the controller, capitalizing on its capability to encapsulate distinct controller actions. This strategic implementation aims to ensure seamless extensibility and enhanced usability. By employing this pattern, we establish a structured framework for defining and managing the diverse operations the controller handles, promoting a more organized and manageable code structure.

UML Diagram

Functionality

In this project, we aim to add functions for the following:

1. Refactoring for SRP:

  • Reorganizing code in teams_controller.rb and team.rb to adhere to the Single Responsibility Principle.

2. Naming and Comment Improvements:

  • Enhancing function and method names for clarity.

  • Adding and refining comments for better code comprehension.

3. Code Optimization:

  • Identifying and removing redundant code segments to streamline the codebase.

4. Testing and Validation:

  • Creating or updating tests to ensure the accuracy of refactored methods.
  • Conducting integration tests to verify overall functionality post-refactoring.

Testing Plan

We plan to employ RSpec for comprehensive testing of the teams_controller.rb and team.rb model. Leveraging FactoryBot, we'll construct the necessary test fixtures and models for thorough testing. Our approach involves utilizing the existing test skeleton provided while enhancing test coverage and minimizing code smells. Considering the current functionalities, our defined tests aim to validate the restructured code in the teams_controller.rb and team.rb model, verifying improved functionality and reduced code smells.

File: ./spec/controllers/teams_controller_spec.rb

Relevant Links

Github Repository: https://github.com/Naveen-Jayanna/expertiza

Team Members

  • Samarth Purushothaman
  • Naveen Jayanna
  • Arpit Choudhary

Mentor

Aditi Vakeel