CSC/ECE 517 Fall 2017/E1764 Refactor Grades Controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Expertiza Background

Expertiza is an educational web application for students to submit the articles, code, websites and peer-review learning objects. It is an open source project based on Ruby on Rails and developed by students for many years and keep refactoring and fixing bugs upon peer review.

Description of the current project

This project is to refactor grades controller which calculates the grades of assignment participants' from peer review and views of listing the scores. After refactor the previous work, it is the part of TLD that use RSpec to examine the correctness of functions and do the integration test.

Files modified in current project

1. grades_controller.rb
2. grades_controller_spec.rb

Grades_Controller

The main purpose of grades controller is to allow students and instructors to see grades and reviews through Expertiza, providing functions such as update scores, view teams, make chart and calculate penalties. Some functions were written in long and redundant way which makes it hard to understand and behaves inefficient. We extract some part of functions to become a helper function to make each function more clear and easier to understand. Besides, we slightly change some variable names by using more specific words to promote the readability.

Grades_Controller_Spec

Grades_controller_spec includes 10 Rspec tests for each function inside the grades_controller.rb. Some of the tests are integration tests and the rest are unit tests.

List of changes

1. Refactor make_chart method
2. Refactor calculate_penatly_attributes method
3. Refactor assign_all_penaties method
4. L136-138, L146-150: Refactor instructor_review method
5. L109: Use find_by instead of dynamic method
6. L178: Adjust the format of sprintf
7. Finish pending test in grades_controller_spec.rb

Solutions Implemented and Delivered

  • Refactor make_chart method

This is a function to make a bar chart based on the grades of participant. The original implementation contains lots of duplicated codes, so we extract the duplicated part out as a helper function called drop_decrement_from_scores. We make the type of participant scores as parameters such as metareview, feedback and teammate.

A helper function for make_chart method.

Testing Details

RSpec

Scope for future improvement