<?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=Agupta27</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=Agupta27"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Agupta27"/>
	<updated>2026-07-17T20:49:16Z</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_M1602_Make_image_loads_conform_with_the_spec&amp;diff=102272</id>
		<title>CSC/ECE 517 Spring 2016 M1602 Make image loads conform with the spec</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec&amp;diff=102272"/>
		<updated>2016-04-15T20:50:59Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;Making image load conform with the spec&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/HTML5 HTML 5] specifies a complex model for image loading on a web browser. It has specifications&amp;lt;ref&amp;gt;https://html.spec.whatwg.org/multipage/#the-picture-element&amp;lt;/ref&amp;gt; for [https://html.spec.whatwg.org/multipage/#the-picture-element picture element] as well as img element, and browsers need to follow these HTML 5 specifications to conform to the standard. Servo's current implementation of image loading is [http://mxr.mozilla.org/servo/source/components/script/dom/htmlimageelement.rs#107 straightforward, but non-compliant] with HTML 5 standards&amp;lt;ref&amp;gt;https://html.spec.whatwg.org/multipage/&amp;lt;/ref&amp;gt; in a number of important ways. The goal of this project is to implement image loading behavior on Servo browser that is more compliant with HTML 5 so its easy to both implement and verify against the text of the specification.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/servo/servo Servo] is a [https://en.wikipedia.org/wiki/Web_browser web browser] layout engine written in [https://www.mozilla.org/en-US/?v=b Mozilla]'s new [https://en.wikipedia.org/wiki/System_programming_language systems language] [https://en.wikipedia.org/wiki/Rust_(programming_language) Rust]&amp;lt;ref&amp;gt;https://servo.org/&amp;lt;/ref&amp;gt;. It is currently being developed by Mozilla Research. The aim of the project is not to create a full browser but rather to create better parallelism&amp;lt;ref&amp;gt;https://www.usenix.org/legacy/event/hotpar09/tech/full_papers/jones/jones.pdf&amp;lt;/ref&amp;gt;, security&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Browser_security&amp;lt;/ref&amp;gt;, modularity&amp;lt;ref&amp;gt;https://msdn.microsoft.com/en-us/library/ff709921.aspx&amp;lt;/ref&amp;gt; and performance. The Servo project is [https://en.wikipedia.org/wiki/Open-source_software open sourced] and receives contributions from individual contributors from around the globe. It currently supports [https://www.linux.com/ Linux], [http://www.apple.com/osx/ OS X], [https://www.microsoft.com/en-us/windows Windows], [https://www.android.com/ Android], and [https://en.wikipedia.org/wiki/Gonk Gonk] (Firefox OS).&lt;br /&gt;
&lt;br /&gt;
Hatched by Mozilla employee Graydon Hoare back in 2009, Rust was built from the ground up using elements from modern programming language design&amp;lt;ref&amp;gt;http://readwrite.com/2015/07/02/mozilla-rust-programming-language-potential/&amp;lt;/ref&amp;gt;. Rust is a [https://en.wikipedia.org/wiki/General-purpose_programming_language general-purpose], [https://developer.mozilla.org/ar/docs/multiparadigmlanguage.html multi-paradigm], [https://en.wikipedia.org/wiki/Compiled_language compiled programming] language, supporting pure-functional, imperative-procedural, and object-oriented styles&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;. It focuses on performance, parallelization, and memory safety and does so because unlike other programming languages it doesn't suffer from &amp;quot;backward-compatibility requirements&amp;quot;&amp;lt;ref&amp;gt;http://readwrite.com/2015/07/02/mozilla-rust-programming-language-potential/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The detailed description of the project can be found [https://github.com/servo/servo/wiki/Image-load-conformance-student-project here].&lt;br /&gt;
&lt;br /&gt;
The steps are as follows:&lt;br /&gt;
&lt;br /&gt;
===Compilation and Build===&lt;br /&gt;
* The first step is to compile Servo browser and build it on a local machine. The steps for compiling and building Servo are:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
compile Servo and ensure that it runs tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
===Initial Steps===&lt;br /&gt;
The initial steps for the project were completed as a part of OSS project 2. The functionalities implemented were:&lt;br /&gt;
* Additional data types were defined in the HTML Image Element to add pending requests as well as current requests. The existing data types were modified so current request was used to store the image properties. &lt;br /&gt;
* A new attribute called Cross Origin was uncommented from existing Servo code and the make_enumerated_getter and setter macros were added to the code to implement Cross Origin.&lt;br /&gt;
* Current Src attribute was added to HTMLImageElement.webidl and appropriate attributes were added for its functionality.&lt;br /&gt;
* Image caching task was implemented, which accepted a URL and a vector of bytes. The cache was used to store the data collected as a newly-complete network request and continue decoding the result into pixel data.&lt;br /&gt;
&lt;br /&gt;
==Design Principles==&lt;br /&gt;
&lt;br /&gt;
These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend. They also make it easy for developers to avoid code smells, easily refactor code, and are also a part of the agile or adaptive software development.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
&lt;br /&gt;
The very first design principle used was the DRY (don't repeat yourself) principle. The essence of this principle is to reduce repetition of information of all kinds. With the use of DRY principle, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
&lt;br /&gt;
The Servo project follows an Event-driven architecture (EDA), also known as Message-driven architecture, which is any software architecture pattern promoting the production, detection, consumption of, and reaction to [https://en.wikipedia.org/wiki/Event_(computing) events]. An event can be defined as &amp;quot;a significant change in state&amp;quot;.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Event-driven_architecture&amp;lt;/ref&amp;gt; The biggest example of event-driven architecture is the Observer Pattern, which is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Observer_pattern&amp;lt;/ref&amp;gt; We are following the Observer Pattern by defining subjects having some observer dependencies, which are notified about state changes through the calling of one of our methods.&lt;br /&gt;
&lt;br /&gt;
===UML Class Diagram===&lt;br /&gt;
&lt;br /&gt;
The following is a class diagram depicting the steps involved in the project. For readability purposes, only the classes relevant to the project have been depicted.&lt;br /&gt;
&lt;br /&gt;
[[File:class_diagram_M1602.png]]&lt;br /&gt;
&lt;br /&gt;
===Flowcharts===&lt;br /&gt;
&lt;br /&gt;
This project involves implementing several algorithms while making changes in the HTML image element. The flowcharts of the algorithms have been depicted below.&lt;br /&gt;
&lt;br /&gt;
====Algorithm 1====&lt;br /&gt;
&lt;br /&gt;
[[File:updatesrc_2.png]]&lt;br /&gt;
&lt;br /&gt;
====Algorithm 2====&lt;br /&gt;
&lt;br /&gt;
[[File:parsasize.png]]&lt;br /&gt;
&lt;br /&gt;
====Algorithm 3====&lt;br /&gt;
&lt;br /&gt;
[[File:updatesrc.png]]&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Initial Steps===&lt;br /&gt;
The following steps were followed to meet the project requirements as per this [https://github.com/servo/servo/wiki/Image-load-conformance-student-project github page].&lt;br /&gt;
&lt;br /&gt;
====Step 1====&lt;br /&gt;
&lt;br /&gt;
Defined data types to represent the image request concept, and add pending and current requests to the  HTML image element. These had to subsume the existing fields in HTMLImageElement that are used for storing the image's properties, and the fields of the current request had to be used instead. &lt;br /&gt;
&lt;br /&gt;
====Step 2====&lt;br /&gt;
&lt;br /&gt;
Implemented the cross origin attribute , for which we uncommented it in the HTMLImageElement.webidl file and then we created a getter and setter method for it in the HTMLImageElement.rd file using the  make_enumerated_getter / make_setter  macros .&lt;br /&gt;
&lt;br /&gt;
====Step 3====&lt;br /&gt;
&lt;br /&gt;
Implemented the current SRC attribute by adding the appropriate attribute to  HTMLImageElement.webidl.&lt;br /&gt;
&lt;br /&gt;
===Subsequent Steps===&lt;br /&gt;
&lt;br /&gt;
These steps have to be implemented as a part of the final OSS project. The class diagram for this project is given [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#UML_Class_Diagram here]. The following are the steps required to complete the final project.&lt;br /&gt;
&lt;br /&gt;
====Step 1====&lt;br /&gt;
&lt;br /&gt;
Adding a functionality html image element to replace existing image cache functionality and instruct it to fetch a URL directly from a network request. The code should enable the result to be sent directly to the image cache.&lt;br /&gt;
&lt;br /&gt;
====Step 2====&lt;br /&gt;
&lt;br /&gt;
Implementing the parse a srcset attribute algorithm by defining a method to parse a scrset based on HTML 5 standards. To demonstrate the correctness of the algorithm, write unit tests in  tests/unit/script/htmlimageelement.rs. The flowchart for the algorithm is given [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_1 here]&lt;br /&gt;
&lt;br /&gt;
====Step 3====&lt;br /&gt;
&lt;br /&gt;
Implementing the parse a sizes attribute algorithm by defining a method to parse an image size based on HTML 5 standards. To demonstrate the correctness of the algorthim, write unit tests in  tests/unit/script/htmlimageelement.rs . The flowchart for the algorithm can be found [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_2 here]&lt;br /&gt;
&lt;br /&gt;
====Step 4====&lt;br /&gt;
&lt;br /&gt;
Implementing the normalize the source densities algorithm by creating data types for the source set and image source.&lt;br /&gt;
&lt;br /&gt;
====Step 5====&lt;br /&gt;
&lt;br /&gt;
Implementing the update the source set algorithm by defining a method to update the source based on HTML 5 standards in  htmlimageelement.rs. The flowchart for this algorithm can be found [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_3 here]&lt;br /&gt;
&lt;br /&gt;
====Step 6====&lt;br /&gt;
&lt;br /&gt;
Implementing the select an image source algorithm by defining a method to select an image source based on HTML 5 standards in  htmlimageelement.rs&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
Following are the steps to run all the tests for HTMLImageElement:&lt;br /&gt;
&lt;br /&gt;
# Install the pre-requisites required for servo as mentioned [https://github.com/servo/servo/blob/master/README.md here] &lt;br /&gt;
# Run the following command on your terminal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Servo browser should open and load the about-Mozilla web page.&lt;br /&gt;
Now run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach test-wpt tests/wpt/web-platform-tests/html/dom/interfaces.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' We have not added any new tests to the test suite as servo follows TDD and tests were previously written for HTML image element. We have just adjusted some of the test expectations for the tests which now pass due to our implementation.&lt;br /&gt;
&lt;br /&gt;
===Test Tidy===&lt;br /&gt;
&lt;br /&gt;
The Mozilla development team has a strict coding standard that all projects have to adhere to. To ensure that the project code conforms with the Mozilla coding standard, they have a code given below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
 ./mach test-tidy  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Issues reported by test are to be fixed before pull request can be generated. Once the test passes, it means that our code is following the standards of Mozilla. Running the above code, you can see that it passes and our code conforms to the Mozilla coding standards.&lt;br /&gt;
&lt;br /&gt;
=== Testing From UI ===&lt;br /&gt;
&lt;br /&gt;
Our project cannot be tested from UI since the project aims to make image loading on Servo browser more conformant to HTML5 standards. However you can check that it doesn't break the existing code and the browser runs correctly by running a test page on servo after performing the build as mentioned above.&lt;br /&gt;
&lt;br /&gt;
Run the following command after the project is build: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the browser is opened without any error messages, it means Servo is working as expected and our code modifications have not caused existing code to break.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
As a result of our changes in the initial and subsequent parts of the project, servo's image loading algorithms and behavior will be conformable to HTML5 specification and it would be possible to verify the behavior against the specification.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec&amp;diff=102271</id>
		<title>CSC/ECE 517 Spring 2016 M1602 Make image loads conform with the spec</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec&amp;diff=102271"/>
		<updated>2016-04-15T20:50:43Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;Making image load conform with the spec&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/HTML5 HTML 5] specifies a complex model for image loading on a web browser. It has specifications&amp;lt;ref&amp;gt;https://html.spec.whatwg.org/multipage/#the-picture-element&amp;lt;/ref&amp;gt; for [https://html.spec.whatwg.org/multipage/#the-picture-element picture element] as well as img element, and browsers need to follow these HTML 5 specifications to conform to the standard. Servo's current implementation of image loading is [http://mxr.mozilla.org/servo/source/components/script/dom/htmlimageelement.rs#107 straightforward, but non-compliant] with HTML 5 standards&amp;lt;ref&amp;gt;https://html.spec.whatwg.org/multipage/&amp;lt;/ref&amp;gt; in a number of important ways. The goal of this project is to implement image loading behavior on Servo browser that is more compliant with HTML 5 so its easy to both implement and verify against the text of the specification.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/servo/servo Servo] is a [https://en.wikipedia.org/wiki/Web_browser web browser] layout engine written in [https://www.mozilla.org/en-US/?v=b Mozilla]'s new [https://en.wikipedia.org/wiki/System_programming_language systems language] [https://en.wikipedia.org/wiki/Rust_(programming_language) Rust]&amp;lt;ref&amp;gt;https://servo.org/&amp;lt;/ref&amp;gt;. It is currently being developed by Mozilla Research. The aim of the project is not to create a full browser but rather to create better parallelism&amp;lt;ref&amp;gt;https://www.usenix.org/legacy/event/hotpar09/tech/full_papers/jones/jones.pdf&amp;lt;/ref&amp;gt;, security&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Browser_security&amp;lt;/ref&amp;gt;, modularity&amp;lt;ref&amp;gt;https://msdn.microsoft.com/en-us/library/ff709921.aspx&amp;lt;/ref&amp;gt; and performance. The Servo project is [https://en.wikipedia.org/wiki/Open-source_software open sourced] and receives contributions from individual contributors from around the globe. It currently supports [https://www.linux.com/ Linux], [http://www.apple.com/osx/ OS X], [https://www.microsoft.com/en-us/windows Windows], [https://www.android.com/ Android], and [https://en.wikipedia.org/wiki/Gonk Gonk] (Firefox OS).&lt;br /&gt;
&lt;br /&gt;
Hatched by Mozilla employee Graydon Hoare back in 2009, Rust was built from the ground up using elements from modern programming language design&amp;lt;ref&amp;gt;http://readwrite.com/2015/07/02/mozilla-rust-programming-language-potential/&amp;lt;/ref&amp;gt;. Rust is a [https://en.wikipedia.org/wiki/General-purpose_programming_language general-purpose], [https://developer.mozilla.org/ar/docs/multiparadigmlanguage.html multi-paradigm], [https://en.wikipedia.org/wiki/Compiled_language compiled programming] language, supporting pure-functional, imperative-procedural, and object-oriented styles&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;. It focuses on performance, parallelization, and memory safety and does so because unlike other programming languages it doesn't suffer from &amp;quot;backward-compatibility requirements&amp;quot;&amp;lt;ref&amp;gt;http://readwrite.com/2015/07/02/mozilla-rust-programming-language-potential/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The detailed description of the project can be found [https://github.com/servo/servo/wiki/Image-load-conformance-student-project here].&lt;br /&gt;
&lt;br /&gt;
The steps are as follows:&lt;br /&gt;
&lt;br /&gt;
===Compilation and Build===&lt;br /&gt;
* The first step is to compile Servo browser and build it on a local machine. The steps for compiling and building Servo are:&lt;br /&gt;
Servo is built with [https://mail.mozilla.org/pipermail/rust-dev/2014-March/009090.html Cargo], the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.&lt;br /&gt;
&lt;br /&gt;
    git clone https://github.com/servo/servo&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --dev&lt;br /&gt;
    ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
compile Servo and ensure that it runs tests/html/about-mozilla.html&lt;br /&gt;
&lt;br /&gt;
===Initial Steps===&lt;br /&gt;
The initial steps for the project were completed as a part of OSS project 2. The functionalities implemented were:&lt;br /&gt;
* Additional data types were defined in the HTML Image Element to add pending requests as well as current requests. The existing data types were modified so current request was used to store the image properties. &lt;br /&gt;
* A new attribute called Cross Origin was uncommented from existing Servo code and the make_enumerated_getter and setter macros were added to the code to implement Cross Origin.&lt;br /&gt;
* Current Src attribute was added to HTMLImageElement.webidl and appropriate attributes were added for its functionality.&lt;br /&gt;
* Image caching task was implemented, which accepted a URL and a vector of bytes. The cache was used to store the data collected as a newly-complete network request and continue decoding the result into pixel data.&lt;br /&gt;
&lt;br /&gt;
==Design Principles==&lt;br /&gt;
&lt;br /&gt;
These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend. They also make it easy for developers to avoid code smells, easily refactor code, and are also a part of the agile or adaptive software development.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
&lt;br /&gt;
The very first design principle used was the DRY (don't repeat yourself) principle. The essence of this principle is to reduce repetition of information of all kinds. With the use of DRY principle, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
&lt;br /&gt;
The Servo project follows an Event-driven architecture (EDA), also known as Message-driven architecture, which is any software architecture pattern promoting the production, detection, consumption of, and reaction to [https://en.wikipedia.org/wiki/Event_(computing) events]. An event can be defined as &amp;quot;a significant change in state&amp;quot;.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Event-driven_architecture&amp;lt;/ref&amp;gt; The biggest example of event-driven architecture is the Observer Pattern, which is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Observer_pattern&amp;lt;/ref&amp;gt; We are following the Observer Pattern by defining subjects having some observer dependencies, which are notified about state changes through the calling of one of our methods.&lt;br /&gt;
&lt;br /&gt;
===UML Class Diagram===&lt;br /&gt;
&lt;br /&gt;
The following is a class diagram depicting the steps involved in the project. For readability purposes, only the classes relevant to the project have been depicted.&lt;br /&gt;
&lt;br /&gt;
[[File:class_diagram_M1602.png]]&lt;br /&gt;
&lt;br /&gt;
===Flowcharts===&lt;br /&gt;
&lt;br /&gt;
This project involves implementing several algorithms while making changes in the HTML image element. The flowcharts of the algorithms have been depicted below.&lt;br /&gt;
&lt;br /&gt;
====Algorithm 1====&lt;br /&gt;
&lt;br /&gt;
[[File:updatesrc_2.png]]&lt;br /&gt;
&lt;br /&gt;
====Algorithm 2====&lt;br /&gt;
&lt;br /&gt;
[[File:parsasize.png]]&lt;br /&gt;
&lt;br /&gt;
====Algorithm 3====&lt;br /&gt;
&lt;br /&gt;
[[File:updatesrc.png]]&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
===Initial Steps===&lt;br /&gt;
The following steps were followed to meet the project requirements as per this [https://github.com/servo/servo/wiki/Image-load-conformance-student-project github page].&lt;br /&gt;
&lt;br /&gt;
====Step 1====&lt;br /&gt;
&lt;br /&gt;
Defined data types to represent the image request concept, and add pending and current requests to the  HTML image element. These had to subsume the existing fields in HTMLImageElement that are used for storing the image's properties, and the fields of the current request had to be used instead. &lt;br /&gt;
&lt;br /&gt;
====Step 2====&lt;br /&gt;
&lt;br /&gt;
Implemented the cross origin attribute , for which we uncommented it in the HTMLImageElement.webidl file and then we created a getter and setter method for it in the HTMLImageElement.rd file using the  make_enumerated_getter / make_setter  macros .&lt;br /&gt;
&lt;br /&gt;
====Step 3====&lt;br /&gt;
&lt;br /&gt;
Implemented the current SRC attribute by adding the appropriate attribute to  HTMLImageElement.webidl.&lt;br /&gt;
&lt;br /&gt;
===Subsequent Steps===&lt;br /&gt;
&lt;br /&gt;
These steps have to be implemented as a part of the final OSS project. The class diagram for this project is given [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#UML_Class_Diagram here]. The following are the steps required to complete the final project.&lt;br /&gt;
&lt;br /&gt;
====Step 1====&lt;br /&gt;
&lt;br /&gt;
Adding a functionality html image element to replace existing image cache functionality and instruct it to fetch a URL directly from a network request. The code should enable the result to be sent directly to the image cache.&lt;br /&gt;
&lt;br /&gt;
====Step 2====&lt;br /&gt;
&lt;br /&gt;
Implementing the parse a srcset attribute algorithm by defining a method to parse a scrset based on HTML 5 standards. To demonstrate the correctness of the algorithm, write unit tests in  tests/unit/script/htmlimageelement.rs. The flowchart for the algorithm is given [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_1 here]&lt;br /&gt;
&lt;br /&gt;
====Step 3====&lt;br /&gt;
&lt;br /&gt;
Implementing the parse a sizes attribute algorithm by defining a method to parse an image size based on HTML 5 standards. To demonstrate the correctness of the algorthim, write unit tests in  tests/unit/script/htmlimageelement.rs . The flowchart for the algorithm can be found [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_2 here]&lt;br /&gt;
&lt;br /&gt;
====Step 4====&lt;br /&gt;
&lt;br /&gt;
Implementing the normalize the source densities algorithm by creating data types for the source set and image source.&lt;br /&gt;
&lt;br /&gt;
====Step 5====&lt;br /&gt;
&lt;br /&gt;
Implementing the update the source set algorithm by defining a method to update the source based on HTML 5 standards in  htmlimageelement.rs. The flowchart for this algorithm can be found [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2016_M1602_Make_image_loads_conform_with_the_spec#Algorithm_3 here]&lt;br /&gt;
&lt;br /&gt;
====Step 6====&lt;br /&gt;
&lt;br /&gt;
Implementing the select an image source algorithm by defining a method to select an image source based on HTML 5 standards in  htmlimageelement.rs&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
Following are the steps to run all the tests for HTMLImageElement:&lt;br /&gt;
&lt;br /&gt;
# Install the pre-requisites required for servo as mentioned [https://github.com/servo/servo/blob/master/README.md here] &lt;br /&gt;
# Run the following command on your terminal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Servo browser should open and load the about-Mozilla web page.&lt;br /&gt;
Now run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach test-wpt tests/wpt/web-platform-tests/html/dom/interfaces.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' We have not added any new tests to the test suite as servo follows TDD and tests were previously written for HTML image element. We have just adjusted some of the test expectations for the tests which now pass due to our implementation.&lt;br /&gt;
&lt;br /&gt;
===Test Tidy===&lt;br /&gt;
&lt;br /&gt;
The Mozilla development team has a strict coding standard that all projects have to adhere to. To ensure that the project code conforms with the Mozilla coding standard, they have a code given below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
 ./mach test-tidy  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Issues reported by test are to be fixed before pull request can be generated. Once the test passes, it means that our code is following the standards of Mozilla. Running the above code, you can see that it passes and our code conforms to the Mozilla coding standards.&lt;br /&gt;
&lt;br /&gt;
=== Testing From UI ===&lt;br /&gt;
&lt;br /&gt;
Our project cannot be tested from UI since the project aims to make image loading on Servo browser more conformant to HTML5 standards. However you can check that it doesn't break the existing code and the browser runs correctly by running a test page on servo after performing the build as mentioned above.&lt;br /&gt;
&lt;br /&gt;
Run the following command after the project is build: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 ./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the browser is opened without any error messages, it means Servo is working as expected and our code modifications have not caused existing code to break.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
As a result of our changes in the initial and subsequent parts of the project, servo's image loading algorithms and behaviour will be comformable to HTML5 specification and it would be possible to verify the behavior against the specification.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101655</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=101655"/>
		<updated>2016-04-02T03:36:33Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
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;
===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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101651</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=101651"/>
		<updated>2016-04-02T03:17:18Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
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;
===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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101648</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=101648"/>
		<updated>2016-04-02T03:11:32Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
===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;
===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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101647</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=101647"/>
		<updated>2016-04-02T03:11:11Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Building Factories */&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;
===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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_OSS_E1601&amp;diff=101537</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=101537"/>
		<updated>2016-03-30T19:37:37Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: Redirected page to CSC/ECE 517 Spring 2016/OSS E1601&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Spring 2016/OSS E1601]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_OSS_E1601&amp;diff=101536</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=101536"/>
		<updated>2016-03-30T19:37:09Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{delete| not required }} &lt;br /&gt;
#REDIRECT [[CSC/ECE 517 Spring 2016/OSS E1601]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101535</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101535"/>
		<updated>2016-03-30T19:32:04Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor response controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016_OSS_M1606]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016/OSS_E1601]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101534</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101534"/>
		<updated>2016-03-30T19:31:25Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor response controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016_OSS_M1606]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016/Refactor methods related to submitted_hyperlinks]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101533</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101533"/>
		<updated>2016-03-30T19:30:44Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor response controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016_OSS_M1606]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016/OSS_E1601]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_OSS_E1601&amp;diff=101532</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=101532"/>
		<updated>2016-03-30T19:18:54Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: moved CSC/ECE 517 Spring 2016 OSS E1601 to CSC/ECE 517 Spring 2016/OSS E1601&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Spring 2016/OSS E1601]]&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101531</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=101531"/>
		<updated>2016-03-30T19:18:54Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: moved CSC/ECE 517 Spring 2016 OSS E1601 to CSC/ECE 517 Spring 2016/OSS E1601&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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101530</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=101530"/>
		<updated>2016-03-30T19:15:48Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101529</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=101529"/>
		<updated>2016-03-30T19:14:48Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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::'' Refactoring the 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101528</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=101528"/>
		<updated>2016-03-30T19:14:18Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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::'' Refactoring controller methods to reflect the refactoring.&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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101527</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=101527"/>
		<updated>2016-03-30T19:13:53Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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::'' Refactoring controller methods to reflect the changes.&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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101526</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=101526"/>
		<updated>2016-03-30T19:12:02Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101525</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=101525"/>
		<updated>2016-03-30T19:11:26Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101524</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=101524"/>
		<updated>2016-03-30T19:10:16Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101523</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=101523"/>
		<updated>2016-03-30T19:08:26Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101522</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=101522"/>
		<updated>2016-03-30T19:07:07Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101521</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=101521"/>
		<updated>2016-03-30T19:06:40Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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 ::'' 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101520</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=101520"/>
		<updated>2016-03-30T19:05:30Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 ::'' 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101519</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=101519"/>
		<updated>2016-03-30T19:05:00Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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'' 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101518</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=101518"/>
		<updated>2016-03-30T19:04:40Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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;
''Task1'' Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&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;
''Task4'' All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
''Task5'' 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101517</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=101517"/>
		<updated>2016-03-30T18:56:54Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Expertiza Introduction */&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;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101516</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=101516"/>
		<updated>2016-03-30T18:53:04Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 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;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101515</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=101515"/>
		<updated>2016-03-30T18:52:37Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 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 efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101514</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=101514"/>
		<updated>2016-03-30T18:51:46Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 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. They are to be moved to assignment_teams.rb for improving the clarity and efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101513</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=101513"/>
		<updated>2016-03-30T18:51:25Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 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, 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. They are to be moved to assignment_teams.rb for improving the clarity and efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101512</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=101512"/>
		<updated>2016-03-30T18:51:07Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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 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 there is only one person in the team, 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. They are to be moved to assignment_teams.rb for improving the clarity and efficiency of code.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101511</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=101511"/>
		<updated>2016-03-30T18:36:12Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Peer Review Information */&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 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101510</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=101510"/>
		<updated>2016-03-30T18:31:46Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Problem statement */&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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve the code''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101509</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=101509"/>
		<updated>2016-03-30T18:30:26Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101508</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=101508"/>
		<updated>2016-03-30T18:28:53Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101507</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=101507"/>
		<updated>2016-03-30T18:22:12Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101506</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=101506"/>
		<updated>2016-03-30T18:22:00Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 students 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101505</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=101505"/>
		<updated>2016-03-30T18:20:16Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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, otherwise you can use the students listed in peer review information) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101498</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=101498"/>
		<updated>2016-03-30T05:11:16Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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) 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101497</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=101497"/>
		<updated>2016-03-30T05:10:38Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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) for an active assignment. Active assignment simply means that the due date is in future and assignment is not in &amp;quot;Finished&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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101491</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=101491"/>
		<updated>2016-03-29T22:20:55Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101490</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=101490"/>
		<updated>2016-03-29T22:19:02Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from the UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101489</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=101489"/>
		<updated>2016-03-29T22:13:41Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101488</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=101488"/>
		<updated>2016-03-29T22:12:33Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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 other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101487</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=101487"/>
		<updated>2016-03-29T22:11:42Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* Key changes */&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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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 other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101486</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=101486"/>
		<updated>2016-03-29T22:10:15Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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 other team. Review should be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101485</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=101485"/>
		<updated>2016-03-29T22:08:44Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment simply means that the due date is in future.&lt;br /&gt;
You can use an instructor login (example username: instructor6 password: password) to create a new assignment or update the due date 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 other team. Review can be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101484</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=101484"/>
		<updated>2016-03-29T22:07:51Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps can be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment implies that due date is in that future.&lt;br /&gt;
You can use instructor login (example username: instructor6 password: password) to create a new assignment or update the due date of some previous assignment and assign student/teams 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 other team. Review can be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/OSS_E1601&amp;diff=101483</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=101483"/>
		<updated>2016-03-29T22:07:25Z</updated>

		<summary type="html">&lt;p&gt;Agupta27: /* 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;
We suggest the reviewers to use the below students and instructor for the purpose of reviewing. These students belong to the same team and work on an assignment given 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 only be displayed to the enrolled students only before the assignment deadline.&lt;br /&gt;
&lt;br /&gt;
== Expertiza Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source web application which enhances 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 student submitted files and hyperlinks, that content was submitted on behalf of a team, not individuals (even there is only one person in the team). Some of the previous contributors worked on a project which associated all the submitted content to teams: there were submitted_hyperlinks and dirctory_num fields in teams table. All the hyperlinks should ideally be recorded in one submitted_hyperlinks field. All the submitted files were uploaded to the 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 look like the author submitted the hyperlinks on behalf of him/herself. They should be moved to assignment_teams.rb.&lt;br /&gt;
&lt;br /&gt;
'''What refactoring we have done to improve''':&lt;br /&gt;
* Removed “hyperlinks_array” method and “hyperlinks” method from assignment_participant.rb. Created “hyperlinks” method in assignment_team.rb.&lt;br /&gt;
* Removed “submit_hyperlink” and “remove_hyperlink” from assignment_pariticpant.rb and created equivalent methods in assignment_team.rb.        &lt;br /&gt;
&lt;br /&gt;
* Removed “has_submissions?” from assginment_participant.rb and created the equivalent method in assignment_team.rb.          &lt;br /&gt;
* All the calls to the above methods were refactored to call the appropriate method's functions.&lt;br /&gt;
* Wrote 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;
1) 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;
2) 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;
3) 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;
4) Most importantly, at all the places in the Expertiza code, where there were calls to the above mentioned methods in assignment_participant.rb, 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;
5) 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 steps needs to be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
''Before the test::'' Have two students in an assignment team (say student1 and student2) for an active assignment. Active assignment implies that due date is in that future.&lt;br /&gt;
You can use instructor login (example username: instructor6 password: password) to create a new assignment or update the due date of some previous assignment and assign student/teams to it.&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 other team. Review can be submitted successfully.&lt;/div&gt;</summary>
		<author><name>Agupta27</name></author>
	</entry>
</feed>