<?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=Hkumbum</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=Hkumbum"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Hkumbum"/>
	<updated>2026-10-10T05:10:48Z</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_2016_E1631_Team-based_reviewing&amp;diff=102264</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102264"/>
		<updated>2016-04-12T03:24:32Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Test Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
Below are the key files to be modified:&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* '''review_mapping_controller.rb:''' Method's like get_reviewer that consist of user_id will consist of calls to generic method which assigns a team_id or user_id based on the assignment being reviewed.&lt;br /&gt;
* '''response_controller:''' Initial check if it's a team based or an individual review to assign the corresponding id.&lt;br /&gt;
&lt;br /&gt;
====Handling Concurrency====&lt;br /&gt;
&lt;br /&gt;
There can exist a concurrency problem with the team review system. If two members from the team start with the review at the same time, the member who started the review first will lose his/her changes as the second members changes will be overwritten.&lt;br /&gt;
&lt;br /&gt;
To solve this problem, we plan to use a boolean field 'lock' for locking mechanism. &lt;br /&gt;
If any member from the team starts with the review, we will set the lock field to true. Once the response is locked, no other member is allowed to edit the response. This lock will be released after the response has been saved.&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL). All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We intend to write unit tests using RSpec for all the methods which we modified/created.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Test Cases===&lt;br /&gt;
1. If the instructor selects &amp;quot;Review by team&amp;quot;, check if the review is done by a team member, not by participant.&lt;br /&gt;
&lt;br /&gt;
2. If one teammate is working on a review, another teammate should not be able to edit it at the same time.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102263</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102263"/>
		<updated>2016-04-12T03:24:23Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Running RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
Below are the key files to be modified:&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* '''review_mapping_controller.rb:''' Method's like get_reviewer that consist of user_id will consist of calls to generic method which assigns a team_id or user_id based on the assignment being reviewed.&lt;br /&gt;
* '''response_controller:''' Initial check if it's a team based or an individual review to assign the corresponding id.&lt;br /&gt;
&lt;br /&gt;
====Handling Concurrency====&lt;br /&gt;
&lt;br /&gt;
There can exist a concurrency problem with the team review system. If two members from the team start with the review at the same time, the member who started the review first will lose his/her changes as the second members changes will be overwritten.&lt;br /&gt;
&lt;br /&gt;
To solve this problem, we plan to use a boolean field 'lock' for locking mechanism. &lt;br /&gt;
If any member from the team starts with the review, we will set the lock field to true. Once the response is locked, no other member is allowed to edit the response. This lock will be released after the response has been saved.&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL). All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We intend to write unit tests using RSpec for all the methods which we modified/created.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Test Cases===&lt;br /&gt;
1. If the instructor selects &amp;quot;Review by team&amp;quot;, check if the review is done by a team member, not by participant.&lt;br /&gt;
2. If one teammate is working on a review, another teammate should not be able to edit it at the same time.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102223</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102223"/>
		<updated>2016-04-12T02:40:06Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
Below are the key files to be modified:&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL). All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102221</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102221"/>
		<updated>2016-04-12T02:39:41Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Key files to be modified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
Below are the key files to be modified&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL). All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102203</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102203"/>
		<updated>2016-04-12T02:18:08Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL). All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102197</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102197"/>
		<updated>2016-04-12T02:11:54Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
RSpec is used to write test cases using TTD approach. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is used for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102196</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102196"/>
		<updated>2016-04-12T02:10:08Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''assignments/edit/_review_report.html.erb:''' Add a dropdown for the instructors to select if the reviews are individual or team-based.&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
RSpec is used to write test cases using TTD approach. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102194</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102194"/>
		<updated>2016-04-12T02:06:13Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Design Pattern ====&lt;br /&gt;
'''Model View Controller'''&lt;br /&gt;
&lt;br /&gt;
In an MVC model, a software application is divided into three major components: Model, View and Controller. &lt;br /&gt;
&lt;br /&gt;
'''Model''' - Keeps data, logic and relations between objects and the database. It also handles validations, associations and transactions.&lt;br /&gt;
&lt;br /&gt;
'''View''' - Displays the data received from the controller in the user interface.&lt;br /&gt;
&lt;br /&gt;
'''Controller''' - Accepts the client's input and converts it into action points for the model or view. Other responsibilities include querying models and organizing data in a structure that is displayed by the view.&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''review_mapping/_review_report.html.erb:'''&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102188</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=102188"/>
		<updated>2016-04-12T01:49:45Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Controllers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
When a participant of a team reviewed an assignment, his/her review is independent of his teammate’s reviews. To allow teammates to discuss and review together, allowing teams to submit reviews for the team as a whole should be allowed ideally. We intend to do this in our project. &lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Objects of ResponseMap record the information of who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review. We added a boolean field &amp;quot;reviewer_is_team&amp;quot; to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, we will be providing a dropdown on the Review Strategy tab of assignment creation.&lt;br /&gt;
# Ensure that features such as &amp;quot;view my scores&amp;quot;, or the &amp;quot;alternate view/heat map&amp;quot; should continue working.&lt;br /&gt;
# Concurrency control: Shouldn't allow multiple teammates to edit the team's review at the same time. The scope of the project doesn't include concurrent editing to allow multiple teammates to edit a review simultaneously.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* '''review_response_map.rb:''' Add a field reviewer_is_team , which determines if the reviewer is doing an individual review or on behalf of the team. &lt;br /&gt;
* '''assignment.rb:''' Add a field review_type , that indicates if the assignment is a team based or an individual assignment decided by the instructor.&lt;br /&gt;
&lt;br /&gt;
====Views====&lt;br /&gt;
* '''review_mapping/_review_report.html.erb:'''&lt;br /&gt;
&lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating Assignment and Team objects to be used for testing. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=101693</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=101693"/>
		<updated>2016-04-03T00:15:48Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Add fields to the ResponseMap model to record who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review.&lt;br /&gt;
# Add a boolean field reviewer_is_team to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table. Else, it will be a reference to the Participants table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, provide a checkbox on the Review Strategy tab of assignment creation.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviewer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* review_response_map.rb&lt;br /&gt;
* participant.rb &lt;br /&gt;
* response_map.rb &lt;br /&gt;
* response.rb &lt;br /&gt;
* assignment_team.rb&lt;br /&gt;
* assignment_participant.rb &lt;br /&gt;
* assignment.rb&lt;br /&gt;
====Views====&lt;br /&gt;
* review_mapping/_review_report.html.erb &lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=101692</id>
		<title>CSC/ECE 517 Spring 2016 E1631 Team-based reviewing</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1631_Team-based_reviewing&amp;diff=101692"/>
		<updated>2016-04-03T00:02:22Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
*Currently all reviews in Expertiza are done by individuals. This is true regardless of whether the assignment is done by individuals or teams . &lt;br /&gt;
*There are occasions when it's advantageous to review projects as a team . &lt;br /&gt;
*It helps foster discussion and thereby improves the process of learning.&lt;br /&gt;
&lt;br /&gt;
== Task Description ==&lt;br /&gt;
This project comprises of the following steps :&lt;br /&gt;
&lt;br /&gt;
# Add fields to the ResponseMap model to record who reviews whom. The field reviewee_id refers to the team who is being reviewed. The field reviewer_id refers to the individual/team performing the review.&lt;br /&gt;
# Add a boolean field reviewer_is_team to identify if the review is performed by a team or an individual.&lt;br /&gt;
# If reviewer_is_team is true, the reviewer_id will be a reference to the Teams table. Else, it will be a reference to the Participants table.&lt;br /&gt;
# For an Instructor to specify whether the review is a Team/Individual based review, provide a checkbox on the Review Strategy tab of assignment creation.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
==== Use Case Diagram ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Specify review type on Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructor. &lt;br /&gt;
&lt;br /&gt;
'''Description:''' The instructor specifies whether this review is an individual review or a team based review on the Review Strategy tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Perform Review.&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Individual Student/Team.&lt;br /&gt;
&lt;br /&gt;
'''Description:''' The individual/team will perform a review for the Assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:OODDUseCase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Database Design ===&lt;br /&gt;
&lt;br /&gt;
ResponseMap in essence, records who reviews whom. Schema of ResponseMap:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Data type&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewed_object_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| reviewee_id&lt;br /&gt;
| int(11)&lt;br /&gt;
|-&lt;br /&gt;
| type&lt;br /&gt;
| varchar(255)&lt;br /&gt;
|-&lt;br /&gt;
| created_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| updated_at&lt;br /&gt;
| datetime&lt;br /&gt;
|-&lt;br /&gt;
| caliberate_to&lt;br /&gt;
| boolean&lt;br /&gt;
|-&lt;br /&gt;
| reviewer_is_team &lt;br /&gt;
| boolean&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The description of the fields of the database for ResponseMap:&lt;br /&gt;
&lt;br /&gt;
1. '''id:''' The unique record identifier.&lt;br /&gt;
&lt;br /&gt;
2. '''reviewed_object_id:''' The id of the object that is reviewed. Assignments or ReviewMaps could be reviewed.&lt;br /&gt;
&lt;br /&gt;
3. '''reviewer_id:''' The reviewer can either be an “AssignmentTeam” or “AssignmentParticipant”, which is indicated by the field reviwer_is_team.&lt;br /&gt;
&lt;br /&gt;
4. '''reviewee_id:''' The id “AssignmentTeam” who is getting the “Response” i.e., the one whose work is being reviewed. &lt;br /&gt;
&lt;br /&gt;
5. '''type :'''  Indicates the type of the ResponseMap.&lt;br /&gt;
&lt;br /&gt;
6. '''created_at:''' The timestamp when the Response was created.&lt;br /&gt;
&lt;br /&gt;
7. '''updated_at:''' The timestamp when the Response was updated.&lt;br /&gt;
&lt;br /&gt;
8. '''calibrate_to:''' A field of boolean data type.&lt;br /&gt;
&lt;br /&gt;
9. '''reviwer_is_team:''' If this field is ‘true’, the reviewer_id refers to the id of the “AssignmentTeam” to which the participant belongs. Else, it refers to the id of the “Participant” itself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Key files to be modified===&lt;br /&gt;
&lt;br /&gt;
====Models====&lt;br /&gt;
* review_response_map.rb&lt;br /&gt;
* participant.rb &lt;br /&gt;
* response_map.rb &lt;br /&gt;
* response.rb &lt;br /&gt;
* assignment_team.rb&lt;br /&gt;
* assignment_participant.rb &lt;br /&gt;
* assignment.rb&lt;br /&gt;
====Views====&lt;br /&gt;
* review_mapping/_review_report.html.erb &lt;br /&gt;
====Controllers====&lt;br /&gt;
* review_mapping_controller.rb&lt;br /&gt;
* participants_controller.rb&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101660</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101660"/>
		<updated>2016-04-02T03:55:56Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Building Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating test Assignment and Team objects. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factory===&lt;br /&gt;
Below is the code to create object of team class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 FactoryGirl.define do&lt;br /&gt;
  factory :team do&lt;br /&gt;
    name &amp;quot;Wikipedia contribution_Team2&amp;quot;&lt;br /&gt;
    parent_id 999&lt;br /&gt;
    #parent_id 741&lt;br /&gt;
    type &amp;quot;AssignmentTeam&amp;quot;&lt;br /&gt;
    submitted_hyperlinks &amp;quot;---\n- http://water.com\n- http://shed.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example RSpec===&lt;br /&gt;
We have written unit tests for each of the methods we have re-factored in this project. Here's a unit test example contained in spec/model/assignment_team_spec.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#has_submissions?&amp;quot; do&lt;br /&gt;
    it &amp;quot;checks if a team has submitted hyperlinks&amp;quot; do&lt;br /&gt;
      # assignment = build(:assignment)&lt;br /&gt;
      assign_team = build(:assignment_team)&lt;br /&gt;
      assign_team.submitted_hyperlinks &amp;lt;&amp;lt; &amp;quot;\n- https://www.harrypotter.ncsu.edu&amp;quot;&lt;br /&gt;
      expect(assign_team.has_submissions?).to be true&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101659</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101659"/>
		<updated>2016-04-02T03:51:59Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Building Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating test Assignment and Team objects. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factory===&lt;br /&gt;
Below is the code to create object of team class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 FactoryGirl.define do&lt;br /&gt;
  factory :team do&lt;br /&gt;
    name &amp;quot;Wikipedia contribution_Team2&amp;quot;&lt;br /&gt;
    parent_id 999&lt;br /&gt;
    #parent_id 741&lt;br /&gt;
    type &amp;quot;AssignmentTeam&amp;quot;&lt;br /&gt;
    submitted_hyperlinks &amp;quot;---\n- http://water.com\n- http://shed.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101658</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101658"/>
		<updated>2016-04-02T03:51:21Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
RSpec is a testing framework for Rails, and is a Behavioral-Driven Development tool. It is a domain specific language(DSL).  &lt;br /&gt;
&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
We have used Factory Girl for creating test Assignment and Team objects. Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factory===&lt;br /&gt;
Below is the code to create object of team class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 FactoryGirl.define do&lt;br /&gt;
  factory :team do&lt;br /&gt;
    name &amp;quot;Wikipedia contribution_Team2&amp;quot;&lt;br /&gt;
    parent_id 999&lt;br /&gt;
    #parent_id 741&lt;br /&gt;
    type &amp;quot;AssignmentTeam&amp;quot;&lt;br /&gt;
    submitted_hyperlinks &amp;quot;---\n- http://water.com\n- http://shed.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;q&lt;br /&gt;
&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101620</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101620"/>
		<updated>2016-04-02T00:37:45Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist|20em}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101619</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101619"/>
		<updated>2016-04-02T00:36:48Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101618</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101618"/>
		<updated>2016-04-02T00:36:38Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101617</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101617"/>
		<updated>2016-04-02T00:34:45Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Running RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  $ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101616</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101616"/>
		<updated>2016-04-02T00:33:57Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Running RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&lt;br /&gt;
$ rspec spec/models/assignment_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101615</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101615"/>
		<updated>2016-04-02T00:30:45Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  gem 'rspec-rails'&lt;br /&gt;
  gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101614</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101614"/>
		<updated>2016-04-02T00:29:05Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
gem 'rspec-rails'&lt;br /&gt;
&lt;br /&gt;
gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101613</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101613"/>
		<updated>2016-04-02T00:28:56Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
gem 'rspec-rails'&lt;br /&gt;
gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101612</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101612"/>
		<updated>2016-04-02T00:28:33Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Setup===&lt;br /&gt;
Below code has to be added to the gemfile&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
gem 'rspec-rails'&lt;br /&gt;
gem &amp;quot;factory_girl_rails&amp;quot;, &amp;quot;~&amp;gt; 4.0&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Building Factories===&lt;br /&gt;
===Running RSpec===&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101611</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101611"/>
		<updated>2016-04-02T00:13:37Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://www.npmjs.com/package/gulp-purescript&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101610</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101610"/>
		<updated>2016-04-02T00:13:08Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing. &amp;lt;ref&amp;gt;https://stackoverflow.com/questions/5183975/factory-girl-whats-the-purpose&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101609</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101609"/>
		<updated>2016-04-02T00:12:14Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101608</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101608"/>
		<updated>2016-04-02T00:10:10Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/5183975/factory-girl-whats-the-purpose&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101607</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101607"/>
		<updated>2016-04-02T00:07:50Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/5183975/factory-girl-whats-the-purpose&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist|20em}}&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101606</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101606"/>
		<updated>2016-04-02T00:06:49Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* UI Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/5183975/factory-girl-whats-the-purpose&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101605</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101605"/>
		<updated>2016-04-02T00:05:55Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Testing Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Factory Girl===&lt;br /&gt;
Factory Girl is a replacement for fixtures. Fixtures have to be updated whenever we change a data model whereas adding and removing fields is much easier in Factory Girl. &lt;br /&gt;
Fixture definitions are global whereas Factories can be local, so isolated cases can be tested. Factories are defined to create objects for testing.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/5183975/factory-girl-whats-the-purpose&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101603</id>
		<title>CSC/ECE 517 Spring 2016/OSS E1601</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101603"/>
		<updated>2016-04-01T23:05:46Z</updated>

		<summary type="html">&lt;p&gt;Hkumbum: /* Testing UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E1601: Refactor methods related to submitted_hyperlinks. ===&lt;br /&gt;
&lt;br /&gt;
This wiki is for the open source refactoring project E1601: Refactor methods related to submitted_hyperlinks for the course ECE/CSC 517.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
The reviewers may use the below student and instructor logins for the purpose of reviewing and testing the functionality. These students belong to the same team and work on an assignment created by the below instructor:&lt;br /&gt;
* Instructor login: username -&amp;gt; instructor6,  password -&amp;gt; password&lt;br /&gt;
* Student  login: username -&amp;gt; student5884,  password -&amp;gt; password &lt;br /&gt;
* Student login: username -&amp;gt; student6420,  password -&amp;gt; password&lt;br /&gt;
'''Please note''': Please do not delete the above users or their team. If you wish to do so, please add them back so as to aid other reviewers. Also note that the option to submit hyperlinks in the UI will be displayed to the enrolled students only if assignment deadline is in future and the assignment is not in &amp;quot;Finish&amp;quot; state.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances the student's learning through peer reviews. The students can form teams and work on assignments given by course instructors. The peers can review the submissions and give feedback. The students also get to review the reviewers!&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
&lt;br /&gt;
'''Before''': When a student submitted files and hyperlinks for an assignment, that content was submitted on behalf of his team, and not individually (even if there is only one person in the team i.e a student working on an assignment cannot be without a team even if he is working alone). Some of the previous contributors had worked on a project which made this change and associated all the submitted content to teams instead of the individual participants: the submitted_hyperlinks and dirctory_num fields were moved to teams table. All the hyperlinks were now recorded in one submitted_hyperlinks field in the team model instead of being present in all the participants of the team. All the submitted files similarly were uploaded to the common file space and in the “course_folder/assignment_folder/team_folder” path.&lt;br /&gt;
&lt;br /&gt;
'''What was wrong with that''': There are multiple methods in assignment_participant.rb which still give the impression that the author is submitting the hyperlinks on behalf of himself and not the team even though the relevant fields have been moved to teams model. These methods are to be moved to assignment_teams.rb for improving the clarity and the efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
&lt;br /&gt;
''Task1::'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Task2::'' Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
''Task3::'' Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
&lt;br /&gt;
''Task4::'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
&lt;br /&gt;
''Task5::'' Refactored some of the logic of controller methods.&lt;br /&gt;
&lt;br /&gt;
''Task6::'' Tests for submitting and removing submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
== List of files changed ==&lt;br /&gt;
&lt;br /&gt;
Model Files:&lt;br /&gt;
&lt;br /&gt;
#assignment_participant.rb&lt;br /&gt;
#assignment_team.rb&lt;br /&gt;
#student_task.rb&lt;br /&gt;
&lt;br /&gt;
View Files:&lt;br /&gt;
&lt;br /&gt;
#submitted_content/_hyperlink.html.erb&lt;br /&gt;
#assignments/edit/_calibration.html.erb&lt;br /&gt;
#assignments/list_submissions.html.erb&lt;br /&gt;
#submitted_content/_main.html.erb&lt;br /&gt;
&lt;br /&gt;
Controller Files:&lt;br /&gt;
&lt;br /&gt;
#sign_up_sheet_controller.rb&lt;br /&gt;
#submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
Files with major modifications:&lt;br /&gt;
&lt;br /&gt;
#The model: assignment_participant.rb&lt;br /&gt;
#The model: assignment_team.rb&lt;br /&gt;
#The controller: submitted_content_controller.rb&lt;br /&gt;
&lt;br /&gt;
== Key changes ==&lt;br /&gt;
&lt;br /&gt;
Four methods &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; were moved from the assignment_participant.rb model to assignment_team.rb, and the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method was removed.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task1::''' The below methods &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; were removed from the assignment_participant.rb. The &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method which existed here seemed suspect as there was no &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in the AssignmentTeam/Team models so the &amp;lt;code&amp;gt;try&amp;lt;/code&amp;gt; would always fail and return an empty array. Also the &amp;lt;code&amp;gt;hyperlinks_array&amp;lt;/code&amp;gt; method retrieved the hyperlinks from the &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; field of the team model so in moving to AssignmentTeam model we just had to remove the .team quantifier.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.team.submitted_hyperlinks.blank? ? [] : YAML::load(self.team.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
They are both merged into a new single &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method in assignment_team.rb. All callers of both methods were refactored to use &amp;lt;code&amp;gt;hyperlinks&amp;lt;/code&amp;gt; method of AssignmentTeam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
        self.submitted_hyperlinks.blank? ? [] : YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task2::''' Earlier, the following method &amp;lt;code&amp;gt;submit_hyperlink&amp;lt;/code&amp;gt; was in assignment_participant.rb:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    team_object = self.team&lt;br /&gt;
    team_object.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    team_object.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been now moved to assignment_team.rb as below. Again, as the method was moved to AssignmentTeam model, it obviated the need to invoke the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
        hyperlink.strip!&lt;br /&gt;
        raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
        url = URI.parse(hyperlink)&lt;br /&gt;
        # If not a valid URL, it will throw an exception&lt;br /&gt;
        Net::HTTP.start(url.host, url.port)&lt;br /&gt;
        hyperlinks = self.hyperlinks&lt;br /&gt;
        hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
        self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
        self.save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
A similar refactoring was done for &amp;lt;code&amp;gt;remove_hyperlinks&amp;lt;/code&amp;gt; method in assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task3::''' The methods &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; earlier existed both in AssignmentTeam model and AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
'' In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        list_of_users = participants;&lt;br /&gt;
        list_of_users.each { |participant| return true if participant.has_submissions? }&lt;br /&gt;
        false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
''In assignment_participant.rb''&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.team.submitted_files.length &amp;gt; 0) or (hyperlinks_array.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What was happening earlier was that &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; (AssignmentTeam method) used to call &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; for each of the AssignmentParticipants in the team. This was redundant as  the &amp;lt;code&amp;gt;submitted_files&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;submitted_hyperlinks&amp;lt;/code&amp;gt; fields had been moved from the participant to the team model in earlier projects. So the participant objects again ended up again going to the team for retrieving these fields.&lt;br /&gt;
&lt;br /&gt;
So we removed &amp;lt;code&amp;gt;has_submissions?&amp;lt;/code&amp;gt; from the AssignmentParticipant and refactored the one already present in AssignmentTeam to the simple code below:&lt;br /&gt;
&lt;br /&gt;
''In assignment_team.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
  def has_submissions?&lt;br /&gt;
        return ((self.submitted_files.length &amp;gt; 0) or (hyperlinks.length &amp;gt; 0))&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task4::''' Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, they were refactored appropriately to call the newly created methods in assignment_team.rb.&lt;br /&gt;
&lt;br /&gt;
''Sample example :''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This was refactored as''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        if (participant.submitted_at.nil? &amp;amp;&amp;amp; participant.team.hyperlinks.empty?)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In refactoring the call points, we used the existing &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; method of AssignmentParticipant to get the AssignmentTeam object associated with the particular participant and then invoked the equivalent methods on the &amp;lt;code&amp;gt;team&amp;lt;/code&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Task5 ::''' Refactoring some of controller code.&lt;br /&gt;
&lt;br /&gt;
In submitted_content_controller, &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method used to cycle through all the participants belonging to the team of current participant, and for each participant call the &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method of the AssignmentParticipant Model to delete the instance of input hyperlink.&lt;br /&gt;
&lt;br /&gt;
Since all the required hyperlink methods and fields are now in AssignmentTeam this would be redundant and waste cycles. So we refactored it to directly call the AssignmentTeam &amp;lt;code&amp;gt;remove_hyperlink&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
''Earlier in submitted_content_controller.rb''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
    hyperlink_to_delete = @participant.hyperlinks_array[params['chk_links'].to_i]&lt;br /&gt;
  &lt;br /&gt;
    team_id = TeamsUser.team_id(@participant.parent_id, @participant.user_id)&lt;br /&gt;
    team_participants = Array.new&lt;br /&gt;
    if Team.exists?(team_id)&lt;br /&gt;
      team_users = TeamsUser.where(team_id: team_id)&lt;br /&gt;
      team_users.each do |team_user|&lt;br /&gt;
        team_participants &amp;lt;&amp;lt; AssignmentParticipant.where(parent_id: @participant.parent_id, user_id: team_user.user_id).first&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      team_participants &amp;lt;&amp;lt; @participant&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
    team_participants.each do |team_participant|&lt;br /&gt;
      team_participant.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Refactored:''&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def remove_hyperlink&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:hyperlinks][:participant_id])&lt;br /&gt;
 &lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
 &lt;br /&gt;
    team = @participant.team&lt;br /&gt;
    hyperlink_to_delete = team.hyperlinks[params['chk_links'].to_i]&lt;br /&gt;
    team.remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Details ==&lt;br /&gt;
&lt;br /&gt;
=== RSpec ===&lt;br /&gt;
There were no existing tests for the hyperlinks related methods. We used RSpec to write test cases using TTD approach. The assignment_team_spec.rb in the spec folder will have these tests. All the tests can be executed by rspec spec command, or can also be executed individually using the command &amp;quot;rspec spec/models/assignment_team_spec.rb&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== UI Testing ===&lt;br /&gt;
&lt;br /&gt;
Following are some of the steps which we performed to test this code from the User interface.&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2, you can also use the student logins listed in this wiki) for an active assignment. Active assignment simply means that the due date is in future and the assignment is not in &amp;quot;Finish&amp;quot; state. You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due dates of some previous assignment and assign the team to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test1:''  Login as student1. Submit a hyperlink (say : linkA) as student1.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. The hyperlink should be visible when you login as student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test2:'' Now as student2, submit another hyperlink (say linkB).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Submit should go through. Now both hyperlinks should be visible from both student1 and student2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test3:'' As student1, try submitting linkB.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' As linkB already exists in team's hyperlinks the submit should not go through.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test4:'' Remove a hyperlink (say linkA).&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Remove goes through. Now only linkB should be visible from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test5:'' Remove all hyperlinks.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Hyperlinks list is empty for team and this can be seen from both student accounts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test6:'' Submit some hyperlink. Try dropping topic after submitting.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' You are not allowed to drop if you have submitted some work. Only if you remove the submitted work it is possible for you to drop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Test7:'' Submit some hyperlink. Do a review of the team after logging in as a student in another team. The assignment should be in review stage for this to be possible, you can move the due dates via instructor login to achieve this.&lt;br /&gt;
&lt;br /&gt;
''Expected:'' Peer review should show the links submitted by the other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Hkumbum</name></author>
	</entry>
</feed>