CSC/ECE 517 Fall 2015/oss E1561 WZL
E1561. Refactoring due_date.rb and deadline_helper.rb
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring due_date.rb and deadline_helper.rb.
Introduction to Expertiza
Expertiza is a Open Source Rails application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. This Open Source application can be cloned from Github, the latest active branch is "Rails 4".
Project Desicription<ref>https://docs.google.com/document/d/1uWs3zyrupTmrOFuv5IbVWCF4NRvCXqJmg8dZ0wCqgus/edit</ref>
Files involved:
due_date.rb response_controller.rb deadline-helper.rb sign_up_sheet.rb
What it does: Manages the deadlines of an assignment, setting due dates for an assignment, copying due dates from one assignment to a new assignment etc.
What's wrong with it:
- It has methods making unnecessary DB calls.
- It contains duplicated methods.
What needs to be done: There are 5 major goals for this project:
- Remove
DueDate.assign_topic_deadline
and useDeadlineHelper.create_topic_deadline
method wherever possible.
- Create a new method for sort in
due_date.rb
and invoke it from places used indue_date.rb
andresponse_controller.rb
.
- Rename
setFlag()
to adhere to Rails naming conventions.
- Refactor
DueDate.default_permission
.
- Refactor
DeadlineHelper.set_start_due_date
method to smaller methods.
Modification
Case 1: Remove DueDate.assign_topic_deadline
and use DeadlineHelper.create_topic_deadline
DueDate.assign_topic_deadline
method which is same as DeadlineHelper.create_topic_deadline
method.
DueDate.assign_topic_deadline Method | DeadlineHelper.create_topic_deadline Method |
---|---|
def self.assign_topic_deadline(due_date,offset,topic_id) topic_deadline = TopicDeadline.new topic_deadline.topic_id = topic_id topic_deadline.due_at = DateTime.parse(due_date.due_at.to_s) + offset.to_i topic_deadline.deadline_type_id = due_date.deadline_type_id topic_deadline.late_policy_id = nil topic_deadline.submission_allowed_id = due_date.submission_allowed_id topic_deadline.review_allowed_id = due_date.review_allowed_id topic_deadline.review_of_review_allowed_id = due_date.review_of_review_allowed_id topic_deadline.round = due_date.round topic_deadline.save end |
def self.create_topic_deadline(due_date,offset,topic_id) topic_deadline = TopicDeadline.new topic_deadline.topic_id = topic_id topic_deadline.due_at = DateTime.parse(due_date.due_at.to_s) + offset.to_i topic_deadline.deadline_type_id = due_date.deadline_type_id topic_deadline.late_policy_id = nil topic_deadline.submission_allowed_id = due_date.submission_allowed_id topic_deadline.review_allowed_id = due_date.review_allowed_id topic_deadline.review_of_review_allowed_id = due_date.review_of_review_allowed_id topic_deadline.round = due_date.round topic_deadline.save end |
Remove DueDate.assign_topic_deadline
and use DeadlineHelper.create_topic_deadline
method in sign_up_sheet.rb
.
Before Change | After Change |
---|---|
set_of_due_dates = DueDate.where(assignment_id: assignment_id) set_of_due_dates.each { |due_date| DueDate.assign_topic_deadline(due_date, 0, topic.id) |
set_of_due_dates = DueDate.where(assignment_id: assignment_id) set_of_due_dates.each { |due_date| DeadlineHelper.create_topic_deadline(due_date, 0, topic.id) |
Results Screenshot
References
<references/>