<?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=Ppraman2</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=Ppraman2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ppraman2"/>
	<updated>2026-05-17T00:13:03Z</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_2017/E1731_Improve_Score_Calculation&amp;diff=107982</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107982"/>
		<updated>2017-04-07T00:34:24Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
The project can be broken down into two primary use cases.&lt;br /&gt;
&lt;br /&gt;
*  The user wants to view the scores before the assignment is finished.  Scores are calculated &amp;quot;on the fly&amp;quot; and presented to the user.&lt;br /&gt;
*  The user wants to view the scores after the assignment is finished.  Scores are calculated on assignment completion and stored in the database for quick retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The above two use cases can then be translated into three major scenarios we need to test.  The use case where the assignment is completed and scores are stored into the database is broken down into two scenarios to test the data input and data retrieval parts separately.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table contains the main scenarios we will cover when testing our project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following diagrams show how the chosen scenarios above map to functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107981</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107981"/>
		<updated>2017-04-07T00:31:47Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Use Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
The project can be broken down into two primary use cases.&lt;br /&gt;
&lt;br /&gt;
*  The user wants to view the scores before the assignment is finished.  Scores are calculated &amp;quot;on the fly&amp;quot; and presented to the user.&lt;br /&gt;
*  The user wants to view the scores after the assignment is finished.  Scores are calculated on assignment completion and stored in the database for quick retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table contains the main scenarios we will cover when testing our project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following diagrams show how the chosen scenarios above map to functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107980</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107980"/>
		<updated>2017-04-07T00:28:58Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Use Cases==&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table contains the main scenarios we will cover when testing our project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following diagrams show how the chosen scenarios above map to functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107979</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107979"/>
		<updated>2017-04-07T00:26:09Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table contains the main scenarios we will cover when testing our project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following diagrams show how the chosen scenarios above map to functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107978</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107978"/>
		<updated>2017-04-07T00:25:37Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table contains the main scenarios we will cover when testing our project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following diagrams show how the chosen scenarios above map to functionality&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107977</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107977"/>
		<updated>2017-04-07T00:24:10Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The &amp;quot;answers&amp;quot; table only contains the scores that user A has given user B on each criterion. This means that if we need to know what score A has given B based on 100, we have to rely on the code to calculate it every time the score is requested. This design slows down Expertiza as every time an instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. In this case, the system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanisms to handle the holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc&lt;br /&gt;
** This is similar to the current scenario&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, they will be fetched using a single db query and displayed&lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in the table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record to be inserted is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated and stored for each of the review rounds because it is possible that user A only reviews user B in one out of several rounds&lt;br /&gt;
* When a request is made to view the scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:E1731-scenario-1.jpg|frame|center]]  &lt;br /&gt;
[[File:E1731-scenario-2-3.jpg|frame|center]]&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E1731-scenario-2-3.jpg&amp;diff=107976</id>
		<title>File:E1731-scenario-2-3.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E1731-scenario-2-3.jpg&amp;diff=107976"/>
		<updated>2017-04-07T00:22:32Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E1731-scenario-1.jpg&amp;diff=107975</id>
		<title>File:E1731-scenario-1.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E1731-scenario-1.jpg&amp;diff=107975"/>
		<updated>2017-04-07T00:21:44Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107968</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107968"/>
		<updated>2017-04-06T23:53:06Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in this new db table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated for all the review rounds because it is possible that user A only review user B in one out of several rounds&lt;br /&gt;
* When a request is made to view scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Assignment is NOT finished and user wants to view scores.  First, set up an assignment with a deadline in the future.  Put in some score information.   The score should be calculated correctly on the fly using OnTheFlyCalc.&lt;br /&gt;
| After the assignment is created, this test will run on the UI.  The user will click the view scores link and the page should display the expected score.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Assignment is finished and the user wants to view scores.  This test will mainly just be a check if clicking view scores on the UI will result in the expected value showing up on the UI.  The interaction in getting the information in the database is already tested in Scenario 1.&lt;br /&gt;
| User clicks on view scores on a past assignment and sees the expected score on the UI&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107967</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107967"/>
		<updated>2017-04-06T23:42:14Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in this new db table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated for all the review rounds because it is possible that user A only review user B in one out of several rounds&lt;br /&gt;
* When a request is made to view scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| An assignment is finished and a score is calculated correctly and placed into the local_db_score table using the scheduled task feature.  First, set up an assignment with some score information.  Create a scheduled task to calculate the score and insert the score into the database upon assignment completion.&lt;br /&gt;
| Query the database and verify score is correct&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107964</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107964"/>
		<updated>2017-04-06T23:34:08Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in this new db table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated for all the review rounds because it is possible that user A only review user B in one out of several rounds&lt;br /&gt;
* When a request is made to view scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Description&lt;br /&gt;
! Expected Result for Pass&lt;br /&gt;
|-&lt;br /&gt;
| row 1, cell 1&lt;br /&gt;
| row 1, cell 2&lt;br /&gt;
| row 1, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107963</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107963"/>
		<updated>2017-04-06T23:28:45Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;br /&gt;
* A general ScoreCalc class will be created&lt;br /&gt;
* OnTheFlyCalc and LocalDBCalc classes will be created which will be subclasses of ScoreCalc class&lt;br /&gt;
* A new database table &amp;quot;local_db_scores&amp;quot; with following columns will be created to store the holistic scores:&lt;br /&gt;
** id: int&lt;br /&gt;
** type: string&lt;br /&gt;
** round: int&lt;br /&gt;
** score: int&lt;br /&gt;
** reference_id: int&lt;br /&gt;
* When an assignment finishes (that is when the deadline has passed), holistic scores will be calculated in LocalDBCalc and then inserted in this new db table &amp;quot;local_db_score&amp;quot;&lt;br /&gt;
** This will be done using scheduled tasks feature&lt;br /&gt;
** If the record is a finalized peer-review score, the type stored in the database will be &amp;quot;ReviewLocalDBScore&amp;quot; and the reference_id will be the response_map id&lt;br /&gt;
** The peer-review scores will be calculated for all the review rounds because it is possible that user A only review user B in one out of several rounds&lt;br /&gt;
* When a request is made to view scores, depending on whether the assignment is ongoing or finished, either OnTheFlyCalc or LocalDBCalc will be called to calculate the score or query the score from the &amp;quot;local_db_scores&amp;quot; table&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107960</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107960"/>
		<updated>2017-04-06T23:07:48Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work only for peer-review scores.  As future projects will introduce other types of scores, the solution must be extensible.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107959</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107959"/>
		<updated>2017-04-06T23:04:19Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Current Scenario */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Today, Expertiza stores the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work for peer-review scores only, by making sure the code is extensible for further work.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107958</id>
		<title>CSC/ECE 517 Spring 2017/E1731 Improve Score Calculation</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017/E1731_Improve_Score_Calculation&amp;diff=107958"/>
		<updated>2017-04-06T22:59:35Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;nowiki&amp;gt;  Expertiza is an opensource web based platform developed to assist students in educational institutions to perform peer reviews and group projects. The reviewing is done through a mechanism where students will be sent request to review work and the system will analyze and publish a summarized report. The software is designed in MVC (Model-View-Controller) architecture using Ruby on Rails.&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Problem Description==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Expertiza store the scores based on each response to each criterion, but no holistic scores are stored. The answers table only contains the score that A gives B on each criterion. This means that if we need to know what score user A gives to user B based on 100, we have to rely on the code to calculate it every time the scores are requested. This design slows down Expertiza as every time instructor clicks on &amp;quot;View Scores&amp;quot;, all the calculations are done to display the score. The situation is even worse if we want to weight the scores by the reputation of each reviewer, which is a measure of how closely that reviewer's scores match other reviewers. The system potentially has to do thousands of arithmetic calculations to display the score for a particular assignment.&lt;br /&gt;
&lt;br /&gt;
===Proposed Solution===&lt;br /&gt;
We propose that we have two mechanism to handle holistic scores, depending on the current state of the assignment:&lt;br /&gt;
* OnTheFlyCalc: Calculates holistic scores over a set of data: A set of records in answers table, namely the responses from user A to user B on each criterion.&lt;br /&gt;
** When an assignment is still ongoing, the reputations for each reviewer will be calculated and handled by OnTheFlyCalc.&lt;br /&gt;
* LocalDBCalc: Calculates the holistic score over a single db query: &amp;quot;get the score that user A gives user B on assignment 999 on round 2&amp;quot;&lt;br /&gt;
** When an asignment has finished, all the reputations will be calculated by LocalDBCalc and stored, since they are finalized. So, when the scores are requested, it is fetched using a single db query and displayed.  &lt;br /&gt;
&lt;br /&gt;
In this project, our goal is to make the OnTheFlyCalc and LocalDBCalc work for peer-review scores only, by making sure the code is extensible for further work.&lt;br /&gt;
&lt;br /&gt;
==Design Plan==&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107690</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107690"/>
		<updated>2017-03-31T22:50:54Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Extra Credit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:E1711.Slide1.jpg|frame|center]]  &lt;br /&gt;
[[File:Slide2.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy_params&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy_params)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107689</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107689"/>
		<updated>2017-03-31T22:50:30Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:E1711.Slide1.jpg|frame|center]]  &lt;br /&gt;
[[File:Slide2.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Unit&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Unit&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107622</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107622"/>
		<updated>2017-03-30T23:45:52Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:E1711.Slide1.jpg|frame|center]]  &lt;br /&gt;
[[File:Slide2.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107621</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107621"/>
		<updated>2017-03-30T23:42:22Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:E1711.Slide1.jpg|frame|center]]  &lt;br /&gt;
[[File:E1711.Slide2.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107620</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107620"/>
		<updated>2017-03-30T23:41:56Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:E1711.Slide1.jpg|frame|center]]  &lt;br /&gt;
[[File:E1711.Slide2r.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Slide2.jpg&amp;diff=107619</id>
		<title>File:Slide2.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Slide2.jpg&amp;diff=107619"/>
		<updated>2017-03-30T23:38:29Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E1711.Slide1.jpg&amp;diff=107618</id>
		<title>File:E1711.Slide1.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E1711.Slide1.jpg&amp;diff=107618"/>
		<updated>2017-03-30T23:37:30Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107617</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107617"/>
		<updated>2017-03-30T23:32:46Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107616</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107616"/>
		<updated>2017-03-30T23:25:42Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following flowchart shows how to arrive at the tested scenarios.  The charts refer to Scenarios by number.  Below Summary table delves into details of the test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107612</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107612"/>
		<updated>2017-03-30T22:47:33Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Extra Credit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To fix this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107611</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107611"/>
		<updated>2017-03-30T22:46:20Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type submission deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type review deadline .  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type metareview deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type drop topic deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created with deadline type sign up deadline.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created. with deadline type team formation deadline  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107582</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107582"/>
		<updated>2017-03-30T01:19:36Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107581</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107581"/>
		<updated>2017-03-30T01:18:11Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Refactor the perform mehtod */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Fucntional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We made the existing tests more complete by adding in sections that properly created the data objects.  We also added verification that once the job is executed, the deadline type for the job is what we expected.  We also added verification to make sure that the number of jobs were changing and the mail delivery counts were increasing as expected.  &lt;br /&gt;
&lt;br /&gt;
The six existing tests that we modified were scenarios 1 to 6 listed above.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We modified existing test cases for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method to be more thorough.  We continuously would run these tests during development to make sure they continue to pass.&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107580</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107580"/>
		<updated>2017-03-30T01:11:02Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Number&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Fucntional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107579</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107579"/>
		<updated>2017-03-30T01:09:06Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.  The selection of the added tests were to verify the functions that were restructured as a part of this effort.  Functions that were not touched are out of the scope of this assignment so no tests were added there.  Adding tests for other functions can be a future assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Fucntional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are no sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with no sign up topics.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; works when there are sign up topics.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a single sign up topic.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that there was a call to &amp;lt;code&amp;gt;find_signed_up_team_members_email_for_all_topics&amp;lt;/code&amp;gt;, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|-&lt;br /&gt;
| Verify &amp;lt;code&amp;gt;find_signed_up_team_members_email&amp;lt;/code&amp;gt; works.&lt;br /&gt;
| Functional&lt;br /&gt;
| New data is inserted into the DB such that there is a single team member on a single assignment with a no sign up topic whose email address is expertiza@malinator.com.  Then a new &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; object is created.  The method is then called and we verify that the found email address is the expertiza@mailinator.com, as expected.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107578</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107578"/>
		<updated>2017-03-30T00:47:52Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107577</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107577"/>
		<updated>2017-03-30T00:47:06Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.  Also note that for each of the groups getting emails, the test cases only deliver one email.  That is because the DB has a minimum amount of test data where each group to send the emails to only has one member and one email address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadline reminders to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email review deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email drop topic deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
-&lt;br /&gt;
| Email sign up deadline reminders to all assignment participants &lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email team formation deadline reminders to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is team formation deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107576</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107576"/>
		<updated>2017-03-30T00:35:51Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
Also you will note at the start of the tests, a lot of information is created in the DB.  All these things need to be in the DB in order to verify that the mailer is successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadlines to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is submission deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email review deadlines to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is review deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email metareview deadlines to metareviews and team members of the assignment&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is metareview deadline.  Verify the count of mail deliveries increase by 2.  The increase is by 2 instead of 1 like the other tests since both a metareviewer and a team member were emailed.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email drop topic deadlines to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.  Verify that the deadline type of the job is drop topic deadline.  Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified|&lt;br /&gt;
-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107575</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107575"/>
		<updated>2017-03-30T00:26:04Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadlines to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches.\n Verify that the submission type of the job is submission deadline.\n Verify the count of mail deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email review deadlines to reviewers&lt;br /&gt;
| Functional&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107574</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107574"/>
		<updated>2017-03-30T00:22:46Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadlines to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches and the mailer deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107573</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107573"/>
		<updated>2017-03-30T00:21:59Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the test cases for ''delayed_mailer.rb''&lt;br /&gt;
Much of our work consisted of modifying the existing tests so they were more thorough and adding some tests.&lt;br /&gt;
&lt;br /&gt;
You can find the test cases in ''delayed_mailer_spec.rb''&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
! Test Tool&lt;br /&gt;
! Test Added/Modified&lt;br /&gt;
|-&lt;br /&gt;
| Email submission deadlines to signed up users&lt;br /&gt;
| Functional&lt;br /&gt;
| A new delayed mailing task is created.  The number of delayed jobs pending is increased by 1.  One second later, the job launches and the mailer deliveries increase by 1.&lt;br /&gt;
| Rspec&lt;br /&gt;
| Modified&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107572</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107572"/>
		<updated>2017-03-30T00:00:56Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Future Refactoring Opportunities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the &amp;lt;b&amp;gt;new&amp;lt;/b&amp;gt; test cases as a result of the refactoring effort.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
|-&lt;br /&gt;
| row 1, cell 1&lt;br /&gt;
| row 1, cell 2&lt;br /&gt;
| row 1, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
5. We found out that all assignments in Expertiza are team assignments and querying if the assignment is a team assignment is hardcoded to return true.  &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; does have some business logic  where the recipient of the email depends on whether or not the assignment is a team assignment.  This business logic needs to be revisited by the Expertiza team before the method can be further simplified to ensure the correct mail goes out in the correct scenario.  We kept the logic the same as it was out of our scope to change business logic.&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107571</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107571"/>
		<updated>2017-03-29T23:45:10Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead the below table summarizes the &amp;lt;b&amp;gt;new&amp;lt;/b&amp;gt; test cases as a result of the refactoring effort.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario Description&lt;br /&gt;
! Test Type&lt;br /&gt;
! Test Description&lt;br /&gt;
|-&lt;br /&gt;
| row 1, cell 1&lt;br /&gt;
| row 1, cell 2&lt;br /&gt;
| row 1, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107570</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107570"/>
		<updated>2017-03-29T23:42:05Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead below is a table summarizing the &amp;lt;b&amp;gt;new&amp;lt;/b&amp;gt; test cases as a result of the refactoring effort.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Header 1&lt;br /&gt;
! Header 2&lt;br /&gt;
! Header 3&lt;br /&gt;
|-&lt;br /&gt;
| row 1, cell 1&lt;br /&gt;
| row 1, cell 2&lt;br /&gt;
| row 1, cell 3&lt;br /&gt;
|-&lt;br /&gt;
| row 2, cell 1&lt;br /&gt;
| row 2, cell 2&lt;br /&gt;
| row 2, cell 3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107569</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107569"/>
		<updated>2017-03-29T23:39:58Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
Note that the recommended format for a test plan included creating a flowchart.  However, our assignment  cannot be easily explained by a flow chart. First, none of the changes impact user behavior (refactoring only).  Second, the changes were in an area of the code that was not impacted by user behavior, so there are no decision points that can be made into a flowchart.&lt;br /&gt;
&lt;br /&gt;
Instead below is a table summarizing the &amp;lt;b&amp;gt;new&amp;lt;/b&amp;gt; test cases as a result of the refactoring effort.&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107568</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107568"/>
		<updated>2017-03-29T23:32:09Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
&lt;br /&gt;
During our testing, we found that the &amp;quot;create new late policy&amp;quot; function was broken.  It was throwing a ActiveModel::ForbiddenAttributesError on LatePoliciesController#create, as seen below:&lt;br /&gt;
&lt;br /&gt;
[[File:Late_Policy_Ruby_Error.jpg|frame|center]]  &lt;br /&gt;
&lt;br /&gt;
To find this, we had to add the following code to the private section of late_policies_controller.rb:&lt;br /&gt;
&lt;br /&gt;
    def late_policy&lt;br /&gt;
    params.require(:late_policy).permit(:policy_name, :penalty_per_unit, :penalty_unit, :max_penalty)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
and change the argument in the LatePolicy.new() to just &lt;br /&gt;
&lt;br /&gt;
    @late_policy = LatePolicy.new(late_policy)&lt;br /&gt;
&lt;br /&gt;
After these two small changes, we were able to create new late policies from the UI.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107200</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107200"/>
		<updated>2017-03-23T02:37:24Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Future Refactoring Opportunities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107199</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107199"/>
		<updated>2017-03-23T02:37:04Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;br /&gt;
&lt;br /&gt;
1. Scheduled Task feature does not belong in the mailers.  It needs to be a standalone file with new tests added.&lt;br /&gt;
2. There are still methods that look like they should be collapsed into one function and opportunities for DRYing out code once other tightly coupled methods are also refactored.&lt;br /&gt;
3. There were practically no tests for this area of the code.  We added tests for what we modified but much code still remains that is not being tested.&lt;br /&gt;
4. There are many calls to the database for the same information in different methods.  These repeated calls could probably be reduced to one call and save the result from the database.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107198</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107198"/>
		<updated>2017-03-23T02:32:23Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Quantitative Results from Refactoring Effort */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107196</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107196"/>
		<updated>2017-03-23T02:27:17Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Quantitative Results from Refactoring Effort */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
The following are some highlighted statistics showing our refactoring efforts &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that the new statistics are incorporating code that used to be in the scheduled tasks file.&lt;br /&gt;
&lt;br /&gt;
Also note that we did not try to fix issues in areas of the code that were outside the scope of the assignment.  We recommend such changes are taken up in future assignments.&lt;br /&gt;
&lt;br /&gt;
Finally, our selection of statistics for this project was to focus on reducing complexity since code needs to be easily understandable in order to be effectively maintained.&lt;br /&gt;
&lt;br /&gt;
'''Total Rubocop detected offenses:''' &lt;br /&gt;
&lt;br /&gt;
Old = 63&lt;br /&gt;
New = &lt;br /&gt;
&lt;br /&gt;
'''Statistics on &amp;lt;code&amp;gt;perform &amp;lt;/code&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
&lt;br /&gt;
Assignment Branch Condition size for perform is too high. [41.11/15]&lt;br /&gt;
&lt;br /&gt;
Cyclomatic complexity for perform is too high. [13/6]&lt;br /&gt;
&lt;br /&gt;
Perceived complexity for perform is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
'''Statistics on &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
Assignment Branch Condition size for mail_signed_up_users is too high. [33.02/15]&lt;br /&gt;
&lt;br /&gt;
Cyclomatic complexity for mail_signed_up_users is too high. [10/6]&lt;br /&gt;
&lt;br /&gt;
Perceived complexity for mail_signed_up_users is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107195</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107195"/>
		<updated>2017-03-23T02:26:34Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Quantitative Results from Refactoring Effort */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
The following are some highlighted statistics showing our refactoring efforts &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that the new statistics are incorporating code that used to be in the scheduled tasks file.&lt;br /&gt;
&lt;br /&gt;
Also note that we did not try to fix issues in areas of the code that were outside the scope of the assignment.  We recommend such changes are taken up in future assignments.&lt;br /&gt;
&lt;br /&gt;
Finally, our selection of statistics for this project was to focus on reducing complexity since code needs to be easily understandable in order to be effectively maintained.&lt;br /&gt;
&lt;br /&gt;
Total Rubocop detected offenses: &lt;br /&gt;
&lt;br /&gt;
Old = 63&lt;br /&gt;
New = &lt;br /&gt;
&lt;br /&gt;
Statistics on &amp;lt;code&amp;gt;perform &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
&lt;br /&gt;
Assignment Branch Condition size for perform is too high. [41.11/15]&lt;br /&gt;
&lt;br /&gt;
Cyclomatic complexity for perform is too high. [13/6]&lt;br /&gt;
&lt;br /&gt;
Perceived complexity for perform is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
Statistics on &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
Assignment Branch Condition size for mail_signed_up_users is too high. [33.02/15]&lt;br /&gt;
&lt;br /&gt;
Cyclomatic complexity for mail_signed_up_users is too high. [10/6]&lt;br /&gt;
&lt;br /&gt;
Perceived complexity for mail_signed_up_users is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107194</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107194"/>
		<updated>2017-03-23T02:25:54Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Quantitative Results from Refactoring Effort */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
The following are some highlighted statistics showing our refactoring efforts &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that the new statistics are incorporating code that used to be in the scheduled tasks file.&lt;br /&gt;
&lt;br /&gt;
Also note that we did not try to fix issues in areas of the code that were outside the scope of the assignment.  We recommend such changes are taken up in future assignments.&lt;br /&gt;
&lt;br /&gt;
Finally, our selection of statistics for this project was to focus on reducing complexity since code needs to be easily understandable in order to be effectively maintained.&lt;br /&gt;
&lt;br /&gt;
Total Rubocop detected offenses: &lt;br /&gt;
&lt;br /&gt;
Old = 63&lt;br /&gt;
New = &lt;br /&gt;
&lt;br /&gt;
Statistics on &amp;lt;code&amp;gt;perform &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
Assignment Branch Condition size for perform is too high. [41.11/15]&lt;br /&gt;
Cyclomatic complexity for perform is too high. [13/6]&lt;br /&gt;
Perceived complexity for perform is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
Statistics on &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old=&lt;br /&gt;
Assignment Branch Condition size for mail_signed_up_users is too high. [33.02/15]&lt;br /&gt;
Cyclomatic complexity for mail_signed_up_users is too high. [10/6]&lt;br /&gt;
Perceived complexity for mail_signed_up_users is too high. [13/7]&lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107193</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107193"/>
		<updated>2017-03-23T02:14:18Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We replaced the existing single method &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; with a shorter version and a new method &amp;lt;code&amp;gt;find_team_members_email_for_all_topics&amp;lt;/code&amp;gt;.  We also heavily modified (including renaming) the existing method &amp;lt;code&amp;gt;getTeamMembersMail&amp;lt;/code&amp;gt;, and it is now called &amp;lt;code&amp;gt;find_team_members_email&amp;lt;/code&amp;gt;.  As the naming of the methods suggest, there are still opportunities for DRYing the two functions to get team member emails, but exiting code makes it extremely difficult to combine the two functions exactly though they are extremely similar at first glance.  Merging the two would require refactoring areas outside the scope of this assignment and a whole new set of test cases to verify a lot of basic functionality is not broken in the process.  We recommend this is taken up as a part of a future assignment.  See &amp;lt;/b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We added test cases for each of the methods we changed.  There are now 10 test cases that are covering this file.  The four new test cases focus on verifying that the functions can access the database to protect against schema changes and making sure the right methods are called.  Tests were not added for code that was not within the scope of this assignment but we recommend the remainder of the functions also get similar test cases.  See details in  &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
Some highlights from analysis of the original &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; file compared with after our changes are: &lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107191</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107191"/>
		<updated>2017-03-23T01:52:22Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: /* Refactor mail_signed_up_users */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; method=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The primary objective of this task was that the method is long and could be broken into smaller appropriately named methods.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  None of the six existing tests verified if the emails are being retrieved from the database so changes in the database schema would break the feature.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We broke the existing &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; into three functions&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
Some highlights from analysis of the original &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; file compared with after our changes are: &lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107177</id>
		<title>CSC/ECE 517 Spring 2017 E1711</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2017_E1711&amp;diff=107177"/>
		<updated>2017-03-23T01:37:03Z</updated>

		<summary type="html">&lt;p&gt;Ppraman2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt; E1711. Refactor delayed_mailer.rb and scheduled_task.rb&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based tool that allows instructors to create collaborative assignments where students can provide peer feedback on each others work.  It provides instructors a system to manage assignments and different courses.&lt;br /&gt;
&lt;br /&gt;
==Scope of project E1711==&lt;br /&gt;
&lt;br /&gt;
The goal of E1711 was to refactor code found in the files &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
The following issues were identified as the scope of this project:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::* &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; duplicated most of its code from &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Our objective is to reduce/remove the duplication in keeping with the DRY principle.&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method uses a giant case statement, instead we were to incorporate the use of polymorphism&lt;br /&gt;
:::* The &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt; is long and should be broken into smaller and better named methods&lt;br /&gt;
:::* Add/modify test cases as we added/removed/modified areas of the code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the assignment can be found on [https://docs.google.com/document/d/17f8WVW7i-S5i0HEc__33lDQYRu9RxD7HQndSumQ_-JA/edit#heading=h.kq28lsw1uwf4 this document]&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
As this was a purely refactoring effort, our testing consisted of confirming existing tests did not break, modifying existing tests to match our changes, or adding tests as needed.  The below sections will cover each objective in detail and will include information on how testing was done for each of those changes.  See each of the &amp;lt;b&amp;gt;Our Testing&amp;lt;/b&amp;gt; sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Remove duplicated code between ''delayed_mailer.rb'' and ''scheduled_task.rb''=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The main objective of this task was to reduce duplicated code as recommended by DRY principle.&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called [https://rubygems.org/gems/delayed_job/versions/4.1.2 delayed_job].   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; mehtod=&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
The objective of this task was to clean up this method.  It was identified as being badly named, long, and not taking advantage of good design.  It is essentially a giant case statement where  one of the variables passed into the &amp;lt;code&amp;gt;DelayedMailer&amp;lt;/code&amp;gt; constructor determines the people who receives the email..  Some suggested ways to refactor this function was first rename the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; to better describe what it does and to use polymorphism in place of the case statement.  The original thought was that polymorphism could be used to determine what was sent out in each email based on the type of the email.&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
The first item we looked at was to rename the method.  A generic name such as &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; usually means that the method is doing too much or does not have a clear objective.  Unfortunately, we found we could not rename the method because the delayed_job gem requires a method named &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; in order to work on a custom job.  See documentation [http://www.rubydoc.info/gems/delayed_job/4.1.2 here]&lt;br /&gt;
&lt;br /&gt;
The second part of the planned refactoring was to use polymorphism to determine the content of the email.  After simplifying much of the code in the file, we discovered that the content of the email was independent of the variables used to initialize the object.  At that point, we weighed the complexity of new code to use polymorphism versus a significantly more simplified case statement, and because of the lack of existing tests, decided that the simplified case statement was not only short, it is also very simple to follow the flow through the code.  We instead focused on DRYing out this code as a better return on immediate investment as opposed to adding polymorphism.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
There were six existing Rspec tests for &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;, but the existing tests only verify that a new delayed job was added to the queue based on the type of deadline specified when creating a new &amp;lt;code&amp;gt;DelayedMalier&amp;lt;/code&amp;gt;.  We deemed the existing testing as adequate for this section of the file as the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method calls other methods to find the email addresses and send the email.&lt;br /&gt;
&lt;br /&gt;
===Our Testing===&lt;br /&gt;
&lt;br /&gt;
We did not change existing testing for the &amp;lt;code&amp;gt;perform&amp;lt;/code&amp;gt; method as the existing testing verified that a job to send out emails was added to the queue.  We did, however, verify that our code changes did not break this portion of the code by continuously running the existing test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Refactor &amp;lt;code&amp;gt;mail_signed_up_users&amp;lt;/code&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Background of Objective===&lt;br /&gt;
&lt;br /&gt;
After a deep investigation into understanding why the same code would appear in two separate files, we concluded that the authors of &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; found that &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; already integrated with a Ruby gem called &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt;.   &amp;lt;i&amp;gt;delayed_job&amp;lt;/i&amp;gt; is used to run tasks asynchronously in the background.  It was used in &amp;lt;i&amp;gt;delayed_mailer&amp;lt;/i&amp;gt; to add an outgoing email to a queue to send out in the future.  Instead of recreating similar infrastructure, the authors copied over the file to a different location, added on the new desired functionality, and renamed it.  The authors also pointed all existing code to use &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; instead of &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Our Changes===&lt;br /&gt;
&lt;br /&gt;
We found that the vast majority of the code in both the files applied to sending emails so we decided to merge the &amp;lt;i&amp;gt;scheduled_task.rb&amp;lt;/i&amp;gt; into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; by porting the enhancements made for the scheduled tasks into &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt;.  Doing so allowed us to meet the objective of DRYing out the code.  However, we still have a situation where scheduled tasks feature has code in a section devoted to mailer code.  We recommend that a future project take up the needed changes to pull out the scheduled task code out of the mailer file and make it a standalone feature as it should have been originally.  See details in the &amp;lt;b&amp;gt;Future Refactoring Opportunities&amp;lt;/b&amp;gt; below.&lt;br /&gt;
&lt;br /&gt;
===Existing Tests===&lt;br /&gt;
&lt;br /&gt;
We did not find any existing automated testing targeting this area of the code.  All existing tests in the &amp;lt;code&amp;gt;spec&amp;lt;/code&amp;gt; file associated with this feature were copies of the tests in the delayed mailer feature and did not exercise any of the new code that was introduced with adding the new types of scheduled tasks.&lt;br /&gt;
&lt;br /&gt;
=== Our Testing===&lt;br /&gt;
&lt;br /&gt;
We went back to the demonstration of this feature and manually tested all the same scenarios.  We verified that no functionality presented in the scheduled tasks demonstration was broken.  Tests were added for the delayed mailer feature (covered in more details in the following sections).  We recommend tests focused towards scheduled tasks are added once the scheduled tasks code is removed from the delayed mailer file back into an independent file.&lt;br /&gt;
&lt;br /&gt;
=Quantitative Results from Refactoring Effort=&lt;br /&gt;
&lt;br /&gt;
We used [https://docs.codeclimate.com/v1.0/docs/rubocop Rubocop] to show the improvements in that resulted from this effort.&lt;br /&gt;
&lt;br /&gt;
Some highlights from analysis of the original &amp;lt;i&amp;gt;delayed_mailer.rb&amp;lt;/i&amp;gt; file compared with after our changes are: &lt;br /&gt;
&lt;br /&gt;
=Future Refactoring Opportunities=&lt;br /&gt;
&lt;br /&gt;
Once we started to refactor the code, we found many additional opportunities to refactor the files that was beyond the planned scope.  We note down some of the opportunities here and leave it to future projects to address.&lt;/div&gt;</summary>
		<author><name>Ppraman2</name></author>
	</entry>
</feed>