<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spurush</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spurush"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Spurush"/>
	<updated>2026-07-01T14:23:31Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2368._Reimplement_of_due_date.rb&amp;diff=151042</id>
		<title>CSC/ECE 517 Fall 2023 - E2368. Reimplement of due date.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2368._Reimplement_of_due_date.rb&amp;diff=151042"/>
		<updated>2023-10-31T19:19:19Z</updated>

		<summary type="html">&lt;p&gt;Spurush: Created page with &amp;quot;==E2368. Reimplement due_date.rb==  This page provides a description of the Expertiza based OSS project.    __TOC__   ===About Expertiza===  [http://expertiza.ncsu.edu/ Expert...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2368. Reimplement due_date.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Project Changes ==&lt;br /&gt;
In this project, the following specific changes were implemented:&lt;br /&gt;
&lt;br /&gt;
* Removed methods used exclusively in test files.&lt;br /&gt;
* Created a new file, due_date_helper.rb, to handle specific functionalities.&lt;br /&gt;
* Moved pertinent methods from the model class to the new helper class.&lt;br /&gt;
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.&lt;br /&gt;
* Renamed methods to accurately describe their responsibilities.&lt;br /&gt;
* Addressed identified code smells and issues using Code Climate analysis.&lt;br /&gt;
&lt;br /&gt;
These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The current implementation of the `DueDate` class can be summarized in three key points:&lt;br /&gt;
&lt;br /&gt;
=== Deadline and Time Handling ===&lt;br /&gt;
The class manages due dates for various elements within an assignment. It includes functionalities to:&lt;br /&gt;
* Determine the current due date based on time comparisons.&lt;br /&gt;
* Check for teammate review allowance based on due dates.&lt;br /&gt;
* Set flags and validate due date formats.&lt;br /&gt;
&lt;br /&gt;
=== Assignment and Topic-Based Due Date Retrieval ===&lt;br /&gt;
The class retrieves the next due date for assignments or topics. It includes logic to:&lt;br /&gt;
* Handle staggered deadlines for topics and fallback procedures for unavailable topic-specific due dates.&lt;br /&gt;
* Retrieve assignment-specific due dates considering the current time.&lt;br /&gt;
&lt;br /&gt;
=== Functionality for Assignment Duplication ===&lt;br /&gt;
The class offers methods to handle due date duplication between assignments. It includes functionalities to:&lt;br /&gt;
* Copy due dates from one assignment to another.&lt;br /&gt;
* Set due dates for assignments based on various parameters.&lt;br /&gt;
* Calculate assignment-specific rounds for responses like author feedback, quizzes, and reviews based on deadlines.&lt;br /&gt;
&lt;br /&gt;
This `DueDate` class serves as a central component within the Expertiza project for managing and handling due dates, validation, and retrieval concerning assignment and deadline management.&lt;br /&gt;
== Improvements in the New Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The changes made in the new implementation of the `DueDate` class addressed several issues, along with their corresponding solutions:&lt;br /&gt;
&lt;br /&gt;
=== Removed methods used only in the test files ===&lt;br /&gt;
* '''Problem''': The code contained methods tailored exclusively for testing, leading to unnecessary clutter and potential confusion within the primary codebase.&lt;br /&gt;
* '''Solution''': Removal of test-specific methods streamlined the code, enhancing focus and clarity, ensuring that the main code is more comprehensible for developers working on functional components.&lt;br /&gt;
&lt;br /&gt;
The method `set_duedate` was originally housed in the `due_date.rb` file and was later relocated to the `due_date_spec.rb` file within the Expertiza project. This method is responsible for setting a due date.&lt;br /&gt;
&lt;br /&gt;
The relocated `set_duedate` method performs the following tasks:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
  submit_duedate = DueDate.new(duedate)&lt;br /&gt;
  submit_duedate.deadline_type_id = deadline&lt;br /&gt;
  submit_duedate.parent_id = assign_id&lt;br /&gt;
  submit_duedate.round = max_round&lt;br /&gt;
  submit_duedate.save&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Created a new due_date_helper.rb file ===&lt;br /&gt;
* '''Problem''': The primary model class had an abundance of methods, including helper functions, affecting readability and maintainability.&lt;br /&gt;
* '''Solution''': The establishment of a dedicated file for due date helper methods segregated the code, enabling a clear distinction between model-specific functions and those supporting due date functionalities, leading to improved modularity and organization.&lt;br /&gt;
&lt;br /&gt;
=== Moved relevant methods from the model class to the helper class ===&lt;br /&gt;
* '''Problem''': The model class contained methods better suited for helper functions, violating the Single Responsibility Principle and causing complexity.&lt;br /&gt;
* '''Solution''': Relocating pertinent methods to the helper class aligned the code with the Single Responsibility Principle, enhancing maintainability and organization by ensuring distinct purposes for each class.&lt;br /&gt;
&lt;br /&gt;
Below are the contents of the newly implemented file app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# frozen_string_literal: true&lt;br /&gt;
&lt;br /&gt;
# app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
# This module contains helper methods related to due dates.&lt;br /&gt;
module DueDateHelper&lt;br /&gt;
  def self.deadline_sort(due_dates)&lt;br /&gt;
    # Override the comparator operator to sort due dates by due_at&lt;br /&gt;
    due_dates.sort { |m1, m2| m1.due_at.to_i &amp;lt;=&amp;gt; m2.due_at.to_i }&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===&lt;br /&gt;
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.&lt;br /&gt;
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
    # for author feedback, quiz, teammate review and metareview, Expertiza only support one round, so the round # should be 1&lt;br /&gt;
    return 0 if ResponseMap.find(response.map_id).type != 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    # sorted so that the earliest deadline is at the first&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    due_dates.reject { |due_date| due_date.deadline_type_id != 1 &amp;amp;&amp;amp; due_date.deadline_type_id != 2 }&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_deadlines.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
    return 0 unless ResponseMap.find(response.map_id).type == 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    determine_assignment_round(response, sorted_deadlines)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.determine_assignment_round(response, sorted_due_dates)&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_due_dates.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Renamed methods to describe their responsibility ===&lt;br /&gt;
* '''Problem''': Method names might not have accurately described their functionality, leading to confusion for developers.&lt;br /&gt;
* '''Solution''': Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.&lt;br /&gt;
&lt;br /&gt;
Before Renaming&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.find_next_topic_due_date(assignment_id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed code smells using Code Climate ===&lt;br /&gt;
* '''Problem''': Code Climate identified issues like inefficiencies, redundancies, or style violations, potentially impacting code quality and maintainability.&lt;br /&gt;
* '''Solution''': Addressing Code Climate's feedback resolved potential issues, leading to an optimized, robust, and maintainable codebase aligning with higher standards.&lt;br /&gt;
&lt;br /&gt;
Before refactoring, the same block of code given below was present in due_date_spec.rb and due_date_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
                                                       submission_allowed_id: @deadline_right.id, review_allowed_id: @deadline_right.id,&lt;br /&gt;
                                                       review_of_review_allowed_id: @deadline_right.id, due_at: '2015-12-30 23:30:12')&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring, we created a new file spec/support/shared_contexts.rb to house the common block of code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RSpec.shared_context 'with_deadline_setup' do&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(&lt;br /&gt;
      :assignment_due_date,&lt;br /&gt;
      deadline_type: @deadline_type,&lt;br /&gt;
      submission_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_of_review_allowed_id: @deadline_right.id,&lt;br /&gt;
      due_at: '2015-12-30 23:30:12'&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By recognizing these problems and applying their respective solutions, the new implementation of the `DueDate` class aims to enhance code quality, readability, and maintainability within the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
&lt;br /&gt;
Created a new file spec/helpers/due_date_helper_spec.rb to handle all the validation for due_date_helper module. Below are some examples - &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'support/shared_contexts'&lt;br /&gt;
&lt;br /&gt;
describe DueDateHelper do&lt;br /&gt;
  def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
    ActiveRecord::Base.transaction do&lt;br /&gt;
      submit_duedate = DueDate.new(duedate)&lt;br /&gt;
      submit_duedate.deadline_type_id = deadline&lt;br /&gt;
      submit_duedate.parent_id = assign_id&lt;br /&gt;
      submit_duedate.round = max_round&lt;br /&gt;
      submit_duedate.save&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  include_context 'with_deadline_setup'&lt;br /&gt;
&lt;br /&gt;
  it 'sort duedate records' do&lt;br /&gt;
    sorted_due_dates = @due_dates&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql false&lt;br /&gt;
&lt;br /&gt;
    sorted_due_dates = DueDateHelper.deadline_sort(@due_dates)&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#calculate_assignment_round' do&lt;br /&gt;
    it 'return 0 when no response map' do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = 'ResponseMap'&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDateHelper.calculate_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/samarth-p/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Spurush</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023&amp;diff=151041</id>
		<title>CSC/ECE 517 Fall 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023&amp;diff=151041"/>
		<updated>2023-10-31T19:18:12Z</updated>

		<summary type="html">&lt;p&gt;Spurush: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Fall 2023 - E2358. Refactor student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2351. Finish mentor management for assignments without topics]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2356. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2359. Refactor user_controller.rb, user.rb, and its child classes]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2367. Reimplement participants_controller.rb, participants.rb and its child classes]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2355. Improving Search Facility In Expertiza]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2365. Create a user interface for Questionnaire in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2364. Create a UI for Course's &amp;amp; Assignment's &amp;quot;Add Participants&amp;quot; page]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2361. Create a page to create and update a Questionnaire in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2362. Create a page to edit an Assignment's due date in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2363. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2375. Reimplement Waitlists]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2357. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2366. Reimplement assignment model and assignment controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2368. Reimplement of due_date.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2370. Reimplement join team requests controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2371. Reimplement quiz_questionnaires_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2369. Reimplement duties controller.rb and badges controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2353. Further refactoring and improvement of review mapping helper]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2373. Reimplementation of teams controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2374. Reimplement the Question hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - NTX-2 Observability and Debuggability]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2350. Allow reviewers to bid on what to review]]&lt;/div&gt;</summary>
		<author><name>Spurush</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151040</id>
		<title>User:Spurush</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151040"/>
		<updated>2023-10-31T19:13:13Z</updated>

		<summary type="html">&lt;p&gt;Spurush: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2368. Reimplement due_date.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Project Changes ==&lt;br /&gt;
In this project, the following specific changes were implemented:&lt;br /&gt;
&lt;br /&gt;
* Removed methods used exclusively in test files.&lt;br /&gt;
* Created a new file, due_date_helper.rb, to handle specific functionalities.&lt;br /&gt;
* Moved pertinent methods from the model class to the new helper class.&lt;br /&gt;
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.&lt;br /&gt;
* Renamed methods to accurately describe their responsibilities.&lt;br /&gt;
* Addressed identified code smells and issues using Code Climate analysis.&lt;br /&gt;
&lt;br /&gt;
These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The current implementation of the `DueDate` class can be summarized in three key points:&lt;br /&gt;
&lt;br /&gt;
=== Deadline and Time Handling ===&lt;br /&gt;
The class manages due dates for various elements within an assignment. It includes functionalities to:&lt;br /&gt;
* Determine the current due date based on time comparisons.&lt;br /&gt;
* Check for teammate review allowance based on due dates.&lt;br /&gt;
* Set flags and validate due date formats.&lt;br /&gt;
&lt;br /&gt;
=== Assignment and Topic-Based Due Date Retrieval ===&lt;br /&gt;
The class retrieves the next due date for assignments or topics. It includes logic to:&lt;br /&gt;
* Handle staggered deadlines for topics and fallback procedures for unavailable topic-specific due dates.&lt;br /&gt;
* Retrieve assignment-specific due dates considering the current time.&lt;br /&gt;
&lt;br /&gt;
=== Functionality for Assignment Duplication ===&lt;br /&gt;
The class offers methods to handle due date duplication between assignments. It includes functionalities to:&lt;br /&gt;
* Copy due dates from one assignment to another.&lt;br /&gt;
* Set due dates for assignments based on various parameters.&lt;br /&gt;
* Calculate assignment-specific rounds for responses like author feedback, quizzes, and reviews based on deadlines.&lt;br /&gt;
&lt;br /&gt;
This `DueDate` class serves as a central component within the Expertiza project for managing and handling due dates, validation, and retrieval concerning assignment and deadline management.&lt;br /&gt;
== Improvements in the New Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The changes made in the new implementation of the `DueDate` class addressed several issues, along with their corresponding solutions:&lt;br /&gt;
&lt;br /&gt;
=== Removed methods used only in the test files ===&lt;br /&gt;
* '''Problem''': The code contained methods tailored exclusively for testing, leading to unnecessary clutter and potential confusion within the primary codebase.&lt;br /&gt;
* '''Solution''': Removal of test-specific methods streamlined the code, enhancing focus and clarity, ensuring that the main code is more comprehensible for developers working on functional components.&lt;br /&gt;
&lt;br /&gt;
The method `set_duedate` was originally housed in the `due_date.rb` file and was later relocated to the `due_date_spec.rb` file within the Expertiza project. This method is responsible for setting a due date.&lt;br /&gt;
&lt;br /&gt;
The relocated `set_duedate` method performs the following tasks:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
  submit_duedate = DueDate.new(duedate)&lt;br /&gt;
  submit_duedate.deadline_type_id = deadline&lt;br /&gt;
  submit_duedate.parent_id = assign_id&lt;br /&gt;
  submit_duedate.round = max_round&lt;br /&gt;
  submit_duedate.save&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Created a new due_date_helper.rb file ===&lt;br /&gt;
* '''Problem''': The primary model class had an abundance of methods, including helper functions, affecting readability and maintainability.&lt;br /&gt;
* '''Solution''': The establishment of a dedicated file for due date helper methods segregated the code, enabling a clear distinction between model-specific functions and those supporting due date functionalities, leading to improved modularity and organization.&lt;br /&gt;
&lt;br /&gt;
=== Moved relevant methods from the model class to the helper class ===&lt;br /&gt;
* '''Problem''': The model class contained methods better suited for helper functions, violating the Single Responsibility Principle and causing complexity.&lt;br /&gt;
* '''Solution''': Relocating pertinent methods to the helper class aligned the code with the Single Responsibility Principle, enhancing maintainability and organization by ensuring distinct purposes for each class.&lt;br /&gt;
&lt;br /&gt;
Below are the contents of the newly implemented file app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# frozen_string_literal: true&lt;br /&gt;
&lt;br /&gt;
# app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
# This module contains helper methods related to due dates.&lt;br /&gt;
module DueDateHelper&lt;br /&gt;
  def self.deadline_sort(due_dates)&lt;br /&gt;
    # Override the comparator operator to sort due dates by due_at&lt;br /&gt;
    due_dates.sort { |m1, m2| m1.due_at.to_i &amp;lt;=&amp;gt; m2.due_at.to_i }&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===&lt;br /&gt;
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.&lt;br /&gt;
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
    # for author feedback, quiz, teammate review and metareview, Expertiza only support one round, so the round # should be 1&lt;br /&gt;
    return 0 if ResponseMap.find(response.map_id).type != 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    # sorted so that the earliest deadline is at the first&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    due_dates.reject { |due_date| due_date.deadline_type_id != 1 &amp;amp;&amp;amp; due_date.deadline_type_id != 2 }&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_deadlines.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
    return 0 unless ResponseMap.find(response.map_id).type == 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    determine_assignment_round(response, sorted_deadlines)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.determine_assignment_round(response, sorted_due_dates)&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_due_dates.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Renamed methods to describe their responsibility ===&lt;br /&gt;
* '''Problem''': Method names might not have accurately described their functionality, leading to confusion for developers.&lt;br /&gt;
* '''Solution''': Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.&lt;br /&gt;
&lt;br /&gt;
Before Renaming&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.find_next_topic_due_date(assignment_id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed code smells using Code Climate ===&lt;br /&gt;
* '''Problem''': Code Climate identified issues like inefficiencies, redundancies, or style violations, potentially impacting code quality and maintainability.&lt;br /&gt;
* '''Solution''': Addressing Code Climate's feedback resolved potential issues, leading to an optimized, robust, and maintainable codebase aligning with higher standards.&lt;br /&gt;
&lt;br /&gt;
Before refactoring, the same block of code given below was present in due_date_spec.rb and due_date_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
                                                       submission_allowed_id: @deadline_right.id, review_allowed_id: @deadline_right.id,&lt;br /&gt;
                                                       review_of_review_allowed_id: @deadline_right.id, due_at: '2015-12-30 23:30:12')&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring, we created a new file spec/support/shared_contexts.rb to house the common block of code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RSpec.shared_context 'with_deadline_setup' do&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(&lt;br /&gt;
      :assignment_due_date,&lt;br /&gt;
      deadline_type: @deadline_type,&lt;br /&gt;
      submission_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_of_review_allowed_id: @deadline_right.id,&lt;br /&gt;
      due_at: '2015-12-30 23:30:12'&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By recognizing these problems and applying their respective solutions, the new implementation of the `DueDate` class aims to enhance code quality, readability, and maintainability within the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
&lt;br /&gt;
Created a new file spec/helpers/due_date_helper_spec.rb to handle all the validation for due_date_helper module. Below are some examples - &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'support/shared_contexts'&lt;br /&gt;
&lt;br /&gt;
describe DueDateHelper do&lt;br /&gt;
  def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
    ActiveRecord::Base.transaction do&lt;br /&gt;
      submit_duedate = DueDate.new(duedate)&lt;br /&gt;
      submit_duedate.deadline_type_id = deadline&lt;br /&gt;
      submit_duedate.parent_id = assign_id&lt;br /&gt;
      submit_duedate.round = max_round&lt;br /&gt;
      submit_duedate.save&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  include_context 'with_deadline_setup'&lt;br /&gt;
&lt;br /&gt;
  it 'sort duedate records' do&lt;br /&gt;
    sorted_due_dates = @due_dates&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql false&lt;br /&gt;
&lt;br /&gt;
    sorted_due_dates = DueDateHelper.deadline_sort(@due_dates)&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#calculate_assignment_round' do&lt;br /&gt;
    it 'return 0 when no response map' do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = 'ResponseMap'&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDateHelper.calculate_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/samarth-p/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Spurush</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151039</id>
		<title>User:Spurush</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151039"/>
		<updated>2023-10-31T19:12:42Z</updated>

		<summary type="html">&lt;p&gt;Spurush: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2368. Reimplement due_date.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Project Changes ==&lt;br /&gt;
In this project, the following specific changes were implemented:&lt;br /&gt;
&lt;br /&gt;
* Removed methods used exclusively in test files.&lt;br /&gt;
* Created a new file, due_date_helper.rb, to handle specific functionalities.&lt;br /&gt;
* Moved pertinent methods from the model class to the new helper class.&lt;br /&gt;
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.&lt;br /&gt;
* Renamed methods to accurately describe their responsibilities.&lt;br /&gt;
* Addressed identified code smells and issues using Code Climate analysis.&lt;br /&gt;
&lt;br /&gt;
These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The current implementation of the `DueDate` class can be summarized in three key points:&lt;br /&gt;
&lt;br /&gt;
=== Deadline and Time Handling ===&lt;br /&gt;
The class manages due dates for various elements within an assignment. It includes functionalities to:&lt;br /&gt;
* Determine the current due date based on time comparisons.&lt;br /&gt;
* Check for teammate review allowance based on due dates.&lt;br /&gt;
* Set flags and validate due date formats.&lt;br /&gt;
&lt;br /&gt;
=== Assignment and Topic-Based Due Date Retrieval ===&lt;br /&gt;
The class retrieves the next due date for assignments or topics. It includes logic to:&lt;br /&gt;
* Handle staggered deadlines for topics and fallback procedures for unavailable topic-specific due dates.&lt;br /&gt;
* Retrieve assignment-specific due dates considering the current time.&lt;br /&gt;
&lt;br /&gt;
=== Functionality for Assignment Duplication ===&lt;br /&gt;
The class offers methods to handle due date duplication between assignments. It includes functionalities to:&lt;br /&gt;
* Copy due dates from one assignment to another.&lt;br /&gt;
* Set due dates for assignments based on various parameters.&lt;br /&gt;
* Calculate assignment-specific rounds for responses like author feedback, quizzes, and reviews based on deadlines.&lt;br /&gt;
&lt;br /&gt;
This `DueDate` class serves as a central component within the Expertiza project for managing and handling due dates, validation, and retrieval concerning assignment and deadline management.&lt;br /&gt;
== Improvements in the New Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The changes made in the new implementation of the `DueDate` class addressed several issues, along with their corresponding solutions:&lt;br /&gt;
&lt;br /&gt;
=== Removed methods used only in the test files ===&lt;br /&gt;
* '''Problem''': The code contained methods tailored exclusively for testing, leading to unnecessary clutter and potential confusion within the primary codebase.&lt;br /&gt;
* '''Solution''': Removal of test-specific methods streamlined the code, enhancing focus and clarity, ensuring that the main code is more comprehensible for developers working on functional components.&lt;br /&gt;
&lt;br /&gt;
The method `set_duedate` was originally housed in the `due_date.rb` file and was later relocated to the `due_date_spec.rb` file within the Expertiza project. This method is responsible for setting a due date.&lt;br /&gt;
&lt;br /&gt;
The relocated `set_duedate` method performs the following tasks:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
  submit_duedate = DueDate.new(duedate)&lt;br /&gt;
  submit_duedate.deadline_type_id = deadline&lt;br /&gt;
  submit_duedate.parent_id = assign_id&lt;br /&gt;
  submit_duedate.round = max_round&lt;br /&gt;
  submit_duedate.save&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Created a new due_date_helper.rb file ===&lt;br /&gt;
* '''Problem''': The primary model class had an abundance of methods, including helper functions, affecting readability and maintainability.&lt;br /&gt;
* '''Solution''': The establishment of a dedicated file for due date helper methods segregated the code, enabling a clear distinction between model-specific functions and those supporting due date functionalities, leading to improved modularity and organization.&lt;br /&gt;
&lt;br /&gt;
=== Moved relevant methods from the model class to the helper class ===&lt;br /&gt;
* '''Problem''': The model class contained methods better suited for helper functions, violating the Single Responsibility Principle and causing complexity.&lt;br /&gt;
* '''Solution''': Relocating pertinent methods to the helper class aligned the code with the Single Responsibility Principle, enhancing maintainability and organization by ensuring distinct purposes for each class.&lt;br /&gt;
&lt;br /&gt;
Below are the contents of the newly implemented file app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# frozen_string_literal: true&lt;br /&gt;
&lt;br /&gt;
# app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
# This module contains helper methods related to due dates.&lt;br /&gt;
module DueDateHelper&lt;br /&gt;
  def self.deadline_sort(due_dates)&lt;br /&gt;
    # Override the comparator operator to sort due dates by due_at&lt;br /&gt;
    due_dates.sort { |m1, m2| m1.due_at.to_i &amp;lt;=&amp;gt; m2.due_at.to_i }&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===&lt;br /&gt;
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.&lt;br /&gt;
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
    # for author feedback, quiz, teammate review and metareview, Expertiza only support one round, so the round # should be 1&lt;br /&gt;
    return 0 if ResponseMap.find(response.map_id).type != 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    # sorted so that the earliest deadline is at the first&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    due_dates.reject { |due_date| due_date.deadline_type_id != 1 &amp;amp;&amp;amp; due_date.deadline_type_id != 2 }&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_deadlines.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
    return 0 unless ResponseMap.find(response.map_id).type == 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    determine_assignment_round(response, sorted_deadlines)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.determine_assignment_round(response, sorted_due_dates)&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_due_dates.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Renamed methods to describe their responsibility ===&lt;br /&gt;
* '''Problem''': Method names might not have accurately described their functionality, leading to confusion for developers.&lt;br /&gt;
* '''Solution''': Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.&lt;br /&gt;
&lt;br /&gt;
Before Renaming&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.find_next_topic_due_date(assignment_id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed code smells using Code Climate ===&lt;br /&gt;
* '''Problem''': Code Climate identified issues like inefficiencies, redundancies, or style violations, potentially impacting code quality and maintainability.&lt;br /&gt;
* '''Solution''': Addressing Code Climate's feedback resolved potential issues, leading to an optimized, robust, and maintainable codebase aligning with higher standards.&lt;br /&gt;
&lt;br /&gt;
Before refactoring, the same block of code given below was present in due_date_spec.rb and due_date_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
                                                       submission_allowed_id: @deadline_right.id, review_allowed_id: @deadline_right.id,&lt;br /&gt;
                                                       review_of_review_allowed_id: @deadline_right.id, due_at: '2015-12-30 23:30:12')&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring, we created a new file spec/support/shared_contexts.rb to house the common block of code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RSpec.shared_context 'with_deadline_setup' do&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(&lt;br /&gt;
      :assignment_due_date,&lt;br /&gt;
      deadline_type: @deadline_type,&lt;br /&gt;
      submission_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_of_review_allowed_id: @deadline_right.id,&lt;br /&gt;
      due_at: '2015-12-30 23:30:12'&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By recognizing these problems and applying their respective solutions, the new implementation of the `DueDate` class aims to enhance code quality, readability, and maintainability within the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
&lt;br /&gt;
Created a new file spec/helpers/due_date_helper_spec.rb to handle all the validation for due_date_helper module. Below are some examples - &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'support/shared_contexts'&lt;br /&gt;
&lt;br /&gt;
describe DueDateHelper do&lt;br /&gt;
  def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
    ActiveRecord::Base.transaction do&lt;br /&gt;
      submit_duedate = DueDate.new(duedate)&lt;br /&gt;
      submit_duedate.deadline_type_id = deadline&lt;br /&gt;
      submit_duedate.parent_id = assign_id&lt;br /&gt;
      submit_duedate.round = max_round&lt;br /&gt;
      submit_duedate.save&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  include_context 'with_deadline_setup'&lt;br /&gt;
&lt;br /&gt;
  it 'sort duedate records' do&lt;br /&gt;
    sorted_due_dates = @due_dates&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql false&lt;br /&gt;
&lt;br /&gt;
    sorted_due_dates = DueDateHelper.deadline_sort(@due_dates)&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#calculate_assignment_round' do&lt;br /&gt;
    it 'return 0 when no response map' do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = 'ResponseMap'&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDateHelper.calculate_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/samarth-p/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Spurush</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151038</id>
		<title>User:Spurush</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Spurush&amp;diff=151038"/>
		<updated>2023-10-31T19:10:12Z</updated>

		<summary type="html">&lt;p&gt;Spurush: Created page with &amp;quot;==E2368. Reimplement due_date.rb==  This page provides a description of the Expertiza based OSS project.    __TOC__   ===About Expertiza===  [http://expertiza.ncsu.edu/ Expert...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E2368. Reimplement due_date.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Project Changes ==&lt;br /&gt;
In this project, the following specific changes were implemented:&lt;br /&gt;
&lt;br /&gt;
* Removed methods used exclusively in test files.&lt;br /&gt;
* Created a new file, due_date_helper.rb, to handle specific functionalities.&lt;br /&gt;
* Moved pertinent methods from the model class to the new helper class.&lt;br /&gt;
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.&lt;br /&gt;
* Renamed methods to accurately describe their responsibilities.&lt;br /&gt;
* Addressed identified code smells and issues using Code Climate analysis.&lt;br /&gt;
&lt;br /&gt;
These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The current implementation of the `DueDate` class can be summarized in three key points:&lt;br /&gt;
&lt;br /&gt;
=== Deadline and Time Handling ===&lt;br /&gt;
The class manages due dates for various elements within an assignment. It includes functionalities to:&lt;br /&gt;
* Determine the current due date based on time comparisons.&lt;br /&gt;
* Check for teammate review allowance based on due dates.&lt;br /&gt;
* Set flags and validate due date formats.&lt;br /&gt;
&lt;br /&gt;
=== Assignment and Topic-Based Due Date Retrieval ===&lt;br /&gt;
The class retrieves the next due date for assignments or topics. It includes logic to:&lt;br /&gt;
* Handle staggered deadlines for topics and fallback procedures for unavailable topic-specific due dates.&lt;br /&gt;
* Retrieve assignment-specific due dates considering the current time.&lt;br /&gt;
&lt;br /&gt;
=== Functionality for Assignment Duplication ===&lt;br /&gt;
The class offers methods to handle due date duplication between assignments. It includes functionalities to:&lt;br /&gt;
* Copy due dates from one assignment to another.&lt;br /&gt;
* Set due dates for assignments based on various parameters.&lt;br /&gt;
* Calculate assignment-specific rounds for responses like author feedback, quizzes, and reviews based on deadlines.&lt;br /&gt;
&lt;br /&gt;
This `DueDate` class serves as a central component within the Expertiza project for managing and handling due dates, validation, and retrieval concerning assignment and deadline management.&lt;br /&gt;
== Improvements in the New Implementation of DueDate Class ==&lt;br /&gt;
&lt;br /&gt;
The changes made in the new implementation of the `DueDate` class addressed several issues, along with their corresponding solutions:&lt;br /&gt;
&lt;br /&gt;
=== Removed methods used only in the test files ===&lt;br /&gt;
* '''Problem''': The code contained methods tailored exclusively for testing, leading to unnecessary clutter and potential confusion within the primary codebase.&lt;br /&gt;
* '''Solution''': Removal of test-specific methods streamlined the code, enhancing focus and clarity, ensuring that the main code is more comprehensible for developers working on functional components.&lt;br /&gt;
&lt;br /&gt;
The method `set_duedate` was originally housed in the `due_date.rb` file and was later relocated to the `due_date_spec.rb` file within the Expertiza project. This method is responsible for setting a due date.&lt;br /&gt;
&lt;br /&gt;
The relocated `set_duedate` method performs the following tasks:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
  submit_duedate = DueDate.new(duedate)&lt;br /&gt;
  submit_duedate.deadline_type_id = deadline&lt;br /&gt;
  submit_duedate.parent_id = assign_id&lt;br /&gt;
  submit_duedate.round = max_round&lt;br /&gt;
  submit_duedate.save&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Created a new due_date_helper.rb file ===&lt;br /&gt;
* '''Problem''': The primary model class had an abundance of methods, including helper functions, affecting readability and maintainability.&lt;br /&gt;
* '''Solution''': The establishment of a dedicated file for due date helper methods segregated the code, enabling a clear distinction between model-specific functions and those supporting due date functionalities, leading to improved modularity and organization.&lt;br /&gt;
&lt;br /&gt;
=== Moved relevant methods from the model class to the helper class ===&lt;br /&gt;
* '''Problem''': The model class contained methods better suited for helper functions, violating the Single Responsibility Principle and causing complexity.&lt;br /&gt;
* '''Solution''': Relocating pertinent methods to the helper class aligned the code with the Single Responsibility Principle, enhancing maintainability and organization by ensuring distinct purposes for each class.&lt;br /&gt;
&lt;br /&gt;
Below are the contents of the newly implemented file app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# frozen_string_literal: true&lt;br /&gt;
&lt;br /&gt;
# app/helpers/due_date_helper.rb&lt;br /&gt;
&lt;br /&gt;
# This module contains helper methods related to due dates.&lt;br /&gt;
module DueDateHelper&lt;br /&gt;
  def self.deadline_sort(due_dates)&lt;br /&gt;
    # Override the comparator operator to sort due dates by due_at&lt;br /&gt;
    due_dates.sort { |m1, m2| m1.due_at.to_i &amp;lt;=&amp;gt; m2.due_at.to_i }&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===&lt;br /&gt;
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.&lt;br /&gt;
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
    # for author feedback, quiz, teammate review and metareview, Expertiza only support one round, so the round # should be 1&lt;br /&gt;
    return 0 if ResponseMap.find(response.map_id).type != 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    # sorted so that the earliest deadline is at the first&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    due_dates.reject { |due_date| due_date.deadline_type_id != 1 &amp;amp;&amp;amp; due_date.deadline_type_id != 2 }&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_deadlines.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
    return 0 unless ResponseMap.find(response.map_id).type == 'ReviewResponseMap'&lt;br /&gt;
&lt;br /&gt;
    due_dates = DueDate.where(parent_id: assignment_id)&lt;br /&gt;
    sorted_deadlines = deadline_sort(due_dates)&lt;br /&gt;
    determine_assignment_round(response, sorted_deadlines)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def self.determine_assignment_round(response, sorted_due_dates)&lt;br /&gt;
    round = 1&lt;br /&gt;
    sorted_due_dates.each do |due_date|&lt;br /&gt;
      break if response.created_at &amp;lt; due_date.due_at&lt;br /&gt;
&lt;br /&gt;
      round += 1 if due_date.deadline_type_id == 2&lt;br /&gt;
    end&lt;br /&gt;
    round&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Renamed methods to describe their responsibility ===&lt;br /&gt;
* '''Problem''': Method names might not have accurately described their functionality, leading to confusion for developers.&lt;br /&gt;
* '''Solution''': Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.&lt;br /&gt;
&lt;br /&gt;
Before Renaming&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.done_in_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def self.set_duedate(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.get_next_due_date(assignment_id, topic_id = nil)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.calculate_assignment_round(assignment_id, response)&lt;br /&gt;
..&lt;br /&gt;
def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
..&lt;br /&gt;
def self.find_next_topic_due_date(assignment_id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fixed code smells using Code Climate ===&lt;br /&gt;
* '''Problem''': Code Climate identified issues like inefficiencies, redundancies, or style violations, potentially impacting code quality and maintainability.&lt;br /&gt;
* '''Solution''': Addressing Code Climate's feedback resolved potential issues, leading to an optimized, robust, and maintainable codebase aligning with higher standards.&lt;br /&gt;
&lt;br /&gt;
Before refactoring, the same block of code given below was present in due_date_spec.rb and due_date_helper_spec.rb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
                                                       submission_allowed_id: @deadline_right.id, review_allowed_id: @deadline_right.id,&lt;br /&gt;
                                                       review_of_review_allowed_id: @deadline_right.id, due_at: '2015-12-30 23:30:12')&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring, we created a new file spec/support/shared_contexts.rb to house the common block of code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RSpec.shared_context 'with_deadline_setup' do&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @deadline_type = build(:deadline_type)&lt;br /&gt;
    @deadline_right = build(:deadline_right)&lt;br /&gt;
    @assignment_due_date = build(&lt;br /&gt;
      :assignment_due_date,&lt;br /&gt;
      deadline_type: @deadline_type,&lt;br /&gt;
      submission_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_allowed_id: @deadline_right.id,&lt;br /&gt;
      review_of_review_allowed_id: @deadline_right.id,&lt;br /&gt;
      due_at: '2015-12-30 23:30:12'&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    @due_dates = []&lt;br /&gt;
    10.times.each do |n|&lt;br /&gt;
      date = if n == 1 || n == 9&lt;br /&gt;
               nil&lt;br /&gt;
             else&lt;br /&gt;
               Time.zone.now - 60 * n&lt;br /&gt;
             end&lt;br /&gt;
      @due_dates &amp;lt;&amp;lt; build(:assignment_due_date, due_at: date)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By recognizing these problems and applying their respective solutions, the new implementation of the `DueDate` class aims to enhance code quality, readability, and maintainability within the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
&lt;br /&gt;
Created a new file spec/helpers/due_date_helper_spec.rb to handle all the validation for due_date_helper module. Below are some examples - &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'support/shared_contexts'&lt;br /&gt;
&lt;br /&gt;
describe DueDateHelper do&lt;br /&gt;
  def set_due_date(duedate, deadline, assign_id, max_round)&lt;br /&gt;
    ActiveRecord::Base.transaction do&lt;br /&gt;
      submit_duedate = DueDate.new(duedate)&lt;br /&gt;
      submit_duedate.deadline_type_id = deadline&lt;br /&gt;
      submit_duedate.parent_id = assign_id&lt;br /&gt;
      submit_duedate.round = max_round&lt;br /&gt;
      submit_duedate.save&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  include_context 'with_deadline_setup'&lt;br /&gt;
&lt;br /&gt;
  it 'sort duedate records' do&lt;br /&gt;
    sorted_due_dates = @due_dates&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql false&lt;br /&gt;
&lt;br /&gt;
    sorted_due_dates = DueDateHelper.deadline_sort(@due_dates)&lt;br /&gt;
    expect(sorted_due_dates.each_cons(2).all? { |m1, m2| (m1.due_at &amp;lt;=&amp;gt; m2.due_at) != 1 }).to eql true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#calculate_assignment_round' do&lt;br /&gt;
    it 'return 0 when no response map' do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = 'ResponseMap'&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDateHelper.calculate_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Spurush</name></author>
	</entry>
</feed>