CSC/ECE 517 Spring 2022 - E2225: Refactor review mapping helper.rb

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for the description of changes made under E2225 OSS assignment for Fall 2022, CSC 517.

Expertiza Background

Expertiza is an educational web application created and maintained by the joint efforts of the students and the faculty at NCSU. It’s an open source project developed on Ruby on Rails platform and it’s code is available on Github. It allows students to review each other’s work and improve their work upon this feedback.

Background

A helper method in Ruby performs certain repetitive tasks across multiple classes or a singular class, so that code is not reused and redundancy is reduced. The review_mapping_helper.rb file is primarily used to perform routine tasks with reviews. Tasks such as returning the user's name instead of the team name when there is a single person in the team, checking whether the work has been submitted within the given round and sorting the reviewers by average number of reviews in each round. Each of these functions' visibility is dependent on the type of user.

Team Members

  • Ankur Mundra (amundra@ncsu.edu)
  • Shruti Magai (smagai@ncsu.edu)
  • Sudharsan Janardhanan (sjanard@ncsu.edu)


Files modified in current project

A helper file has been modified for this project namely:

1. review_mapping_helper.rb
2. /reports/_feedback_report.html.erb
3. spec/helpers/review_mapping_helper_spec.rb


List of changes

We worked on the following work items(WIs)
WI1 : Refactor get_team_color method to reduce cognitive complexity
WI2 : Refactor check_submission_state to reduce cognitive complexity
WI3 : Improved assignment branch condition of method get_awarded_review_score
WI4 : Refactored review_metrics method to reduce cognitive complexity
WI5 : Refactored calculate_key_chart_information to reduce complexity
WI6 : Added top level class documentation and corrected indentation
WI7 : Updated method names for method name too long issue


Solutions Implemented and Delivered

1. Refactoring get_team_color method

This method retrieves the team's color according to the state of the review and assignment status

The initial method consisted of an if clause with multiple if-else statements nested inside.
We refactored the code and utilized the unless statement to make the code ruby friendly.

Initial code:

Refactored code:


2. Refactoring check_submission_state method

The initial method consisted of an if clause with multiple if-else statements nested inside.
We refactored the code and used inline if conditions to make the code more concise.

Initial code:

Refactored code:

3.Refactoring get_awarded_review_score to reduce the Assignment Branch Condition size

Assignment Branch Condition size for get_awarded_review_score was too high. Reduced the ABC size to make the method more readily understood, more reusable and more testable.

4. Refactoring review_metrics method

We utilize the unless statement to return an empty value if there is no review associated with a given team, eliminating the use of if statements in favor of ruby styled code.

Refactored code:

5. Refactored calculate_key_chart_information to reduce complexity

Used a guard clause instead of wrapping the code inside a conditional expression. Having simplicity, atomic definitions and eager return statements are ways to keep the code base concise.

6. Top level documentation and corrected indentation

We've added top level documentation to describe the functionality of classes such as the ReviewStrategy class, StudentReviewStrategy class and TeamReviewStratregy class.
Ruby style guidelines dictate that 2 spaces be used instead of tabs. We've performed these changes throughout the document.

7. Method name too long issue

Changed the name of the method get_each_review_and_feedback_response_map method to get_each_review_and_feedback and get_certain_review_and_feedback_response_map was changed to get_certain_review_feedback.

Test Plan

Manual UI Testing

As mentioned previously, the function of the review_mapping_helper file is to ease the responsibilities of the review_mapping_controller. Repetitive tasks such associated with the review controller are performed in this helper file. The video embedded below provides the UI testing performed on the helper method.

Link to UI Test

RSpec Unit Tests

As a result, no functionality in any function has changed; only refactoring has taken place. All of the refactoring was thoroughly tested using rspec tests. Run the following command to run the spec file: rspec spec/controllers/review mapping controller spec.rb. No functionality was broken as a result of the refactoring. Adding additional testcases is out of the question since this is primarily a refactoring project since no additional methods were added. As we can see from the image below, running spec/helpers/review_mapping_helper_spec.rb command, we pass all test cases