<?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=Pkulkar5</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=Pkulkar5"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pkulkar5"/>
	<updated>2026-05-08T18:10:41Z</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/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101948</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101948"/>
		<updated>2016-04-08T22:22:10Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
==='''CSSOM'''===&lt;br /&gt;
CSSOM which is the CSS Object Model defines APIs (including generic parsing and serialization rules) for media queries, selectors, and CSS itself&amp;lt;ref&amp;gt;https://drafts.csswg.org/cssom/&amp;lt;/ref&amp;gt;. The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes. CSSOM aims at proving a way to access the CSS style classes and properties. One can even modify the CSS rules using this API. These changes can be targeted to affect individual elements or the whole webpage. &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. CSSOM is actually a collection of all the CSS stylesheets found on a web page which is very similar to Document Object Model (DOM) but only stores collection of CSS instead of HTML. &amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;. CSSOM identifies which elements on your webpage require styling and modifies them. It is also used to optimize the speed at which webpages get loaded.&lt;br /&gt;
It is an integral part of the process that is used to display content on a webpage. The web browser first creates a DOM by examining the HTMLs, then creates a CSSOM by examining the CSS stylesheets. It then creates a render tree by comibining the DOM and the CSSOM and displays the webpage.&amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==='''Rust'''===&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Servo'''===&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&amp;lt;ref&amp;gt;https://servo.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project is to go through the following steps in a somewhat linear order:&lt;br /&gt;
*Compiling servo on a machine and making sure it runs on a specific url. Then emailing the mozilla mailing list to introduce the group.&lt;br /&gt;
*Creating a StyleSheet interface which represents an abstract, base style sheet. This creation requires a couple of steps :&lt;br /&gt;
**Adding a new IDL file (which contains specifications)&lt;br /&gt;
**Creating the Rust file which has implementations of the things specified in IDL.&lt;br /&gt;
**Listing the Rust file in mod.rs file.&lt;br /&gt;
*After that comes the creation of  a StyleSheetList interface. Which represents an ordered collection of CSS style sheets. And basically because it's another interface, again the .webidl and .rs files need to be implemented.&lt;br /&gt;
*Adding the attribute &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;. &lt;br /&gt;
*In the three steps just mentioned some guidelines about implementation must be followed, like the return types of certain methods.&lt;br /&gt;
*Run the tests specified by the mozilla team.&lt;br /&gt;
*Finally updating the interfaces.html, and adding the new interface names.&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*making the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual implementation of &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; and adding a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*creating the CSSRule interface which represents an abstract, base CSS Rule. It is done using the Webidl format.&lt;br /&gt;
*creating the CSSRuleList interface and implementing &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt; which is an array like object containing an ordered collection of CSS rules.&lt;br /&gt;
*implementing the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; to allow mutation of the contents of the vector in the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;.&lt;br /&gt;
*creating the CSSStyleRule interface that extends the CSSRule interface and making &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
In this mozilla project, we are asked to strictly follow the existing design patterns and coding conventions. The main aim of this project is to add and modify interfaces. Interfaces allow developers to follow a clean design principle wherein they do not have to program to classes. It is too easy to add a dependency on a class. In order to avoid that kind of dependency on the implementation i.e. classes, developers can program to interfaces. This type of design pattern is an architectural pattern and makes the code more modular and object oriented. Programming to an interface has a flavor of DRY principle because even if the underlying implementation changes, the handle to the implementation is an interface and that does not change. In this way, our mozilla project becomes more modular and object oriented. Servo has a utility of tests that checks the coding standards followed by Mozilla on this project. We will execute the following utility tests command.&lt;br /&gt;
&amp;lt;code&amp;gt;./mach test-tidy&amp;lt;/code&amp;gt; Any issues encountered by executing this test can be flagged before generating the pull request. This ensures that the developers follow the coding standards.&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We have tried to implement the most commonly-used portions of the CSSOM API specification to increase Servo's compatibility with existing webpages &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. We have created two interfaces, StyleSheet and StyleSheetList in our initial steps. As a part of our subsequent steps, we would be adding 4 new interfaces: CSSStyleSheet, CSSRule, CSSRuleList and the CSSStyleRule interface. We have implemented only the obvious methods for these interfaces so that more advanced work can be done to make this CSSOM API fully functional keeping our work as the basis.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101947</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101947"/>
		<updated>2016-04-08T22:21:00Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
==='''CSSOM'''===&lt;br /&gt;
CSSOM which is the CSS Object Model defines APIs (including generic parsing and serialization rules) for media queries, selectors, and CSS itself&amp;lt;ref&amp;gt;https://drafts.csswg.org/cssom/&amp;lt;/ref&amp;gt;. The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes. CSSOM aims at proving a way to access the CSS style classes and properties. One can even modify the CSS rules using this API. These changes can be targeted to affect individual elements or the whole webpage. &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. CSSOM is actually a collection of all the CSS stylesheets found on a web page which is very similar to Document Object Model (DOM) but only stores collection of CSS instead of HTML. &amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;. CSSOM identifies which elements on your webpage require styling and modifies them. It is also used to optimize the speed at which webpages get loaded.&lt;br /&gt;
It is an integral part of the process that is used to display content on a webpage. The web browser first creates a DOM by examining the HTMLs, then creates a CSSOM by examining the CSS stylesheets. It then creates a render tree by comibining the DOM and the CSSOM and displays the webpage.&amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==='''Rust'''===&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Servo'''===&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&amp;lt;ref&amp;gt;https://servo.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project is to go through the following steps in a somewhat linear order:&lt;br /&gt;
*Compiling servo on a machine and making sure it runs on a specific url. Then emailing the mozilla mailing list to introduce the group.&lt;br /&gt;
*Creating a StyleSheet interface which represents an abstract, base style sheet. This creation requires a couple of steps :&lt;br /&gt;
**Adding a new IDL file (which contains specifications)&lt;br /&gt;
**Creating the Rust file which has implementations of the things specified in IDL.&lt;br /&gt;
**Listing the Rust file in mod.rs file.&lt;br /&gt;
*After that comes the creation of  a StyleSheetList interface. Which represents an ordered collection of CSS style sheets. And basically because it's another interface, again the .webidl and .rs files need to be implemented.&lt;br /&gt;
*Adding the attribute &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;. &lt;br /&gt;
*In the three steps just mentioned some guidelines about implementation must be followed, like the return types of certain methods.&lt;br /&gt;
*Run the tests specified by the mozilla team.&lt;br /&gt;
*Finally updating the interfaces.html, and adding the new interface names.&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*creating the CSSRule interface which represents an abstract, base CSS Rule. It is done using the Webidl format.&lt;br /&gt;
*creating the CSSRuleList interface and implementing &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt; which is an array like object containing an ordered collection of CSS rules.&lt;br /&gt;
*implementing the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; to allow mutation of the contents of the vector in the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;.&lt;br /&gt;
*creating the CSSStyleRule interface that extends the CSSRule interface and making &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
In this mozilla project, we are asked to strictly follow the existing design patterns and coding conventions. The main aim of this project is to add and modify interfaces. Interfaces allow developers to follow a clean design principle wherein they do not have to program to classes. It is too easy to add a dependency on a class. In order to avoid that kind of dependency on the implementation i.e. classes, developers can program to interfaces. This type of design pattern is an architectural pattern and makes the code more modular and object oriented. Programming to an interface has a flavor of DRY principle because even if the underlying implementation changes, the handle to the implementation is an interface and that does not change. In this way, our mozilla project becomes more modular and object oriented. Servo has a utility of tests that checks the coding standards followed by Mozilla on this project. We will execute the following utility tests command.&lt;br /&gt;
&amp;lt;code&amp;gt;./mach test-tidy&amp;lt;/code&amp;gt; Any issues encountered by executing this test can be flagged before generating the pull request. This ensures that the developers follow the coding standards.&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We have tried to implement the most commonly-used portions of the CSSOM API specification to increase Servo's compatibility with existing webpages &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. We have created two interfaces, StyleSheet and StyleSheetList in our initial steps. As a part of our subsequent steps, we would be adding 4 new interfaces: CSSStyleSheet, CSSRule, CSSRuleList and the CSSStyleRule interface. We have implemented only the obvious methods for these interfaces so that more advanced work can be done to make this CSSOM API fully functional keeping our work as the basis.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101946</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101946"/>
		<updated>2016-04-08T21:26:31Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
==='''CSSOM'''===&lt;br /&gt;
CSSOM which is the CSS Object Model defines APIs (including generic parsing and serialization rules) for media queries, selectors, and CSS itself&amp;lt;ref&amp;gt;https://drafts.csswg.org/cssom/&amp;lt;/ref&amp;gt;. The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes. CSSOM aims at proving a way to access the CSS style classes and properties. One can even modify the CSS rules using this API. These changes can be targeted to affect individual elements or the whole webpage. &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. CSSOM is actually a collection of all the CSS stylesheets found on a web page which is very similar to Document Object Model (DOM) but only stores collection of CSS instead of HTML. &amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;. CSSOM identifies which elements on your webpage require styling and modifies them. It is also used to optimize the speed at which webpages get loaded.&lt;br /&gt;
It is an integral part of the process that is used to display content on a webpage. The web browser first creates a DOM by examining the HTMLs, then creates a CSSOM by examining the CSS stylesheets. It then creates a render tree by comibining the DOM and the CSSOM and displays the webpage.&amp;lt;ref&amp;gt;https://varvy.com/performance/cssom.html&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==='''Rust'''===&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==='''Servo'''===&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&amp;lt;ref&amp;gt;https://servo.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project is to go through the following steps in a somewhat linear order:&lt;br /&gt;
*Compiling servo on a machine and making sure it runs on a specific url. Then emailing the mozilla mailing list to introduce the group.&lt;br /&gt;
*Creating a StyleSheet interface which represents an abstract, base style sheet. This creation requires a couple of steps :&lt;br /&gt;
**Adding a new IDL file (which contains specifications)&lt;br /&gt;
**Creating the Rust file which has implementations of the things specified in IDL.&lt;br /&gt;
**Listing the Rust file in mod.rs file.&lt;br /&gt;
*After that comes the creation of  a StyleSheetList interface. Which represents an ordered collection of CSS style sheets. And basically because it's another interface, again the .webidl and .rs files need to be implemented.&lt;br /&gt;
*Adding the attribute &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;. &lt;br /&gt;
*In the three steps just mentioned some guidelines about implementation must be followed, like the return types of certain methods.&lt;br /&gt;
*Run the tests specified by the mozilla team.&lt;br /&gt;
*Finally updating the interfaces.html, and adding the new interface names.&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Design Principles'''==&lt;br /&gt;
In this mozilla project, we are asked to strictly follow the existing design patterns and coding conventions. The main aim of this project is to add and modify interfaces. Interfaces allow developers to follow a clean design principle wherein they do not have to program to classes. It is too easy to add a dependency on a class. In order to avoid that kind of dependency on the implementation i.e. classes, developers can program to interfaces. This type of design pattern is an architectural pattern and makes the code more modular and object oriented. Programming to an interface has a flavor of DRY principle because even if the underlying implementation changes, the handle to the implementation is an interface and that does not change. In this way, our mozilla project becomes more modular and object oriented. Servo has a utility of tests that checks the coding standards followed by Mozilla on this project. We will execute the following utility tests command.&lt;br /&gt;
&amp;lt;code&amp;gt;./mach test-tidy&amp;lt;/code&amp;gt; Any issues encountered by executing this test can be flagged before generating the pull request. This ensures that the developers follow the coding standards.&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We have tried to implement the most commonly-used portions of the CSSOM API specification to increase Servo's compatibility with existing webpages &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/CSSOM-student-project&amp;lt;/ref&amp;gt;. We have created two interfaces, StyleSheet and StyleSheetList in our initial steps. As a part of our subsequent steps, we would be adding 4 new interfaces: CSSStyleSheet, CSSRule, CSSRuleList and the CSSStyleRule interface. We have implemented only the obvious methods for these interfaces so that more advanced work can be done to make this CSSOM API fully functional keeping our work as the basis.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101940</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101940"/>
		<updated>2016-04-08T20:43:21Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Rust */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&amp;lt;ref&amp;gt;https://servo.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101939</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101939"/>
		<updated>2016-04-08T20:43:04Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety. &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&amp;lt;ref&amp;gt;https://servo.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101938</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101938"/>
		<updated>2016-04-08T20:42:26Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety. &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS). [https://servo.org]&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101937</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101937"/>
		<updated>2016-04-08T20:41:00Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety. &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101935</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101935"/>
		<updated>2016-04-08T20:34:10Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Rust */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety. [https://en.wikipedia.org/wiki/Rust_(programming_language)]&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101934</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101934"/>
		<updated>2016-04-08T20:31:59Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Rust */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety. &amp;lt;ref name=&amp;quot;Rust programming language&amp;quot;&amp;gt;https://en.wikipedia.org/wiki/Rust_(programming_language)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101933</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101933"/>
		<updated>2016-04-08T20:23:00Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Subsequent Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Document.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101932</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101932"/>
		<updated>2016-04-08T20:20:31Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Rust */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&lt;br /&gt;
&lt;br /&gt;
=='''Servo'''==&lt;br /&gt;
&lt;br /&gt;
Servo is a project in [https://en.wikipedia.org/wiki/Mozilla Mozilla] research to write a parallel layout engine in Rust. It aims to achieve better parallelism, security, modularity and performance. Servo is built with Cargo, the rust package manager. It currently supports 64bit OSX, 64bit Linux, Android, and Gonk(Firefox OS).&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Documet.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101931</id>
		<title>CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Implement_Common_Parts_of_the_CSSOM_API&amp;diff=101931"/>
		<updated>2016-04-08T20:19:22Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
Cascading Style Sheets ([https://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]) is a style sheet language used for describing the presentation of a document written in a markup language. Although most often used to set the visual style of web pages and user interfaces written in [https://en.wikipedia.org/wiki/HTML HTML] and [https://en.wikipedia.org/wiki/XHTML XHTML], the language can be applied to any [https://en.wikipedia.org/wiki/XML XML] document, including plain XML, [https://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG] and [https://en.wikipedia.org/wiki/XUL XUL], and is applicable to rendering in speech, or on other media. Along with HTML and [https://en.wikipedia.org/wiki/JavaScript JavaScript], CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications&lt;br /&gt;
&lt;br /&gt;
=='''CSSOM'''==&lt;br /&gt;
CSSOM (CSS object model) defines [https://en.wikipedia.org/wiki/Application_programming_interface APIs] (including generic parsing and serialization rules) for media queries, selectors, and CSS itself.&lt;br /&gt;
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc. What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python. The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&lt;br /&gt;
&lt;br /&gt;
=='''Rust'''==&lt;br /&gt;
&lt;br /&gt;
We can organize different languages on a spectrum with control on one end and safety on the other. Languages like C and C++ fall on the end of the side of control, where as on the other side we have languages like Javascript, Ruby, Python, etc.&lt;br /&gt;
What Rust does is stepping off this line. What it does is not a tradeoff between control and safety, but it provides you both the low level of control found in C and C++, and the high level of safety in JavaScript and Python.&lt;br /&gt;
The three concepts that distinguish rust from other programming languages are: Ownership, Borrowing and lifetime. Ownership is how Rust achieves its largest goal, memory safety.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
&lt;br /&gt;
The project initial steps were described as the following:&lt;br /&gt;
*compile Servo and ensure that it runs on &amp;lt;code&amp;gt;tests/html/about-mozilla.html&amp;lt;/code&amp;gt;&lt;br /&gt;
*email the &amp;lt;code&amp;gt;mozilla.dev.servo&amp;lt;/code&amp;gt; mailing list introducing your group and your progress&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; interface. See the documentation for how to go about this. Comment out any method in the WebIDL that cannot be trivially implemented according to the specification.&lt;br /&gt;
*create the &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; interface. Leave &amp;lt;code&amp;gt;[ArrayClass]&amp;lt;/code&amp;gt; commented out, since it is not yet supported by Servo. Store a &amp;lt;code&amp;gt;JS&amp;lt;Document&amp;gt;&amp;lt;/code&amp;gt; member to allow accessing a document's stylesheets.&lt;br /&gt;
*add the &amp;lt;code&amp;gt;styleSheets&amp;lt;/code&amp;gt; attribute from the Document extension to &amp;lt;code&amp;gt;Document.webidl&amp;lt;/code&amp;gt;, and make it return a new instance of &amp;lt;code&amp;gt;StyleSheetList&amp;lt;/code&amp;gt; referencing the current document.&lt;br /&gt;
*run &amp;lt;code&amp;gt;./mach test-wpt&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/tests/wpt/html/dom/interfaces.html&amp;lt;/code&amp;gt; and update the test result expectations according to the documentation&lt;br /&gt;
*update &amp;lt;code&amp;gt;tests/wpt/mozilla/tests/mozilla/interfaces.html&amp;lt;/code&amp;gt; to add the new interface names and allow the test to pass&lt;br /&gt;
&lt;br /&gt;
The Subsequent steps are:&lt;br /&gt;
*to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member of &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; along with the actual &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt;. Add a member to &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; for the associated element, and implement the &amp;lt;code&amp;gt;ownerNode&amp;lt;/code&amp;gt; attribute of &amp;lt;code&amp;gt;StyleSheet&amp;lt;/code&amp;gt; using this.&lt;br /&gt;
*create the CSSStyleSheet interface, containing an &amp;lt;code&amp;gt;Arc&amp;lt;Stylesheet&amp;gt;&amp;lt;/code&amp;gt; member. Add a method to &amp;lt;code&amp;gt;Document&amp;lt;/code&amp;gt; that returns a new &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; instance for a particular index in the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member.&lt;br /&gt;
*create the CSSRule interface.&lt;br /&gt;
*create the CSSRuleList interface and implement &amp;lt;code&amp;gt;CSSStyleSheet.cssRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
*implement the &amp;lt;code&amp;gt;insertRule&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;deleteRule&amp;lt;/code&amp;gt; methods of &amp;lt;code&amp;gt;CSSStyleSheet&amp;lt;/code&amp;gt; by making the &amp;lt;code&amp;gt;rules&amp;lt;/code&amp;gt; member of the &amp;lt;code&amp;gt;Stylesheet&amp;lt;/code&amp;gt; type contain a RefCell, and using this to mutate the contents of the vector.&lt;br /&gt;
*create the CSSStyleRule interface and make &amp;lt;code&amp;gt;cssRules&amp;lt;/code&amp;gt; return &amp;lt;code&amp;gt;CSSStyleRule&amp;lt;/code&amp;gt; values for appropriate rules.&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 github page.&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
We had to implement the StyleSheet interface for which we had to create two file: stylesheet.rs and StyleSheet.webidl and included stylesheet interface in the mod.rs file.&lt;br /&gt;
In the StyleSheet interface we avoided the three methods: ownerNode, parentStyleSheet and media as they could not be trivially implemented and the instructions were clear to avoid such methods.&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
We had to implement StyleSheetList interface for which we had to create two file: stylesheetlist.rs and StyleSheetList.webidl and included stylesheetlist interface in the mod.rs file.&lt;br /&gt;
We used JS&amp;lt;Document&amp;gt; instead of [ArrayClass] as [ArrayClass] is not yet supported by Servo.&lt;br /&gt;
In the StyleSheetList interface we did not implement the getter as we do not have a list of stylesheets/scripts/dom.&lt;br /&gt;
&lt;br /&gt;
===='''Step 3'''====&lt;br /&gt;
We had to implement a partial interface Document with an attribute as styleSheets. The declaration of the interface was done in Document.webidl and its implementation was done in document.rs file. The implementation returned a new instance of StyleSheetList referencing the current document.&lt;br /&gt;
&lt;br /&gt;
==='''Subsequent Steps'''===&lt;br /&gt;
&lt;br /&gt;
===='''Step 1'''====&lt;br /&gt;
&lt;br /&gt;
We will be making changes in the &amp;lt;code&amp;gt;Documet.rs&amp;lt;/code&amp;gt; file to make the &amp;lt;code&amp;gt;stylesheets&amp;lt;/code&amp;gt; member store the associated &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt;. We're also going to implement the following:&lt;br /&gt;
&lt;br /&gt;
===='''Step 2'''====&lt;br /&gt;
&lt;br /&gt;
We will also implement the &amp;lt;code&amp;gt;.webidl&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.rs&amp;lt;/code&amp;gt; files for the following:&lt;br /&gt;
&lt;br /&gt;
*CSSStyleSheet interface&lt;br /&gt;
*CSSRule interface&lt;br /&gt;
*CSSRuleList interface&lt;br /&gt;
*CSSStyleRule interface&lt;br /&gt;
&lt;br /&gt;
=='''Testing'''==&lt;br /&gt;
Following are the steps to run all the tests:&lt;br /&gt;
1.	Install the pre-requisites required for servo as mentioned here&lt;br /&gt;
2.	Run the following commands&lt;br /&gt;
    cd&lt;br /&gt;
    git clone https://github.com/mohammed-alfatih/servo.git&lt;br /&gt;
    cd servo&lt;br /&gt;
    ./mach build --release&lt;br /&gt;
'''Note''': It may take around 30 mins to build&lt;br /&gt;
    ./mach test-wpt /tests/wpt/html/dom/interfaces.html&lt;br /&gt;
You will see that all tests pass as expected.&lt;br /&gt;
&lt;br /&gt;
'''Note''': There were no predefined test cases mentioned for our project. So now you will see 0 testcases. As far as we know there is no way to test this from UI.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
We added the two new interfaces in tests/wpt/mozilla/tests/mozilla/interfaces.html.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101559</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101559"/>
		<updated>2016-03-31T22:03:55Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe FileHelper do&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/pranavkulkarni/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/662 Git Pull Request]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.7.99.160:3000 Demo link] &lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#[https://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY Principle]&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101496</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101496"/>
		<updated>2016-03-29T23:10:27Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Test files method in the FileHelper module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe FileHelper do&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101495</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101495"/>
		<updated>2016-03-29T23:10:10Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Test files method in the FileHelper module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
describe FileHelper do&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101494</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101494"/>
		<updated>2016-03-29T23:09:56Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Test files method in the FileHelper module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
describe FileHelper do&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101493</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101493"/>
		<updated>2016-03-29T23:09:24Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Test files method in the FileHelper module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
describe FileHelper do&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101492</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101492"/>
		<updated>2016-03-29T23:08:39Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test files method in the FileHelper module===&lt;br /&gt;
The files method takes an argument of a directory path and returns all the files present in that directory. In the original repository, there was no test case for this method. We have added a test for this method in the file_helper_spec.rb file. The test case takes an example directory like /tmp/expertiza1603/ and returns the files present in that directory. Since the test cases can be run in any environment, the result of the test case is dependent on the presence of such a directory structure. We have created a sample directory with two files on the VCL environment(152.7.99.160). If such a directory is not present, it is important to create a directory by that name.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
describe FileHelper do&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class DummyClass&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @dummy_class = DummyClass.new&lt;br /&gt;
    @dummy_class.extend(FileHelper)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#files&amp;quot; do&lt;br /&gt;
    it 'return files present in a dir' do&lt;br /&gt;
      expected_array = [&amp;quot;/tmp/expertiza1603/1.txt&amp;quot;, &amp;quot;/tmp/expertiza1603/2.txt&amp;quot;]&lt;br /&gt;
      expect(@dummy_class.files(&amp;quot;/tmp/expertiza1603&amp;quot;)).to match_array(expected_array)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101480</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101480"/>
		<updated>2016-03-29T22:02:20Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Testing through GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 or administrator5 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 or administrator5  with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101479</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101479"/>
		<updated>2016-03-29T21:35:31Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Testing through GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
&lt;br /&gt;
====Test export fields method====&lt;br /&gt;
*Login as super_administrator2 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;br /&gt;
&lt;br /&gt;
====Test get_user_list method====&lt;br /&gt;
*Login as super_administrator2 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Users&amp;quot;&lt;br /&gt;
*You should see all the users on the page.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101478</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101478"/>
		<updated>2016-03-29T21:27:45Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Testing through GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
*Login as super_administrator2 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101477</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101477"/>
		<updated>2016-03-29T21:27:31Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing through GUI===&lt;br /&gt;
*Login as super_administrator2 with password as &amp;quot;password&amp;quot;&lt;br /&gt;
*Click on &amp;quot;Manage...&amp;quot;&amp;quot; and click on &amp;quot;Courses&amp;quot;&lt;br /&gt;
*On the &amp;quot;Actions&amp;quot; tab, click on &amp;quot;Add Participants&amp;quot;&lt;br /&gt;
*On the page that opens up, go to the bottom and select &amp;quot;Export course participants&amp;quot;&lt;br /&gt;
Click on &amp;quot;Export&amp;quot; button and a csv file should download with the selected radio button fields.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101417</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101417"/>
		<updated>2016-03-28T20:04:06Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Test the export_fields method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring was done in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will test only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101410</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101410"/>
		<updated>2016-03-28T19:47:13Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities. This is an implementation of Separation Of Concerns design principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101409</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101409"/>
		<updated>2016-03-28T19:42:13Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Refactoring: Use SQL summation to calculate average_question_score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implemented by using two for loops and fetching all the answers given by all the reviewers and then filtering using an if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns the only desired value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101405</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101405"/>
		<updated>2016-03-28T19:35:54Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Assignment Participant */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses a participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs to a user and it represents a connection between a user and an activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Duplicated export_fields method===&lt;br /&gt;
This method exports the headers of the csv file to be downloaded. The method export_fields occurs in various models with different implementations. However, the implementation for this method had been duplicated in course_participant and user models. This led to the disadvantage of having redundant code in the system and an inefficient coding practice. User model represents the base class and other models inherit from this class. Hence, deleting the method from User model made little sense. The refactoring invoked the User models export_fields method from within the export_fields of course_participant. Since the export_file controller calls this method on the course_participant object, there wasn't a choice to delete the method completely. This refactoring has the advantage that code is reused and the proper object is tied to the header fields instead of just the generic User object.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Breaking get_user_list method===&lt;br /&gt;
This method contained a lot of if-else statements that executed different codes depending on the type of user. The refactoring broke the large method into smaller methods, one for each user type. This improved the modularity of the code. It made the code more manageable and understandable from maintenance point of view (separation of responsibilities).&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: topic_name in Participant.rb===&lt;br /&gt;
In participant.rb model, there is a method topic_name. However, this method doesn't seem to be required here. A course participant cannot have a topic. If it is an assignment participant object, we can find which team that participant is in first, then find which topic is this team holding. In fact, there is a topic_name field in SignedUpTeam class. On thorough investigation, we found that the method has no caller, which is the right implementation in any case. Hence, the refactoring involved deleting this method altogether. The refactoring was verified by the fact that none of the existing test cases failed.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101229</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101229"/>
		<updated>2016-03-24T01:12:13Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses an participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs a user and it represents a connection between user and a activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101228</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101228"/>
		<updated>2016-03-24T01:11:55Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses an participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs a user and it represents a connection between user and a activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101201</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101201"/>
		<updated>2016-03-24T00:42:52Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses an participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs a user and it represents a connection between user and a activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Expertiza mainly uses RSpec for testing and has a comprehensive set of test cases overall. However, there are some models that do not have the required rspecs. We have included test cases for all the refactoring that we have done. We also ensured that the existing test cases do not fail.&lt;br /&gt;
&lt;br /&gt;
===Test adding attr_accessible to class to improve security===&lt;br /&gt;
The earlier version of Expertiza did not have an rspec for the CourseParticipant model. We added an rspec named course_participant_spec.rb as the rspec for this model covering tests for the refactorings done in this project. The attr_accessible improves security by allowing only those fields that are in the list of attr_accessible macro for mass assignment. We test this by using “should allow_mass_assignment_of” and “should_not allow_mass_assignment_of”. Those attributes that are not in the list of attr_accessible will pass the test only when tested as “should_not allow_mass_assignment_of” and the attributes that are in the list of attr_accessible will pass the test only when tested as “should allow_mass_assignment_of”. The following is the code snippet of the test case.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  describe &amp;quot;#accessible attributes&amp;quot; do&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_submit) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_review) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:user_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:parent_id) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:submitted_at) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:permission_granted) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:penalty_accumulated) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:grade) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:type) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:handle) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:time_stamp) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:digital_signature) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:duty) }&lt;br /&gt;
    it { should allow_mass_assignment_of(:can_take_quiz) }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test the export_fields method===&lt;br /&gt;
This refactoring happened in the CourseParticipant model. The duplication is removed and the export_fields method is kept only in the User model and a call to the User model is made from CourseParticipant. To test this method, we test the functionality of this method as there is no test case for this method in the previous version. The export_fields method takes an argument of options which is a list of all the fields that the end user wants to export as course participant data and it returns the corresponding fields by making a call to User model. The ideal test case will tes only the export_fields in the course_participant model and not the one in user model. This is in line with the strategy of testing incoming query messages by making assertions about what they send back. Therefore, for a given set of options, only the required right set of fields are to be returned. We expect that the returned list of fields will match the ones the method asked using the options field. Below is a sample test snippet.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#export_fields&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns export fields for a csv based on radio buttons checked&amp;quot; do&lt;br /&gt;
      options = {&amp;quot;personal_details&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;role&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;parent&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;email_options&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;, &amp;quot;handle&amp;quot;=&amp;gt;&amp;quot;true&amp;quot;}&lt;br /&gt;
      fields = [&amp;quot;name&amp;quot;, &amp;quot;full name&amp;quot;, &amp;quot;email&amp;quot;, &amp;quot;role&amp;quot;, &amp;quot;parent&amp;quot;, &amp;quot;email on submission&amp;quot;, &amp;quot;email on review&amp;quot;, &amp;quot;email on metareview&amp;quot;, &amp;quot;handle&amp;quot;]&lt;br /&gt;
      expect(CourseParticipant.export_fields(options)).to match_array(fields)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test refactoring of get_user_list method into smaller methods===&lt;br /&gt;
In order to test get_user_list, we create a dummy object of User and set its role as instructor and fetch the user list of that instructor which returns the list of participants of that instructor’s course. The list could be empty or non empty depending on the user object.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 describe &amp;quot;#get_user_list&amp;quot; do&lt;br /&gt;
      it 'user list' do&lt;br /&gt;
        @role = Role.new name: &amp;quot;Instructor&amp;quot;&lt;br /&gt;
        user1 = User.new name: &amp;quot;instructor4&amp;quot;, role: @role&lt;br /&gt;
        expect(user1.get_user_list).to be_empty&lt;br /&gt;
        expect(user1.get_users_instructor)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101189</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101189"/>
		<updated>2016-03-24T00:34:35Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses an participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs a user and it represents a connection between user and a activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;br /&gt;
&lt;br /&gt;
===Refactoring: Add attr_accessible to class to improve security===&lt;br /&gt;
The course_participant model has a number of instance variables like can_submit, can_review, user_id, parent_id, submitted_at, permission_granted, penalty_accumulated, grade, type, handle, time_stamp, digital_signature, duty, can_take_quiz. Earlier, these variables were less secure and hence susceptible to tampering with URLs or forms from malicious users. In general, elements are filled based on the data sent as a hash from the view. This happens as mass assignment where any matching key in the hash will be set. To protect this mass assignment from malicious attacks, a good design is to add attr_accessible macro. Adding this keyword to instance variables ensures that only the specified attributes in the list of attr_accessible are allowed for mass assignment. This ensures that developers can carefully consider which attributes should be allowed to do mass assignment. This way, the refactoring is done.&lt;br /&gt;
&amp;lt;code&amp;gt;attr_accessible :can_submit, :can_review, :user_id, :parent_id, :submitted_at, :permission_granted, :penalty_accumulated, :grade, :type, :handle, :time_stamp, :digital_signature, :duty, :can_take_quiz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactoring: files method is duplicate and used in assignment_team.rb as well. Move it to either a common place or keep it at the most appropriate place===&lt;br /&gt;
This refactoring belongs to AssignmentParticipant model. This model is a special class of Participant and it denotes the participants who have collaborated for a particular Assignment. This method takes a parameter which is a directory and it returns all the files present in that directory. The directory argument is basically a string containing the file path for reviewer uploaded files during peer review. This argument comes from AssignmentParticipant model but the files method as a whole is independent of the model as its function is to return files present in a directory. It does not need to belong to any model. Hence the ‘files’ method must be placed in file_helper.rb. Thus the ‘files’ method is moved from the AssignmentParticipant model to a helper module like file_helper.rb. The design principle that is reinforced here is that a class must have responsibilities that belong to itself and not other “helper” responsibilities.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  def files(directory)&lt;br /&gt;
    files_list = Dir[directory + &amp;quot;/*&amp;quot;]&lt;br /&gt;
    files = Array.new&lt;br /&gt;
    files_list.each do |file|&lt;br /&gt;
      if File.directory?(file)&lt;br /&gt;
        dir_files = files(file)&lt;br /&gt;
        dir_files.each{|f| files &amp;lt;&amp;lt; f}&lt;br /&gt;
      end&lt;br /&gt;
      files &amp;lt;&amp;lt; file&lt;br /&gt;
    end&lt;br /&gt;
    files&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Course_participant.png&amp;diff=101180</id>
		<title>File:Course participant.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Course_participant.png&amp;diff=101180"/>
		<updated>2016-03-24T00:27:12Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: Course participant model&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Course participant model&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101176</id>
		<title>CSC/ECE 517 Spring 2016/Refactor user course participant and assignment participant model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_user_course_participant_and_assignment_participant_model&amp;diff=101176"/>
		<updated>2016-03-24T00:15:23Z</updated>

		<summary type="html">&lt;p&gt;Pkulkar5: /* Tasks identified */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E1603. Refactor user, course_participant and assignment_participant model ==&lt;br /&gt;
This page provides details about the changes made to Expertiza under project E1603. Refactor user, course_participant and assignment_participant model.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
Expertiza is an educational web application built on top of Ruby on Rails. The project is open source with code available on Github and maintained by both the students and faculty of the NC State University. The application allows instructors to manage courses and assignments. The students can choose a topic from the list for an assignment, form a team, submit their work and do multiple reviews on other's work. The application helps instructors and teaching assistants in scoring and maintaining the grades for the assignment.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The users of the expertiza are modeled using the user model. A participant signs up for courses and assignments. A user can have multiple participants and all participants belong to a user. The participant model is inherited by the course and assignment participant model. Our work involves refactoring functions defined in these models. Some methods were moved to places with better fit and some methods were improvised with better implementations. The further sections in the document will explain the changes complement and how it will impact the overall usage of expertiza.&lt;br /&gt;
&lt;br /&gt;
==Tasks accomplished in this project==&lt;br /&gt;
* Moved the export_fields method to the User model from CourseParticipant model to remove redudancy.&lt;br /&gt;
* Added attr_accessible modifier to CourseParticipant to improve security.&lt;br /&gt;
* Refactored the get_user_list method into smaller methods, one method for each if condition in User model.&lt;br /&gt;
* Moved the ‘files’ method from AssignmentParticipant model which was duplicate and used in assignment_team.rb as well to a common place (FileHelper module).&lt;br /&gt;
* Refactored the average_question_score method by using sql summation to find values for sum_of_scores and number_of_scores variables in AssignmentParticipant model.&lt;br /&gt;
&lt;br /&gt;
==Models==&lt;br /&gt;
&lt;br /&gt;
===User===&lt;br /&gt;
The user model stores details of the user like name,email,role,timezone and his preferences on how expertiza should behave to him. A user can have many roles like student, instructor or administrator. The user model is used for logging in, participating in courses, assignments and creating teams. The user model maintains parent child relationship, a user will have one parent and can have many children.&lt;br /&gt;
&lt;br /&gt;
===Assignment Participant===&lt;br /&gt;
Expertiza uses an participant abstraction for modeling the participance of a user in any of the activities like courses and assignments. A participant belongs a user and it represents a connection between user and a activity. Assignment_participant, which is a child class of participant models the association between users and assignments. This association also needs to be mapped to other activities performed by a user related to the assignment. These activities include reviews, quiz, response to reviews, teammate reviews etc.. The assignment_participant model is related to models which is responsible for all the mentioned activities.&lt;br /&gt;
&lt;br /&gt;
===Course Participant===&lt;br /&gt;
The course_participant is a child class of the participant abstraction and it represents the association between a user and a course. The model also stores fields required for the association and supports bulk importing and exporting.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
&lt;br /&gt;
===Use SQL summation to calculate average_question_score===&lt;br /&gt;
The average of the score for a question in the review given by all other students who reviewed an assignment needs to be calculated in the average_question_score method in assignment participant model. This was originally implement by using two for loops and fetching all the answers given by all the reviewers and then filtering using a if statement. This method consumes more CPU cycles and impacts the performance of the application server. It also consumes more bandwidth since the application fetches all the data from the database but returns only one value to the user. This was reimplemented to use the SQL summation inside the database and returns only value to the application. This method also takes advantage of the database indexing and fetches only values required instead of filtering in the application.&lt;/div&gt;</summary>
		<author><name>Pkulkar5</name></author>
	</entry>
</feed>