CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for information regarding the changes made for the E2415. Reimplementation of responses controller.rb OSS assignment for Spring 2024, CSC/ECE 517.

Introduction

The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. A recent initiative under CSC/ECE 517 Spring 2024 - E2415, mentored by Ameya Vaichalkar, focused on the reimagination of the responses_controller.rb. This documentation encapsulates the efforts and methodologies employed in the reimplementation process, aligning with Rails' conventions and enhancing the application's functionality and maintainability.

Problem Description

The current ResponseController is notably lengthy and encompasses more than the essential CRUD operations. Notably, the edit method includes functionality for sorting reviews, a task that could be more appropriately handled within the Response model. The controller employs several methods, such as assign_action_parameters and set_content, to set parameters. While these methods help avoid code duplication, a more streamlined approach could further ensure that client methods readily access the required objects. The questionnaire_from_response_map method identifies the evaluation tool type—rubric, quiz, or survey—and adapts the review rubric based on the topic, indicating potential for simplification despite its complexity.

Reimplementation Objectives

The project's core objectives were manifold, aiming not only to adhere to contemporary Rails naming conventions but also to streamline and refactor the existing ResponseController for better clarity, functionality, and adherence to best practices. Key focus areas included:

  • Naming Conventions: Transitioning to pluralized controller names for consistency with Rails standards.
  • Refactoring for Clarity and Efficiency: Simplifying the overly complex ResponseController by separating concerns and reducing the bulk of non-CRUD operations.
  • Maintaining Robust Security Practices: Retaining up-to-date authentication and authorization methods without modification.
  • Optimizing Code Structure and Logic: Relocating functionalities such as review sorting and reviewer type checks to more appropriate locations within the model or through polymorphism.
  • Streamlining Parameter Setting: Consolidating methods like assign_action_parameters and set_content to ensure efficient access to required objects within the response model.
  • Enhancing Feedback Mechanisms: Keeping the creation of feedback responses within the controller, given its direct relation to Response objects.
  • Standardizing and Optimizing Item Sorting: Reducing redundancy in item sorting calls and aligning terminology with the standard term "item" rather than "question".
  • Simplifying Questionnaire Determination: Refining methods to decide the applicable rubric, survey, or quiz based on the response context.
  • Improving Email Notification System: Moving email generation related to responses to a helper module, thus centralizing and streamlining notification logic.

Method Reimplemented

The ResponsesController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods. To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application.

Model set_content method



  • Controller Renaming: The controller was renamed to responses_controller.rb, aligning with Rails conventions.
  • Code Refactoring: The controller was streamlined by relocating non-CRUD functionalities to the model or helper modules, such as sorting reviews and checking reviewer types.
  • Authentication and Authorization: These methods were preserved as-is, ensuring the application's security integrity.
  • Functionality Relocation: Sorting reviews was moved to response.helper, and type checks were implemented via polymorphism, eliminating the need for conditional checks in the controller.
  • Parameter Setting Optimization: The set_content method in the response model was enhanced to incorporate the functionalities of assign_action_parameters, simplifying object access.
  • Feedback Creation: The new_feedback functionality was refined to efficiently create and manage Response objects.
  • Item Sorting and Terminology: The term "question" was replaced with "item", and the item sorting logic was optimized to reduce redundancy.
  • Questionnaire Determination Simplification: The method was renamed to get_questionnaire_by_response, with logic simplified for clarity and efficiency.
  • Email Notification Refinement: Email-related methods were consolidated into the ResponseHelper, with new constructs like EmailObject and Mailer introduced for better organization.

Design and Implementation Details

During the reimplementation, the team employed various design patterns and refactoring strategies to achieve a cleaner, more maintainable codebase. Notably, the "Extract Method" pattern played a crucial role in breaking down complex methods into simpler, more understandable components. Additionally, the team focused on reducing cyclomatic complexity by dividing lengthy functions into smaller methods and adopting polymorphism to eliminate conditional checks.

File(s) Modified

  • responses_controller.rb
  • response_helper.rb
  • response_model.rb

Test Plan and Coverage

The project adopted Test-Driven Development (TDD) principles, ensuring that each new feature and refactoring effort was accompanied by comprehensive test cases. This approach not only facilitated the detection of potential issues early in the development cycle but also contributed to a robust and reliable codebase. Test coverage metrics were carefully monitored, with significant improvements observed in both the breadth and depth of the testing suite.

Relevant Links

  • GitHub Repository: Expertiza GitHub
  • Pull Requests: Detailed pull request for the reimplementation can be viewed here.

Team

Mentor

  • Ameya Vaichalkar (ameyav)

Contributors

  • Deana Franks
  • Maday Moya
  • Jacob Leavitt