<?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=Jwboykin</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=Jwboykin"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jwboykin"/>
	<updated>2026-09-08T23:41:50Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123749</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123749"/>
		<updated>2019-04-11T05:52:06Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Each submission on the submissions page should link to &amp;quot;perform review&amp;quot; instead of &amp;quot;assign grade&amp;quot; iff [the instructor/ta is a participant of the assignment and the last due date for the assignment has not passed]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
list_submissions_html.erb should be modified to change the link as noted above. TBD if controller changes in assignment_controler are needed to get due date information and participant information to the view.&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Review page should allow instructor/TA to submit review if they are a participant of the assignment and the last due date hasn't passed&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Check response.html.erb to make sure there aren't any restrictions preventing instructor/ta from submitting reviews if they meet the criteria above. Existing logic may assume all reviewers are student. TBD if any modifications to response_controller is necessary to enable this functionality.&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify response.html.erb to distinguish reviews done by the instructor. TBD if the response controller needs modification to deliver this information to the view. Modify the add-ta-128.png icon file to look more like an instructor and add it to the view next to the reviews done by the instructor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 4: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
From the assignment page student_task/view.html.erb add a new link reviewers to the calibration report _calibration_report.html.erb IF they have submitted a review and the instructor has submitted a review to the same assignment.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
The following shall be tested:&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is a participant and the last due date is not past then the submission list should link to &amp;quot;perform review&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is a participant and the last due date is past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is not a participant and the last due date is past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is not a participant and the last due date is not past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A review submitted by an instructor/ta should be accepted like any other review so long as they are a participant and the last submission due date has not passed&lt;br /&gt;
&lt;br /&gt;
Optional: Test optional functionality&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
5. Projected hosted at: http://final.flazzle.com&lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123748</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123748"/>
		<updated>2019-04-11T05:51:13Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Each submission on the submissions page should link to &amp;quot;perform review&amp;quot; instead of &amp;quot;assign grade&amp;quot; iff [the instructor/ta is a participant of the assignment and the last due date for the assignment has not passed]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
list_submissions_html.erb should be modified to change the link as noted above. TBD if controller changes in assignment_controler are needed to get due date information and participant information to the view.&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Review page should allow instructor/TA to submit review if they are a participant of the assignment and the last due date hasn't passed&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Check response.html.erb to make sure there aren't any restrictions preventing instructor/ta from submitting reviews if they meet the criteria above. Existing logic may assume all reviewers are student. TBD if any modifications to response_controller is necessary to enable this functionality.&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify response.html.erb to distinguish reviews done by the instructor. TBD if the response controller needs modification to deliver this information to the view. Modify the add-ta-128.png icon file to look more like an instructor and add it to the view next to the reviews done by the instructor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 4: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
From the assignment page student_task/view.html.erb add a new link reviewers to the calibration report _calibration_report.html.erb IF they have submitted a review and the instructor has submitted a review to the same assignment.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
The following shall be tested:&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is a participant and the last due date is not past then the submission list should link to &amp;quot;perform review&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is a participant and the last due date is past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is not a participant and the last due date is past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For a given assignment, If instructor/ta is not a participant and the last due date is not past then the submission list should link to &amp;quot;assign grade&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A review submitted by an instructor/ta should be accepted like any other review so long as they are a participant and the last submission due date has not passed&lt;br /&gt;
&lt;br /&gt;
Optional: Test optional functionality&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews &lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123747</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123747"/>
		<updated>2019-04-11T05:45:58Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Project Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Each submission on the submissions page should link to &amp;quot;perform review&amp;quot; instead of &amp;quot;assign grade&amp;quot; iff [the instructor/ta is a participant of the assignment and the last due date for the assignment has not passed]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
list_submissions_html.erb should be modified to change the link as noted above. TBD if controller changes in assignment_controler are needed to get due date information and participant information to the view.&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Review page should allow instructor/TA to submit review if they are a participant of the assignment and the last due date hasn't passed&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Check response.html.erb to make sure there aren't any restrictions preventing instructor/ta from submitting reviews if they meet the criteria above. Existing logic may assume all reviewers are student. TBD if any modifications to response_controller is necessary to enable this functionality.&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify response.html.erb to distinguish reviews done by the instructor. TBD if the response controller needs modification to deliver this information to the view. Modify the add-ta-128.png icon file to look more like an instructor and add it to the view next to the reviews done by the instructor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 4: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
From the assignment page student_task/view.html.erb add a new link reviewers to the calibration report _calibration_report.html.erb IF they have submitted a review and the instructor has submitted a review to the same assignment.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
Write testing methodology (logic) here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews &lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123746</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123746"/>
		<updated>2019-04-11T05:45:20Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Project Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Each submission on the submissions page should link to &amp;quot;perform review&amp;quot; instead of &amp;quot;assign grade&amp;quot; iff [the instructor/ta is a participant of the assignment and the last due date for the assignment has not passed]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
list_submissions_html.erb should be modified to change the link as noted above. TBD if controller changes in assignment_controler are needed to get due date information and participant information to the view.&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Review page should allow instructor/TA to submit review if they are a participant of the assignment and the last due date hasn't passed&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Check response.html.erb to make sure there aren't any restrictions preventing instructor/ta from submitting reviews if they meet the criteria above. Existing logic may assume all reviewers are student. TBD if any modifications to response_controller is necessary to enable this functionality.&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify response.html.erb to distinguish reviews done by the instructor. TBD if the response controller needs modification to deliver this information to the view. Modify the add-ta-128.png icon file to look more like an instructor and add it to the view next to the reviews done by the instructor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
==Task 4:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Refactor:  A &amp;quot;course_staff&amp;quot; column was added to the &amp;quot;response_maps&amp;quot; table.  Is it really necessary to have a column named as &amp;quot;course_staff&amp;quot; for reviews?&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Remove the column name from the response maps, if it exists.&lt;br /&gt;
&lt;br /&gt;
Find another way of indicating the review is an instructor review.&lt;br /&gt;
&lt;br /&gt;
==Task 5: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
From the assignment page student_task/view.html.erb add a new link reviewers to the calibration report _calibration_report.html.erb IF they have submitted a review and the instructor has submitted a review to the same assignment.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
Write testing methodology (logic) here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews &lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123745</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123745"/>
		<updated>2019-04-11T05:31:58Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Project Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Each submission on the submissions page should link to &amp;quot;perform review&amp;quot; instead of &amp;quot;assign grade&amp;quot; iff [the instructor/ta is a participant of the assignment and the last due date for the assignment has not passed]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
list_submissions_html.erb should be modified to change the link as noted above. TBD if controller changes in assignment_controler are needed to get due date information and participant information to the view.&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Review page should allow instructor/TA to submit review if they are a participant of the assignment and the last due date hasn't passed&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Check response.html.erb to make sure there aren't any restrictions preventing instructor/ta from submitting reviews if they meet the criteria above. Existing logic may assume all reviewers are student. TBD if any modifications to response_controller is necessary to enable this functionality.&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify the add-ta-128.png icon file to look more like an instructor and add it to the view.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
==Task 4:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Refactor:  A &amp;quot;course_staff&amp;quot; column was added to the &amp;quot;response_maps&amp;quot; table.  Is it really necessary to have a column named as &amp;quot;course_staff&amp;quot; for reviews?&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Remove the column name from the response maps, if it exists.&lt;br /&gt;
&lt;br /&gt;
Find another way of indicating the review is an instructor review.&lt;br /&gt;
&lt;br /&gt;
==Task 5: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
Write testing methodology (logic) here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews &lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123744</id>
		<title>CSC/ECE 517 Spring 2019/E1927 Let Course Staff as Well as Students Do Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019/E1927_Let_Course_Staff_as_Well_as_Students_Do_Reviews&amp;diff=123744"/>
		<updated>2019-04-11T05:11:32Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''Problem Summary'''=&lt;br /&gt;
In Expertiza, students are able to perform reviews on other students work by filling out a review form on Expertiza.  Instructors and TAs for the course should be able to submit a review in the same manner as a student.  Only instructors or TAs who are participants in the assignment should be allowed to leave reviews. However, the instructor and TA reviews should be distinguished from other student reviews so the student knows the review was written by the instructor.&lt;br /&gt;
&lt;br /&gt;
='''Project Tasks'''=&lt;br /&gt;
&lt;br /&gt;
==Task 1:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor or TA who is a participant of an assignment, then the instructor should be able to review any team that submitted the assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
(Find the code that validates the TA is a participant.  See the comments in the project description for more information.)&lt;br /&gt;
&lt;br /&gt;
==Task 2:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
If the last due date for the assignment has not passed, then the “Assign grade” link should be changed to “Perform review”, and when clicked on, it should pull up a review page for the team, showing their submitted work at the top, as a review page normally does.&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
(Put the name of the file to be revised here.  Show the current code, the revised code, and your results.)&lt;br /&gt;
&lt;br /&gt;
==Task 3:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
An instructor icon should be used to indicate an instructor review and this icon should be seen on the instructor review page read by the student.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
&lt;br /&gt;
Modify the add-ta-128.png icon file to look more like an instructor and add it to the view.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1927_Add-ta-128.png|alt=Add a TA]]&lt;br /&gt;
&lt;br /&gt;
==Task 4:==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Refactor:  A &amp;quot;course_staff&amp;quot; column was added to the &amp;quot;response_maps&amp;quot; table.  Is it really necessary to have a column named as &amp;quot;course_staff&amp;quot; for reviews?&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Remove the column name from the response maps, if it exists.&lt;br /&gt;
&lt;br /&gt;
Find another way of indicating the review is an instructor review.&lt;br /&gt;
&lt;br /&gt;
==Task 5: (OPTIONAL)==&lt;br /&gt;
'''Problem:'''&lt;br /&gt;
&lt;br /&gt;
Similar to the calibration report from the Design Exercise assignment, create a view that would allow the student reviewers differ from the reviews completed by the course staff.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Solution:'''&lt;br /&gt;
Review the code from the Design Exercise calibration assignment.  Discuss ideas with the professor (as advised from previous mentor meetings) to form a plan on how to address this task.&lt;br /&gt;
&lt;br /&gt;
='''Test Plan'''=&lt;br /&gt;
Write testing methodology (logic) here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
1.  Project Document: https://docs.google.com/document/d/1Ozw2Bj2u_LyeKUdDqAyQtz1stEIKrxkmRnwmNyUgmzw/edit#heading=h.bumi2mscmmgf&lt;br /&gt;
&lt;br /&gt;
2.  Github Repo: https://github.com/mblewallncsu/expertiza&lt;br /&gt;
&lt;br /&gt;
3.  Previous Work, Project E1824:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1824:_Let_course_staff_as_well_as_students_do_reviews&lt;br /&gt;
&lt;br /&gt;
4.  Previous Work, Project E1855:  http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1855_let_course_staff_as_well_as_students_do_reviews &lt;br /&gt;
&lt;br /&gt;
='''Team Members'''=&lt;br /&gt;
&lt;br /&gt;
1. Jimmy Boykin&lt;br /&gt;
&lt;br /&gt;
2. Srikara Krishna &lt;br /&gt;
&lt;br /&gt;
3. Michael Lewallen&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122151</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122151"/>
		<updated>2019-03-25T19:00:05Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
&lt;br /&gt;
[[File:Big1.png]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
[[File:big2.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122150</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122150"/>
		<updated>2019-03-25T18:59:39Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Big1.png]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:big2.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Big2.png&amp;diff=122149</id>
		<title>File:Big2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Big2.png&amp;diff=122149"/>
		<updated>2019-03-25T18:59:25Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122148</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122148"/>
		<updated>2019-03-25T18:58:30Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Big1.png]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.41.51_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Big1.png&amp;diff=122146</id>
		<title>File:Big1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Big1.png&amp;diff=122146"/>
		<updated>2019-03-25T18:58:06Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122144</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122144"/>
		<updated>2019-03-25T18:53:18Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.42.04_PM.png]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.41.51_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122143</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122143"/>
		<updated>2019-03-25T18:52:10Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.42.04_PM.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.41.51_PM.png|800px]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122141</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122141"/>
		<updated>2019-03-25T18:50:20Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #returns the next due date&lt;br /&gt;
  def next_due_date(topic_id = nil)&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.42.04_PM.png] | width 200]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.41.51_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122136</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122136"/>
		<updated>2019-03-25T18:46:19Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.33.27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 7'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. &lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.42.04_PM.png]]&lt;br /&gt;
&lt;br /&gt;
Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.41.51_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.42.04_PM.png&amp;diff=122135</id>
		<title>File:Screen Shot 2019-03-25 at 2.42.04 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.42.04_PM.png&amp;diff=122135"/>
		<updated>2019-03-25T18:44:24Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: assignment modify url view&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;assignment modify url view&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.41.51_PM.png&amp;diff=122134</id>
		<title>File:Screen Shot 2019-03-25 at 2.41.51 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.41.51_PM.png&amp;diff=122134"/>
		<updated>2019-03-25T18:43:43Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: assignment remove link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;assignment remove link&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122132</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122132"/>
		<updated>2019-03-25T18:37:55Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
[[File:Screen_Shot_2019-03-25_at_2.33.27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122131</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122131"/>
		<updated>2019-03-25T18:37:41Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
[[File:creen_Shot_2019-03-25_at_2.33.27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.33.27_PM.png&amp;diff=122130</id>
		<title>File:Screen Shot 2019-03-25 at 2.33.27 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2019-03-25_at_2.33.27_PM.png&amp;diff=122130"/>
		<updated>2019-03-25T18:36:57Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: refactor current stage name screenshot&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;refactor current stage name screenshot&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122126</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122126"/>
		<updated>2019-03-25T18:32:34Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
Multiple functions in the code were calling DueDate.get_next_due_date(self.id, topic_id). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
A new private function next_due_date was added. Other calls to the DueDate.get_next_due_date were replaced.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122125</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122125"/>
		<updated>2019-03-25T18:29:19Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122123</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122123"/>
		<updated>2019-03-25T18:26:29Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Solutions Implemented */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was like nesting of calls and not very Ruby standard.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil)[This is the initial one] method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After removing the current_stage_name method, its uses were replaced with current_stage_name. One example of the refactoring is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Current_stage.png|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122118</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122118"/>
		<updated>2019-03-25T17:54:58Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: /* Problem 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was creating a chain of calls.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to get_current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with get_current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil) method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if topic_missing?(topic_id)&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After removing the current_stage_name method, its uses were replaced with get_current_stage_name. One example of the refactoring is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Current_stage.png|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
link_for_current_stage function served no purpose. The function checked to see if any given due date had a link (presumably web URL) and would return it. The database had no values and there is no where in the application this URL could be provided. There doesn't appear to be any use for having a separate URL for each stage.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
Removed function. Removed test related to the function. Removed the one call to this function.&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to get_current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#get_current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.get_current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.get_current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.get_current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_E1906_Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122112</id>
		<title>CSC/ECE 517 Spring 2019 E1906 Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_E1906_Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122112"/>
		<updated>2019-03-25T17:48:39Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: moved CSC/ECE 517 Spring 2019 E1906 Refactor stage deadlines in Assignment.rb to CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb]]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122111</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1906._Refactor_stage_deadlines_in_Assignment.rb&amp;diff=122111"/>
		<updated>2019-03-25T17:48:39Z</updated>

		<summary type="html">&lt;p&gt;Jwboykin: moved CSC/ECE 517 Spring 2019 E1906 Refactor stage deadlines in Assignment.rb to CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
=='''Expertiza Background'''==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github [https://github.com/expertiza/expertiza Expertiza on GitHub].Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.&lt;br /&gt;
&lt;br /&gt;
=='''Stage Deadline Background'''==&lt;br /&gt;
An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called &amp;quot;stage&amp;quot;.For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a &amp;quot;submission&amp;quot; phase.&lt;br /&gt;
&lt;br /&gt;
[[File: StageBackground.png|center]]&lt;br /&gt;
&lt;br /&gt;
Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the &amp;quot;Other's work&amp;quot; link is grayed out as review is not permissible during submission phase.&lt;br /&gt;
&lt;br /&gt;
[[File: Statusinadeadline.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
=='''Important Links'''==&lt;br /&gt;
&lt;br /&gt;
[http://oss.flazzle.com/ Deployed_Project_Link]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jwboykin/expertiza Expertiza_Link_for_this_Project]&lt;br /&gt;
&lt;br /&gt;
=='''Problem Statement'''==&lt;br /&gt;
E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:&lt;br /&gt;
&lt;br /&gt;
* current_stage_name(topic_id = nil)&lt;br /&gt;
* find_current_stage(topic_id = nil)&lt;br /&gt;
* get_current_stage(topic_id = nil)&lt;br /&gt;
* link_for_current_stage(topic_id = nil)&lt;br /&gt;
* stage_deadline(topic_id = nil)&lt;br /&gt;
&lt;br /&gt;
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.&lt;br /&gt;
&lt;br /&gt;
=='''Solutions Implemented'''==&lt;br /&gt;
&lt;br /&gt;
==='''Problem 1'''===&lt;br /&gt;
&lt;br /&gt;
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have created a new method &amp;quot;finished?&amp;quot; that checks if the next_due_date is nil (which means that the assignment is &amp;quot;finished&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # New function to check if the assignment is finished&lt;br /&gt;
  def finished?( topic_id = nil )&lt;br /&gt;
    DueDate.get_next_due_date(self.id, topic_id).nil?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have called this method at all the places where previously different methods were being used to check the same thing.&lt;br /&gt;
*Signup sheet table uses assignment finished? method instead of current_stage_name&lt;br /&gt;
[[File:Problem1_1.png‎|center]]&lt;br /&gt;
&lt;br /&gt;
*Use assignment finished? method where only a comparison to &amp;quot;Finished&amp;quot; was being done using get_current_stage and find_current_stage&lt;br /&gt;
[[File:Problem1_2.png|center]] [[File:Problem1_3.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 2'''===&lt;br /&gt;
&lt;br /&gt;
The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
To make the code DRY and more easy to understand,we have created a new private method &amp;quot;topic_missing?&amp;quot; to check if the topic_id is nil in case of staggered assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Function to check if topic id is null when its a staggered assignment&lt;br /&gt;
  def topic_missing?( topic_id = nil)&lt;br /&gt;
    topic_id.nil? and self.staggered_deadline?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactoring with new method topic_missing?&lt;br /&gt;
&lt;br /&gt;
[[File:Topic missing.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 3'''===&lt;br /&gt;
&lt;br /&gt;
find_current_stage(topic_id=nil) method is being used only locally in the assignment.rb and once in the student_teams controller to check to check whether to display or not the reviews option for team members.This method was calling another function to get the next_due_date for an assignment that was creating a chain of calls.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have removed this function.We have replaced it with finished? method in the student_teams controller(shown in screenshot above in Problem 1) and with DueDate.get_next_due_date where the next due date was required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Before :&lt;br /&gt;
 due_date = find_current_stage(topic_id)&lt;br /&gt;
 &lt;br /&gt;
 After :&lt;br /&gt;
 due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Problem 4'''===&lt;br /&gt;
&lt;br /&gt;
get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
We have changed the method name to get_current_stage_name(topic_id=nil) to make it more clear to understand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Refactored get_current_stage with get_current_stage_name&lt;br /&gt;
&lt;br /&gt;
[[File:Get current stage name.png|center]]&lt;br /&gt;
&lt;br /&gt;
==='''Problem 5'''===&lt;br /&gt;
&lt;br /&gt;
current_stage_name(topic_id=nil) method was implementing things which was already being done by other methods and thus this method was redundant. &lt;br /&gt;
The initial code given was:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))&lt;br /&gt;
    end&lt;br /&gt;
    due_date = find_current_stage(topic_id)&lt;br /&gt;
&lt;br /&gt;
    unless self.staggered_deadline?&lt;br /&gt;
      if due_date != 'Finished' &amp;amp;&amp;amp; !due_date.nil? &amp;amp;&amp;amp; !due_date.deadline_name.nil?&lt;br /&gt;
        return due_date.deadline_name&lt;br /&gt;
      else&lt;br /&gt;
        return get_current_stage(topic_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First thing we noticed was that due_date.deadline_name was always nil because there was no field to enter the deadline name on the form, and therefore, the statement  &amp;lt;pre&amp;gt; return due_date.deadline_name &amp;lt;/pre&amp;gt; was never getting executed. &lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
This method was checking for the due_date.deadline_name which was always nil. After removing the dead code, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_stage_name(topic_id = nil)&lt;br /&gt;
    if self.staggered_deadline? and topic_id.nil?&lt;br /&gt;
      return 'Unknown'&lt;br /&gt;
    else&lt;br /&gt;
      get_current_stage(topic_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Looking at the get_current_stage_name(topic_id=nil) method shown below and comparing it to what we have above, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required within assignment.rb.&lt;br /&gt;
*Below is the get_current_stage_name method for reference&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_current_stage_name(topic_id = nil)&lt;br /&gt;
    return 'Unknown' if topic_missing?(topic_id)&lt;br /&gt;
    due_date = DueDate.get_next_due_date(self.id, topic_id)&lt;br /&gt;
    finished?(topic_id)? &amp;quot;Finished&amp;quot; : DeadlineType.find(due_date.deadline_type_id).name&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After removing the current_stage_name method, its uses were replaced with get_current_stage_name. One example of the refactoring is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Current_stage.png|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The associated rspec tests that tested the current_stage method were also no longer needed.&lt;br /&gt;
&lt;br /&gt;
==='''Problem 6'''===&lt;br /&gt;
&lt;br /&gt;
===='''Solution'''====&lt;br /&gt;
&lt;br /&gt;
=='''Automated Testing using RSPEC'''==&lt;br /&gt;
&lt;br /&gt;
===='''Tests for get_current_stage_name'''====&lt;br /&gt;
&lt;br /&gt;
The current version of expertiza did not have any tests for get_current_stage(topic_id=nil) method.Now as we have changed it to get_current_stage_name(topic_id=nil),we have added its tests as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#get_current_stage_name' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.get_current_stage_name).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns Finished' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.get_current_stage_name(123)).to eq('Finished')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns current stage name' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(assignment).to receive(:topic_missing?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1,123).and_return(assignment_due_date)&lt;br /&gt;
          deadline = create(:deadline_type, id: 1, name:&amp;quot;Review&amp;quot;)&lt;br /&gt;
          allow(DeadlineType).to receive(:find).with(1).and_return(deadline)&lt;br /&gt;
          expect(assignment.get_current_stage_name(123)).to eq('Review')&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===='''Tests for finished?'''====&lt;br /&gt;
&lt;br /&gt;
We have added tests for the new method that we have added finished?.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when assignment next due date is nil' do&lt;br /&gt;
      it 'returns True' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(nil)&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(TRUE)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#finished?' do&lt;br /&gt;
    context 'when there is a next due date' do&lt;br /&gt;
      it 'returns False' do&lt;br /&gt;
        allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return('2021-11-11 11:11:11')&lt;br /&gt;
        expect(assignment.finished?(123)).to eq(false)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As topic_missing? method is made private,there was no need to test this.&lt;br /&gt;
&lt;br /&gt;
===='''Tests for stage_deadline'''====&lt;br /&gt;
&lt;br /&gt;
We also have corrected the tests for stage_deadline according to the modifications done(It is using finished? and topic_missing? methods).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#stage_deadline' do&lt;br /&gt;
    context 'when topic id is nil and current assignment has staggered deadline' do&lt;br /&gt;
      it 'returns Unknown' do&lt;br /&gt;
        allow(assignment).to receive(:topic_missing?).and_return(true)&lt;br /&gt;
        expect(assignment.stage_deadline).to eq('Unknown')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when current assignment does not have staggered deadline' do&lt;br /&gt;
      context 'when due date is nil' do&lt;br /&gt;
        it 'returns nil' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(true)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to be nil&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when due date is not nil and due date is not equal to Finished' do&lt;br /&gt;
        it 'returns due date' do&lt;br /&gt;
          allow(assignment).to receive(:finished?).with(123).and_return(false)&lt;br /&gt;
          allow(DueDate).to receive(:get_next_due_date).with(1, 123).and_return(assignment_due_date)&lt;br /&gt;
          expect(assignment.stage_deadline(123)).to match('2011-11-11 11:11:11')&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Team'''==&lt;br /&gt;
[mailto:jwboykin@ncsu.edu Jimmy Boykin]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:rkaur@ncsu.edu Ramandeep Kaur]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:sbasnet2@ncsu.edu Sushan Basnet]&lt;/div&gt;</summary>
		<author><name>Jwboykin</name></author>
	</entry>
</feed>