CSC/ECE 517 Spring 2022 - E2216: Refactor late policies controller

From Expertiza_Wiki
Jump to navigation Jump to search

Background

The later policies controller file manages the SCRUM from late policies. Chiefly, the file checks if new or updated late policies are valid policies, in that they do not have the same name as an already existing policy, does not have a late penatly per unit time that surpasses the max late penalty, and does not have a late penalty surpassing 100.

Team Members

  • Wyatt Plaga (wgplaga@ncsu.edu)
  • Sujith Tumma (stumma2@ncsu.edu)
  • Shawn Salekin (ssaleki@ncsu.edu)

Description about project

This wiki describes the work done to refactor late_policies_controller.rb. The main focus of the work went into removing code duplication, as well as simplifying the code for readability, for the create and update methods. This also includes adding code comments for understandibility.

Files Involved

  • late_policies_controller.rb

Code Issues

1. All the late policies will show up on the index page, not just policies created by the current instructor. Need to create public & private late policies. Try to leverage code for private and public courses, assignments, and questionnaires.

2. create and update have some duplicate code. Fix that using a partial, _form.

3. Both create and update need comments and a better identifier naming.

4. Reduce code duplication. Find a way to make the code more DRY

5. Line 64: The if condition can be simplified.

6. Improve the variable name for same_policy_name. (Boolean variables can be named in a better way)

7. Add method comments

8. Find the use of instance variables in create and update method? Do we really need it? Can it be made local variables instead?

Code Changes

1. All the late policies will show up on the index page, not just policies created by the current instructor. Need to create public & private late policies. Try to leverage code for private and public courses, assignments, and questionnaires

Current code:

(No such code exists)

Modifications:

- add a column named 'private' on to the LatePolicy model
- In the controller#index method, filter the results by private != 0 or instructor_id = current_user_id

3. Both create and update need comments and a better identifier naming.

Current identifiers names:

invalid_penalty_per_unit (Problem with this is ,try to read "!invalid_penalty_per_unit". So, "valid_penalty" increases the readability. )
policy_name_exists

Modifications:

valid_penalty (This is a function to check the validity of the penalty.)
duplicate_name_check (This variable checks if the late policy name already exists.)


6. Improve the variable name for same_policy_name. (Boolean variables can be named in a better way)

Current identifiers names:

same_policy_name

Modifications:

Got rid of this identifier by replacing it with a function named "duplicate_name_check"

7. Add method comments

No comments

Modifications:

Added comments for all the methods to increase the readability of the code.

GitHub links

Link to Expertiza repository: here

Link to the forked repository: here