<?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=Aagrawa6</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=Aagrawa6"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aagrawa6"/>
	<updated>2026-06-09T02:17:49Z</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_2016_E1709_Visualizations_for_instructors&amp;diff=106150</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106150"/>
		<updated>2016-12-02T23:30:12Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Mockups */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups(Final Versions) ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, we have finally implemented the following:&lt;br /&gt;
&lt;br /&gt;
* We added a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We added the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a number of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we added here routes to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view receives the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller gets all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It then gets a list of all the rubrics used in those questionnaires from the ''Questions'' model. These are displayed to the instructor. It then routes the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers of those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here: https://github.com/expertiza/expertiza/pull/861&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can any number of rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106149</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106149"/>
		<updated>2016-12-02T23:29:15Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Implementation Thoughts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, we have finally implemented the following:&lt;br /&gt;
&lt;br /&gt;
* We added a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We added the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a number of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we added here routes to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view receives the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller gets all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It then gets a list of all the rubrics used in those questionnaires from the ''Questions'' model. These are displayed to the instructor. It then routes the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers of those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here: https://github.com/expertiza/expertiza/pull/861&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can any number of rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106148</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106148"/>
		<updated>2016-12-02T23:29:02Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, we have finally implemented the following:&lt;br /&gt;
&lt;br /&gt;
* We added a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We added the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a number of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we added here routes to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view receives the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller gets all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It then gets a list of all the rubrics used in those questionnaires from the ''Questions'' model. These are displayed to the instructor. It then routes the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers of those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here: https://github.com/expertiza/expertiza/pull/861&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can any number of rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106129</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106129"/>
		<updated>2016-12-02T23:16:47Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Pull Request and Demo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here: https://github.com/expertiza/expertiza/pull/861&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can any number of rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106122</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106122"/>
		<updated>2016-12-02T23:08:53Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here:&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can any number of rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106119</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106119"/>
		<updated>2016-12-02T23:05:48Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here:&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can select 5 rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106118</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=106118"/>
		<updated>2016-12-02T23:04:37Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Mockups Updated with final Version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the Ruby on Rails&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Ruby_on_Rails&amp;lt;/ref&amp;gt; framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Create a new table for review and author feedback report.&lt;br /&gt;
* The new table should have the following information: reviewer name, the number of reviews he has done, length of reviews, review summary, whether there is a link or a file attached, Average author feedback rating per team, Author feedback summary and a field where an instructor can give his grades and write comments.&lt;br /&gt;
* Add interactive visualization to show the class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
'''Iterator Pattern&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Iterator_pattern&amp;lt;/ref&amp;gt;:'''&lt;br /&gt;
The iterator design pattern uses an iterator to traverse a container and access its elements. When we are implementing the response and author feedback report, we will be iterating through each reviewer to get the review performed by them and then each author based on the feedback given for each review. This iteration will occur with the data returned by the ResponseMap model for all of the review and feedback information. For the class performance report, we will be iterating through each questionnaire per assignment, and thereafter each question per questionnaire. The same iteration will also be required to get answers per question per reviewer.&lt;br /&gt;
&lt;br /&gt;
'''MVC Pattern&amp;lt;ref&amp;gt;https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm&amp;lt;/ref&amp;gt;:''' &lt;br /&gt;
In the MVC design pattern a controller processes the request, interprets the data in model and then renders particular view.&lt;br /&gt;
For rendering response and author feedback report, we check the the data, in the form that was submitted from the UI, in the ResponseMappingController. Depending on the data, we process various models and then display a particular view.&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* When the author will select the review and author feedback, it will show him the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Mockup1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
This report is an integration of two preexisting reports &amp;quot;Review&amp;quot;and &amp;quot;Author Feedback&amp;quot;. Thus we will be reusing a lot of components with addition of few.&lt;br /&gt;
&lt;br /&gt;
* A new option will be provided in the dropdown called as &amp;quot;Review and Author Feedback Report&amp;quot;.&lt;br /&gt;
* On submitting this form, the user is redirected to action &amp;quot;response_report&amp;quot; in controller &amp;quot;ReviewMappingController&amp;quot;.&lt;br /&gt;
* We will add new case for our requirement.&lt;br /&gt;
** We will require data from ReviewResponseMap, FeedbackResponseMap, AssignmentParticipant models.&lt;br /&gt;
** From ReviewResponseMap and AssignmentParticipant, for each reviewer we will get number of reviews completed, length of reviews, summary of reviews and whether reviewers had added a file or link for their review.&lt;br /&gt;
** From FeedbackResponseMap, we will get author feedback summary and the total score that author gave for the particular reviewer.&lt;br /&gt;
* All the above data will be rendered using a new partial &amp;quot;_response_and_feedback.html.erb&amp;quot; in &amp;quot;/app/views/review_mapping&amp;quot;. This partial is called from &amp;quot;response_report.html.haml&amp;quot;.&lt;br /&gt;
* In a similar tabular format for Review/ Author feedback report, we will show the data in a table.&lt;br /&gt;
*Hyperlinks will be provided where necessary, so instructor can view additional details. For e.g. to view review summary or author feedback summary.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
* The instructor can view the class performance on assignments by clicking on the graph icon on the assignments page as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Image11.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can select various rubric questions used for evaluation of that assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Image22.png]]&lt;br /&gt;
&lt;br /&gt;
* Once you click on the graph icon, it will take the instructor to the page shown below where the instructor can see the performance of the class based on various selected rubric questions.&lt;br /&gt;
&lt;br /&gt;
[[File:Image33.png]]&lt;br /&gt;
&lt;br /&gt;
* The instructor can select the round 1 or round 2 from the drop-down menu.&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
==== Implementation ====&lt;br /&gt;
&lt;br /&gt;
==== Pull Request and Demo ====&lt;br /&gt;
&lt;br /&gt;
The demo for the class performance report can be seen here: https://youtu.be/_fp4YYCgY2w&lt;br /&gt;
The pull request is here:&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
* '''RSpec''': RSpec is a behavior design development framework which is used for testing the functionality of the system.&lt;br /&gt;
* ''' Capybara''': We will be using capybara for automation of the manual test cases written in RSpec.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can select 5 rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
While software and hardware requirements are the same as current Expertiza system, we will require following addition tools:&lt;br /&gt;
&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Image33.png&amp;diff=106116</id>
		<title>File:Image33.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Image33.png&amp;diff=106116"/>
		<updated>2016-12-02T23:01:50Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Image22.png&amp;diff=106115</id>
		<title>File:Image22.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Image22.png&amp;diff=106115"/>
		<updated>2016-12-02T23:01:35Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Imag22&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Imag22&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Image11.png&amp;diff=106114</id>
		<title>File:Image11.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Image11.png&amp;diff=106114"/>
		<updated>2016-12-02T23:00:55Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104900</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104900"/>
		<updated>2016-11-09T05:31:23Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
*'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
*'''For use case 2''', test if the instructor can select 5 rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
* '''Computing Power:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Memory:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Disk Storage:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Peripherals:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Network:''' Same as the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
* '''Operating system environment:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Networking environment:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104899</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104899"/>
		<updated>2016-11-09T05:31:08Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Test Plan Added*/&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Project Design ==&lt;br /&gt;
&lt;br /&gt;
=== Design Patterns ===&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
'''For use case 1''', test if the instructor can see the text metrics of reviews and author feedbacks received for an assignment or a project per student. &lt;br /&gt;
'''For use case 2''', test if the instructor can select 5 rubric metrics used for an assignment. Also, test if the instructor can view the class performance from a graph using the metrics selected by the instructor.&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
* '''Computing Power:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Memory:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Disk Storage:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Peripherals:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Network:''' Same as the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
* '''Operating system environment:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Networking environment:''' Same as the current Expertiza system.&lt;br /&gt;
* '''Tools:''' Gruff API in addition to the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104887</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104887"/>
		<updated>2016-11-09T05:22:47Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Use Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* '''View Review and Author Feedback Report as Instructor''': As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* '''View Class Performance as Instructor''': As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104885</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104885"/>
		<updated>2016-11-09T05:22:14Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Use Cases Added */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
In order to implement the above functionality for the class performance report, our initial observation resulted in the following path for implementation.&lt;br /&gt;
&lt;br /&gt;
* We will need a new controller ''ClassPerformanceController''.&lt;br /&gt;
* We will need the following two new views.&lt;br /&gt;
** A view to ''select_rubrics''. This view will allow instructors to select a couple of rubrics to evaluate the class performance on.&lt;br /&gt;
** A view to ''show_class_performance''. This view will display the class performance using relevant graphs to represent the information clearly.&lt;br /&gt;
* Routes for each of the views created.&lt;br /&gt;
* Model methods to facilitate getting the required information and calculations.&lt;br /&gt;
&lt;br /&gt;
We need to provide a link to the instructor to see this view. As shown above, this will be a button in the assignment management page routed at ''tree_display/list'' which corresponds to the function ''list'' in the controller ''TreeDisplayController.rb''. The button we are adding here to route to the newly created ''select_rubrics'' view.&lt;br /&gt;
&lt;br /&gt;
The ''select_rubrics'' view will receive the following parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will get all the questionnaires related to that assignment from the ''AssignmentQuestionnaire'' model. It will then get a list of all the rubrics used in those questionnaires from the ''Questions'' model. These will be displayed to the instructor. It will then route the instructor to the ''show_class_performance'' view upon selection of rubrics. It will pass the following parameters to the ''show_class_performance'' view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assignment_id&lt;br /&gt;
Array[question_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will take the list of questions for the assignment and find all the answers for those questions. It will then calculate the average score per question for the entire class from those answers and pass this to the view. The ''show_class_performance'' view will use the [https://github.com/topfunky/gruff Gruff API] in order to provide an aesthetically appealing visualization of the data.&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
* View Review and Author Feedback Report as Instructor: As an instructor, he can see the different metrics of reviews and average feedback rating received per student done for an assignment or a project.&lt;br /&gt;
* View Class Performance as Instructor: As an instructor, he can select 5 rubric metrics used per assignment. The instructor is able to see the graph to check the class performance based upon the metrics selected.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104872</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104872"/>
		<updated>2016-11-09T05:10:57Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Class Performance Report */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104871</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104871"/>
		<updated>2016-11-09T05:10:44Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Workflow Diagram 2 added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow3.png]]&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Workflow3.png&amp;diff=104870</id>
		<title>File:Workflow3.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Workflow3.png&amp;diff=104870"/>
		<updated>2016-11-09T05:10:16Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104859</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104859"/>
		<updated>2016-11-09T05:02:01Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104858</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104858"/>
		<updated>2016-11-09T05:01:37Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104854</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104854"/>
		<updated>2016-11-09T05:00:34Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Workflow Diagram 1 added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
Expertiza assignments are based on a peer review system where the instructor creates rubrics for an assignment through questionnaires which students use to review other students' submissions. The author of the submission is given an opportunity to provide feedback about these reviews. All questions in the questionnaire have an assigned grade which is based on a pre-defined grading scale. Instructors can see a report on the scores of a student given by reviewers, on the score of feedback given to the reviewers and many other reports. Based on these reports (which are all on separate pages), the instructors grade the student. These reports are, however, on separate pages and it is difficult for an instructor to navigate to many pages before grading the student. The first requirement is meant to solve this problem by merging the review scores with the author feedbacks on the same page.&lt;br /&gt;
&lt;br /&gt;
Furthermore, there is no way for an instructor to evaluate the rubric he/she has posted on assignments. Students may consistently be getting negative reviews for a rubric which might not be totally relevant to the assignment thereby reducing their scores. A report of average class scores for each rubric in the questionnaires would help instructors refactor their rubric and understand where students generally perform well and where they struggle. This new report forms the second part of the requirement.&lt;br /&gt;
&lt;br /&gt;
We are not modifying any of the existing functionalities of Expertiza. Our work would involve modifying the review report and creating a new report for average class scores.&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
=== Review and Author Feedback Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
&lt;br /&gt;
[[File:workflow1.png]]&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
=== Class Performance Report ===&lt;br /&gt;
&lt;br /&gt;
==== Workflow ====&lt;br /&gt;
&lt;br /&gt;
==== Mockups ====&lt;br /&gt;
&lt;br /&gt;
==== Implementation Thoughts ====&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== System Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Workflow1.png&amp;diff=104853</id>
		<title>File:Workflow1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Workflow1.png&amp;diff=104853"/>
		<updated>2016-11-09T04:59:52Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104850</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104850"/>
		<updated>2016-11-09T04:29:10Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Task Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
* Add a new column to give the length of reviews.&lt;br /&gt;
* Separate data from columns number of reviews and summary details.&lt;br /&gt;
* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
* Create a new route/view/controller for class performance.&lt;br /&gt;
* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
* Create graphs to show the class performance as per the rubric metrics selected dynamically.&lt;br /&gt;
&lt;br /&gt;
=== Workflow ===&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104849</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104849"/>
		<updated>2016-11-09T04:27:25Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Task Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
#* Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
#* Add a new column to give the length of reviews.&lt;br /&gt;
#* Separate data from columns number of reviews and summary details.&lt;br /&gt;
#* Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
#* Create a new column to check the average author feedback rating per team.&lt;br /&gt;
#* Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
#* Create a new route/view/controller for class performance.&lt;br /&gt;
#* Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
#* Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
&lt;br /&gt;
=== Workflow ===&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104848</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104848"/>
		<updated>2016-11-09T04:26:11Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Task Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
# Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
# Add a new column to give the length of reviews.&lt;br /&gt;
# Separate data from columns number of reviews and summary details.&lt;br /&gt;
# Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
# Create a new column to check the average author feedback rating per team.&lt;br /&gt;
# Add interactive visualization to show class performance of an assignment to an instructor.&lt;br /&gt;
# Create a new route/view/controller for class performance.&lt;br /&gt;
# Add a new link to point to the new controller created. This new link will be created per assignment.&lt;br /&gt;
# Create two new views, one for selecting rubric criteria and second to show the graph.&lt;br /&gt;
&lt;br /&gt;
=== Workflow ===&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104847</id>
		<title>CSC/ECE 517 Fall 2016 E1709 Visualizations for instructors</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016_E1709_Visualizations_for_instructors&amp;diff=104847"/>
		<updated>2016-11-09T04:21:04Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Task Description Added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza] is an open-source web application to create re-usable learning objects through peer-reviews to facilitate incremental learning. Students can submit learning objects such as articles, wiki pages, repository links and with the help of peer reviews, improve them. The project has been developed using the [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] framework and is supported by the [http://www.nsf.gov National Science Foundation].&lt;br /&gt;
&lt;br /&gt;
== Project ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
&lt;br /&gt;
=== Task Description ===&lt;br /&gt;
&lt;br /&gt;
The project requires completion of the following tasks:&lt;br /&gt;
&lt;br /&gt;
# Integrate review data with author feedback data to help instructors grade the reviewers.&lt;br /&gt;
# Add a new column to give the length of reviews.&lt;br /&gt;
# Separate data from columns number of reviews and summary details.&lt;br /&gt;
# Create a new column to check if a reviewer added a link or a file.&lt;br /&gt;
# Create a new column to check the average author feedback rating per team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Workflow ===&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104619</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104619"/>
		<updated>2016-11-05T03:19:48Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* UI Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
== '''UI Testing''' ==&lt;br /&gt;
* How to test creation of new assignment with due dates using U(username: instructor6, password: password)I: [https://www.youtube.com/watch?v=zJILRQpSgn4]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104605</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104605"/>
		<updated>2016-11-05T02:53:37Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* UI Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
== '''UI Testing''' ==&lt;br /&gt;
* How to test creation of new assignment with due dates using UI: [https://www.youtube.com/watch?v=zJILRQpSgn4]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104603</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104603"/>
		<updated>2016-11-05T02:53:12Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Testing The System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
== '''UI Testing''' ==&lt;br /&gt;
* How to test creation of new assignment with due dates using UI:&lt;br /&gt;
[https://www.youtube.com/watch?v=zJILRQpSgn4]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104602</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104602"/>
		<updated>2016-11-05T02:52:54Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* UI Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
[http://www.example.com link title]== '''UI Testing''' ==&lt;br /&gt;
* How to test creation of new assignment with due dates using UI:&lt;br /&gt;
[https://www.youtube.com/watch?v=zJILRQpSgn4]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104601</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104601"/>
		<updated>2016-11-05T02:52:16Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Screencast&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
== '''UI Testing''' ==&lt;br /&gt;
* How to test creation of new assignment with due dates using UI:&lt;br /&gt;
[[Media:https://www.youtube.com/watch?v=zJILRQpSgn4]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104581</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104581"/>
		<updated>2016-11-05T01:10:46Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Testing The System''' ==&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104580</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104580"/>
		<updated>2016-11-05T01:10:21Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== '''Testing The System''' ===&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104579</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104579"/>
		<updated>2016-11-05T01:09:26Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== '''Testing The System''' ===&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104578</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104578"/>
		<updated>2016-11-05T01:08:38Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;&amp;quot;Testing The System&amp;quot;&amp;quot; ===&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104577</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104577"/>
		<updated>2016-11-05T01:08:15Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Testing The System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== Testing The System ===&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
* rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
* rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104576</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104576"/>
		<updated>2016-11-05T01:07:09Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Testing The System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== Testing The System ===&lt;br /&gt;
Run the following commands to test the new RSpec files created: &amp;lt;/br&amp;gt;&lt;br /&gt;
1. rspec spec/models/deadline_helper_spec.rb &amp;lt;/br&amp;gt;&lt;br /&gt;
2. rspec spec/models/due_date_spec.rb &amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104575</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=104575"/>
		<updated>2016-11-05T01:06:45Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: Testing the System Section Added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== Testing The System ===&lt;br /&gt;
Run the following commands to test the new RSpec files created:&lt;br /&gt;
1. rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
2. rspec spec/models/due_date_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103617</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103617"/>
		<updated>2016-10-29T01:53:12Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: References Added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103616</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103616"/>
		<updated>2016-10-29T01:52:10Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;{{Cite web|url=https://expertiza.ncsu.edu/|title=|last=|first=|date=|website=|publisher=|access-date=}}&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103614</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103614"/>
		<updated>2016-10-29T01:51:39Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Sources and Citations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103613</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103613"/>
		<updated>2016-10-29T01:51:13Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Sources and Citations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103610</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103610"/>
		<updated>2016-10-29T01:48:00Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Tasks Identified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt; files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103608</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103608"/>
		<updated>2016-10-29T01:47:45Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Tasks Identified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;http://www.rspec.info&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103607</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103607"/>
		<updated>2016-10-29T01:47:21Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* deadline_helper_spec.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;http://www.semaphoreci.com|access-date&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103605</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103605"/>
		<updated>2016-10-29T01:46:55Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* RSpec testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;http://www.travis-ci.com&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103602</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103602"/>
		<updated>2016-10-29T01:46:26Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Code Climate */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com/dashboard&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.travis-ci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103596</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103596"/>
		<updated>2016-10-29T01:44:35Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;{{Cite web|url=https://codeclimate.com/dashboard|title=Log in to your Code Climate dashboard with GitHub or your email.|website=codeclimate.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.travis-ci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
==Sources and Citations==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103590</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103590"/>
		<updated>2016-10-29T01:42:26Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;http://www.expertiza.ncsu.edu&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;http://www.rubyonrails.org&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;{{Cite web|url=https://codeclimate.com/dashboard|title=Log in to your Code Climate dashboard with GitHub or your email.|website=codeclimate.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.travis-ci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;quot;[http://www.expertiza.ncsu.edu]&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Ruby on Rails]&amp;quot;. [http://www.rubyonrails.org]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Log in to your Code Climate dashboard with GitHub or your email].&amp;quot;. [http://www.codeclimate.com]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[RSpec: Behaviour Driven Development for Ruby]&amp;quot;. [http://www.rspec.info]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Travis CI - Test and Deploy with Confidence]&amp;quot;. [http://www.travis-ci.com link title]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Working Effectively with Data Factories Using FactoryGirl]&amp;quot;. [http://www.semaphoreci.com]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103587</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103587"/>
		<updated>2016-10-29T01:39:20Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;{{Cite web|url=http://www.expertiza.ncsu.edu|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;{{Reflist}} is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rubyonrails.org|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;{{Cite web|url=https://codeclimate.com/dashboard|title=Log in to your Code Climate dashboard with GitHub or your email.|website=codeclimate.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.travis-ci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;quot;[http://www.expertiza.ncsu.edu]&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Ruby on Rails]&amp;quot;. [http://www.rubyonrails.org]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Log in to your Code Climate dashboard with GitHub or your email].&amp;quot;. [http://www.codeclimate.com]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[RSpec: Behaviour Driven Development for Ruby]&amp;quot;. [http://www.rspec.info]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Travis CI - Test and Deploy with Confidence]&amp;quot;. [http://www.travis-ci.com link title]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Working Effectively with Data Factories Using FactoryGirl]&amp;quot;. [http://www.semaphoreci.com]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103575</id>
		<title>CSC/ECE 517 Fall 2016/E1634. Refactor and write unit test of due date.rb and deadline helper.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2016/E1634._Refactor_and_write_unit_test_of_due_date.rb_and_deadline_helper.rb&amp;diff=103575"/>
		<updated>2016-10-29T01:30:21Z</updated>

		<summary type="html">&lt;p&gt;Aagrawa6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza ===&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;{{Cite web|url=http://www.expertiza.ncsu.edu|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is an open source project for school assignment management for instructors and students based on the Ruby on Rails&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rubyonrails.org|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; framework. Expertiza allows the instructor to create new assignments and customise 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 word documents. Expertiza provides a dashboard for all the assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistants. In addition to assignments, it encompasses peer reviews wherein participants are allowed to provide feedback anonymously about each other's work thereby providing scope for the better outcome. The due_date.rb file is responsible for informing the users about the deadline for submission of the each assignment. Due dates in Expertiza have their association with many other components like assignments, reviews etc.&lt;br /&gt;
&lt;br /&gt;
=== Code Climate ===&lt;br /&gt;
Code Climate&amp;lt;ref&amp;gt;{{Cite web|url=https://codeclimate.com/dashboard|title=Log in to your Code Climate dashboard with GitHub or your email.|website=codeclimate.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is a tool that runs static analysis on a GitHub project and outputs many details like test coverage, complexity, duplication, security, style, and more. There is a Google Chrome extension to integrate the Code Climate results generated directly into GitHub which is visible when browsing the repository on the browser. It allows us to see issues displayed directly inside GitHub's UI, to review which lines are covered in diffs and files, and add repositories and open tickets without changing your workflow.&lt;br /&gt;
&lt;br /&gt;
== '''Tasks Identified''' ==&lt;br /&gt;
To install Code climate Chrome Extension that highlights the duplicated code.&lt;br /&gt;
&lt;br /&gt;
To refactor the following two files:&lt;br /&gt;
* due_date.rb&lt;br /&gt;
** Ternary operators must not be nested. Prefer `if` or `else` constructs instead.&lt;br /&gt;
** Useless assignment to variable - `sorted_deadlines`.&lt;br /&gt;
** Prefer `each` over `for`.&lt;br /&gt;
** Use `find_by` instead of `where.first`.&lt;br /&gt;
** Correct the use of Time function&lt;br /&gt;
* deadline_helper.rb&lt;br /&gt;
** Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.to_i`, `Time.now.to_f` instead.&lt;br /&gt;
** Trailing whitespace detected.&lt;br /&gt;
** Extra empty line detected at module body end.&lt;br /&gt;
&lt;br /&gt;
* Create respective RSpec&amp;lt;ref&amp;gt;{{Cite web|url=http://www.rspec.info|access-date=2016-10-28}}&amp;lt;/ref&amp;gt;files in /spec/models/ and /spec/helper folder and write unit tests for each method in due_date.rb and deadline_helper.rb.&lt;br /&gt;
&lt;br /&gt;
== '''Current Implementation''' ==&lt;br /&gt;
DueDate is a Model class to manage the deadlines of an assignment. It has methods for setting due dates for an assignment, copying due dates from one assignment to a new assignment etc. DeadlineHelper provides helper functions that help DueDate perform certain tasks. The assignment focuses on refactoring some of the methods based on warnings received from Code Climate's static analysis and modifying the language to make it more Ruby-friendly. The assignment also involves writing unit test cases for due_date.rb and deadline_helper.rb in order to increase test coverage. &lt;br /&gt;
&lt;br /&gt;
The goal of this project is to attempt to make this part of the application easier to read and write unit test cases that the application must pass. &lt;br /&gt;
&lt;br /&gt;
== '''Changed Implementation''' ==&lt;br /&gt;
Changes implemented involves refactoring the code and making it more understandable by adding comments in the code.&lt;br /&gt;
&lt;br /&gt;
The modified files are&lt;br /&gt;
* due_date.rb (path: /app/models)&lt;br /&gt;
* deadline_helper.rb (path: /app/helpers)&lt;br /&gt;
Testing files&lt;br /&gt;
* due_date_spec.rb (path: /spec/models)&lt;br /&gt;
* deadline_helper_spec.rb (path: /spec/helpers)&lt;br /&gt;
&lt;br /&gt;
=== due_date.rb ===&lt;br /&gt;
* Converted for..in loop to object.each in order to follow better Ruby syntax.&lt;br /&gt;
* Unnecessary assignment to sorted_deadlines removed.&lt;br /&gt;
* Nested ternary operators have been changed to if..else in order to make it more readable.&lt;br /&gt;
[[File:Duedaterb.png]]&lt;br /&gt;
* Changed where(...).first to find_by(...) which is the newer recommended syntax.&lt;br /&gt;
* Corrected the Time.now functions by adding the correct zones to them such as Time.zone.now.&lt;br /&gt;
* Removed trailing whitespaces.&lt;br /&gt;
[[File:DueDaterb2.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper.rb ===&lt;br /&gt;
* Time functions were changed to functions with zones&lt;br /&gt;
* Extra line removed&lt;br /&gt;
[[File:Deadlinehelper.png]]&lt;br /&gt;
&lt;br /&gt;
== '''RSpec testing''' ==&lt;br /&gt;
There were no existing tests for the functions in due_date.rb and deadline_helper.rb. We have added exhaustive set of RSpec tests to test all the code. We have added two new spec files 'due_date_spec.rb' and ‘deadline_helper_spec.rb’ which cover the testing scenarios for the functions in ‘due_date.rb’ and ‘deadline_helper.rb’. &lt;br /&gt;
&lt;br /&gt;
For both of these two files, all Travis CI&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.travis-ci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; test cases have passed for all previous test cases as well as the ones added by us with the test coverage for the files due_date.rb and deadline_helper.rb reported as 100%.&lt;br /&gt;
&lt;br /&gt;
These RSpec files have 100% code coverage visible at: /coverage/index.html.&lt;br /&gt;
&lt;br /&gt;
=== due_date_spec.rb ===&lt;br /&gt;
This file is located at spec/models and tests the functionalities of the due_date.rb file located in app/models. There are 18 test cases in total which are listed below.&lt;br /&gt;
* If the factory is successfully able to build the due_date objects.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date factory created successfully&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due dates created correctly&amp;quot; do&lt;br /&gt;
    expect(@due_dates.length).to be == 10&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;set_flag&amp;quot; successfully sets the due_date flag.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due date flag is set&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.flag).to be false&lt;br /&gt;
    @assignment_due_date.set_flag&lt;br /&gt;
    expect(@assignment_due_date.flag).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;due_at_is_valid_datetime&amp;quot; returns nil (no errors) for a valid datetime in due_at (no invalid test cases can be added here because model does not allow invalid datetime to be set at all).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due at is valid datetime&amp;quot; do&lt;br /&gt;
    expect(@assignment_due_date.due_at_is_valid_datetime).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.copy&amp;quot; is able to copy due dates from one assignment to another.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;copy due dates to new assignment&amp;quot; do&lt;br /&gt;
    new_assignment_id = build(:assignment, id: 999).id&lt;br /&gt;
    old_assignment_id = @assignment_due_date.assignment.id&lt;br /&gt;
    DueDate.copy(old_assignment_id, new_assignment_id)&lt;br /&gt;
    expect(DueDate.where(parent_id: new_assignment_id).count).to eql DueDate.where(parent_id: old_assignment_id).count&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.set_duedate&amp;quot; is able to create another due date by copying data from an existing due date object.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;create new duedate record with values&amp;quot; do&lt;br /&gt;
    DueDate.set_duedate({id: 999}, @assignment_due_date.deadline_type_id,&lt;br /&gt;
                        @assignment_due_date.parent_id, @assignment_due_date.round)&lt;br /&gt;
    new_due_date = DueDate.find_by(id: 999)&lt;br /&gt;
    expect(new_due_date).to be_valid&lt;br /&gt;
    expect(new_due_date.deadline_type_id).to eql @assignment_due_date.deadline_type_id&lt;br /&gt;
    expect(new_due_date.parent_id).to eql @assignment_due_date.parent_id&lt;br /&gt;
    expect(new_due_date.round).to eql @assignment_due_date.round&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.deadline_sort&amp;quot; is able to sort the due dates in ascending order.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;sort duedate records&amp;quot; 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 = DueDate.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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.done_in_assignment_round&amp;quot; returns the correct number of rounds for specific inputs. This involves an invalid test case as well for 0 rounds.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#done_in_assignment_round&amp;quot; do&lt;br /&gt;
    it &amp;quot;return 0 when no response map&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      response.type = &amp;quot;ResponseMap&amp;quot;&lt;br /&gt;
      response.save&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(1, response)).to eql 0&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;return round 1 for single round&amp;quot; do&lt;br /&gt;
      response = ReviewResponseMap.create&lt;br /&gt;
      expect(DueDate.done_in_assignment_round(@assignment_due_date.parent_id, response)).to eql 1&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.get_next_due_date&amp;quot; works as expected. This involves several invalid test cases as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe &amp;quot;#get_next_due_date&amp;quot; do&lt;br /&gt;
    it &amp;quot;no subsequent due date&amp;quot; do&lt;br /&gt;
      expect(DueDate.get_next_due_date(@assignment_due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;nil value throws exception&amp;quot; do&lt;br /&gt;
      expect { DueDate.get_next_due_date(nil) }.to raise_exception(ActiveRecord::RecordNotFound)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next assignment due date&amp;quot; do&lt;br /&gt;
      due_date = create(: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: Time.zone.now + 5000)&lt;br /&gt;
      expect(DueDate.get_next_due_date(due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from topic for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_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: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date does not exist for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;next due date is before Time.now for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:topic_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now - 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id, due_date.parent_id)).to be nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it &amp;quot;get next due date from assignment for staggered deadline&amp;quot; do&lt;br /&gt;
      assignment_id = create(:assignment, staggered_deadline: true, name: &amp;quot;testassignment&amp;quot;).id&lt;br /&gt;
      due_date = create(:assignment_due_date, deadline_type: @deadline_type,&lt;br /&gt;
        submission_allowed_id: @deadline_right, review_allowed_id: @deadline_right,&lt;br /&gt;
        review_of_review_allowed_id: @deadline_right, due_at: Time.zone.now + 5000, parent_id: assignment_id)&lt;br /&gt;
      expect(DueDate.get_next_due_date(assignment_id)).to be_valid&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the function &amp;quot;self.default_permission&amp;quot; returns the correct default permissions for particular deadline and permission types.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;metareview review_of_review_allowed default permission OK&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('metareview', 'review_of_review_allowed')).to be == DeadlineRight::OK&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;review submission_allowed default permission NO&amp;quot; do&lt;br /&gt;
    expect(DueDate.default_permission('review', 'submission_allowed')).to be == DeadlineRight::NO&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/due_date_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Duedaterspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Duedatecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== deadline_helper_spec.rb ===&lt;br /&gt;
This is a test file for testing the functionalities of Deadline_helper.rb file located at app/helpers. Different test cases present in this file are:&lt;br /&gt;
* Check if the factory&amp;lt;ref&amp;gt;{{Cite web|url=http://http://www.semaphoreci.com|access-date=2016-10-28}}&amp;lt;/ref&amp;gt; is valid:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;has a valid factory&amp;quot; do&lt;br /&gt;
    factory = FactoryGirl.build(:topic_due_date)&lt;br /&gt;
    expect(factory).to be_valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Fail if the due date is invalid:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;should fail because of invalid due_date&amp;quot; do&lt;br /&gt;
      expect { DeadlineHelper.create_topic_deadline(nil, 0, 0)}.to raise_exception(NoMethodError)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If new due_date object is created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;new due_date object created&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 1)&lt;br /&gt;
      expect(TopicDueDate.count).to be == 2&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at should be same for 0 offset:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 it &amp;quot;due_at should be same for 0 offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 0, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == @topic_due_date.due_at.to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is positive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for positive offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* due_at is calculated correctly if offset is negative:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;due_at calculated correctly for negative offset&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, -5000, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) - 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The offset is being converted to integer properly:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it &amp;quot;offset converted to integer correctly&amp;quot; do&lt;br /&gt;
      DeadlineHelper.create_topic_deadline(@topic_due_date, 5000.15, 10)&lt;br /&gt;
      new_due_date = TopicDueDate.find_by(parent_id: 10)&lt;br /&gt;
      expect(new_due_date).to be_valid&lt;br /&gt;
      expect(new_due_date.due_at.to_s).to be == (Time.zone.parse(@topic_due_date.due_at.to_s) + 5000).to_s&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To test this file run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/models/deadline_helper_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The output of this RSpec file is present in below screenshot:&lt;br /&gt;
[[File:Deadlinerspec.png]]&lt;br /&gt;
&lt;br /&gt;
Code coverage details of the above RSpec files is present in below screenshot:&lt;br /&gt;
[[File:Deadlinecoverage.png]]&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;quot;[http://www.expertiza.ncsu.edu]&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Ruby on Rails]&amp;quot;. [http://www.rubyonrails.org]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Log in to your Code Climate dashboard with GitHub or your email].&amp;quot;. [http://www.codeclimate.com]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[RSpec: Behaviour Driven Development for Ruby]&amp;quot;. [http://www.rspec.info]. Retrieved 2016-10-28.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Travis CI - Test and Deploy with Confidence]&amp;quot;. [http://www.travis-ci.com link title]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;[Working Effectively with Data Factories Using FactoryGirl]&amp;quot;. [http://www.semaphoreci.com]. Retrieved 2016-10-28&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aagrawa6</name></author>
	</entry>
</feed>