CSC/ECE 517 Spring 2023 - E2307. Refactor due date.rb class
Introduction
Expertiza is an online Ruby on Rails application that provides an interactive learning experience for instructors, teaching assistants as well as students. It provides several features like adding individual or team assignments, quizzes, self or peer assessment, topic selection in signup sheet, etc. One such feature is assigning different types of due dates for either assignments or for topic selection in signup sheets. There may be due dates for submitting assignments, reviewing other people’s assignments. In this project, we refactor the due_date.rb
class, which is responsible for all different due date related operations. We have also tried to employ design principles like SRP (Single Responsibility Principle)
and DRY (Do not Repeat Yourself) principle
while refactoring
Team Members
Kaushik Jadhav (unity_id: kajadhav, github: kaushikjadhav01)
Aditi Vakeel (unity_id: avakeel, github: aditi-v79)
Shivesh Madan Nath Jha (unity_id: sjha7, github: ShiveshJha12)
Mentor
Ankur Mundra (unity_id: amundra, github: amundra)
Problem Statement
due_date.rb
is a class model which is responsible for adding or modifying due dates of assignments or topics in signup sheets. It has two child classes: assignment_due_date.rb
for managing assignment due date operations and topic_due_date.rb
for managing topic due date operations. The code of the class, although pretty clean, still has room for improvement and needs to be refactored. For example, it has too much “code smell”, that is excessive use of class methods and few methods are either too long or otherwise violate design principles like SRP (Single Responsibility Principle)
and DRY (Do not Repeat Yourself) principle
in some way. This project involves resolving all such issues and refactoring due_date.rb
to improve readability as well as fixing existing test cases and adding a few new ones. The following section lists all issues resolved in this project
Issues
Issues and their progress/comments can be viewed in much more detail on our repository project board [1].
1. def self.default_permission: Class method, converted to instance method
2. def self.current_due_date: Class method, instantiated and moved to assignment.rb
. Also simplified logic and reduced the lines of code as per DRY (Do not Repeat Yourself) principle
.
3. def self.teammate_review_allowed: Class method, instantiated and moved to participant.rb
.
4. def set_flag: Redundant method, not being used anywhere and so safely removed
5. def due_at_is_valid_datetime: Can be completely removed and replaced by Rails built-in validation APIs
6. def self.set_duedate: Redundant method, not being used anywhere and so safely removed
7. def self.deadline_sort: Comparator operator was overridden and the method was no longer necessary, hence removed.
8. def self.done_in_assignment_round: Incorrect naming convention, incorrect location and way too complex logic. Moved to response_map.rb
, changed name to assignment_latest_review_round and reduced logic complexity using proper db query and efficient use of conditional statements so as to satisfy DRY (Do not Repeat Yourself) principle
.
9. def self.get_next_due_date: Class method and also violating the SRP (Single Responsibility Principle)
. Converted to instance method and moved to assignment.rb
. As it is supposed to have only one responsibility of getting the next due date, intermediate logic for getting all following assignment due dates were moved to a separate new method called upcoming_due_dates_after_topic_date
10. Codeclimate Issues: A total of 18 codeclimate rubocop issues listed on https://codeclimate.com/github/expertiza/expertiza/app/models/due_date.rb were also resolved.
Current codeclimate build has 0 issues: https://codeclimate.com/github/CSC-517-Spr23-kajadhav-avakeel-sjha7/expertiza/app/models/due_date.rb
Files Modified
app/controllers/student_teams_controller.rb
current_due_date and teammate_review_allowed were moved from DueDate to DueDateHelper. Updated method calls likewise.
app/helpers/assignment_helper.rb
self.default_permission of due_date.rb was converted to an instance method. So update method calls likewise.
app/models/assignment.rb
self.get_next_due_date of due_date.rb was converted to instance method and moved to assignment.rb. A new upcoming_due_dates_after_topic_date method was added to simplify get_next_due_date. The current_due_date method from due_date.rb was also instantiated and moved here.
app/models/due_date.rb
self.default_permission was converted to an instance method. current_due_date and teammate_review_allowed were moved to assignment.rb and participant.rb respectively. set_flag and set_duedate methods were redundant and hence were removed. due_at_is_valid_datetime was removed and replaced by built-in rails validation. deadline_sort comparator overwritten and method was simplified. done_in_assignment_round was renamed to assignment_latest_review_round and moved to response_map.rb.
app/models/participant.rb
teammate_review_allowed method was converted to instance method and moved here.
app/models/response_map.rb
done_in_assignment_round was renamed to assignment_latest_review_round, instantiated and moved here.
app/views/shared/responses/_response_actions.html.erb
app/views/sign_up_sheet/review_bids_others_work.html.erb
app/views/submitted_content/_self_review.html.erb
Rename method calls of done_in_assignment_round to assignment_latest_review_round
spec/lib/scoring_spec.rb
spec/models/assignment_spec.rb
spec/models/due_date_spec.rb
spec/models/review_response_map_spec.rb
spec/models/self_review_response_map_spec.rb
Fix existing tests and add new test cases.
Testing / Test Plan
Manual Testing
Along with the unit tests that we have written to test our files, we conducted a few system tests manually to verify the functionality works as expected
1. Create a new assignment and add due dates
2. Edit due dates of existing assignment
3. Add participants to assignment
4. Verify assignment dates in student login
5. Add team to assignment in student login before deadline
6. Submit Assingment before due date
7. Self Review before due date
8. Review Others after submission due date
9. Check scores after review due date ends
10. Add assignment with Sign Up Sheet and it's due dates
11. Choose topic in Sign Up Sheet before due date
12. Enable staggered deadlines and repeat all above tests
Automated Rspec Testing
To run the unit tests :
rspec spec/lib/scoring_spec.rb
rspec spec/models/assignment_spec.rb
rspec spec/models/due_date_spec.rb
rspec spec/models/review_response_map_spec.rb
rspec spec/models/self_review_response_map_spec.rb
Test Coverage
The Test Coverage was increased from an initial 75%
to 81.25%
Relevant Links
Github Repository: https://github.com/CSC-517-Spr23-kajadhav-avakeel-sjha7/expertiza
Pull Request: https://github.com/expertiza/expertiza/pull/2534
VCL Server: http://152.7.178.112:3000/
VCL Database: http://152.7.178.112/phpmyadmin/